+ ppir_node *node;
+ ppir_branch_node *else_branch, *after_branch;
+ nir_block *nir_else_block = nir_if_first_else_block(if_stmt);
+ bool empty_else_block =
+ (nir_else_block == nir_if_last_else_block(if_stmt) &&
+ exec_list_is_empty(&nir_else_block->instr_list));
+ ppir_block *block = comp->current_block;
+
+ node = ppir_node_create(block, ppir_op_branch, -1, 0);
+ if (!node)
+ return false;
+ else_branch = ppir_node_to_branch(node);
+ ppir_node_add_src(block->comp, node, &else_branch->src[0],
+ &if_stmt->condition, 1);
+ else_branch->num_src = 1;
+ /* Negate condition to minimize branching. We're generating following:
+ * current_block: { ...; if (!statement) branch else_block; }
+ * then_block: { ...; branch after_block; }
+ * else_block: { ... }
+ * after_block: { ... }
+ *
+ * or if else list is empty:
+ * block: { if (!statement) branch else_block; }
+ * then_block: { ... }
+ * else_block: after_block: { ... }
+ */
+ else_branch->negate = true;
+ list_addtail(&else_branch->node.list, &block->node_list);
+
+ ppir_emit_cf_list(comp, &if_stmt->then_list);
+ if (empty_else_block) {
+ nir_block *nblock = nir_if_last_else_block(if_stmt);
+ assert(nblock->successors[0]);
+ assert(!nblock->successors[1]);
+ else_branch->target = ppir_get_block(comp, nblock->successors[0]);
+ /* Add empty else block to the list */
+ list_addtail(&block->successors[1]->list, &comp->block_list);
+ return true;
+ }
+
+ else_branch->target = ppir_get_block(comp, nir_if_first_else_block(if_stmt));
+
+ nir_block *last_then_block = nir_if_last_then_block(if_stmt);
+ assert(last_then_block->successors[0]);
+ assert(!last_then_block->successors[1]);
+ block = ppir_get_block(comp, last_then_block);
+ node = ppir_node_create(block, ppir_op_branch, -1, 0);
+ if (!node)
+ return false;
+ after_branch = ppir_node_to_branch(node);
+ /* Unconditional */
+ after_branch->num_src = 0;
+ after_branch->target = ppir_get_block(comp, last_then_block->successors[0]);
+ /* Target should be after_block, will fixup later */
+ list_addtail(&after_branch->node.list, &block->node_list);
+
+ ppir_emit_cf_list(comp, &if_stmt->else_list);
+
+ return true;