diff --git a/src/mesa/drivers/dri/i965/brw_cfg.cpp b/src/mesa/drivers/dri/i965/brw_cfg.cpp index 548b45899b2..9dffa63ef4d 100644 --- a/src/mesa/drivers/dri/i965/brw_cfg.cpp +++ b/src/mesa/drivers/dri/i965/brw_cfg.cpp @@ -133,10 +133,7 @@ cfg_t::create(void *parent_mem_ctx, exec_list *instructions) cur_if = cur; cur_else = NULL; - /* Set up the block just after the endif. Don't know when exactly - * it will start, yet. - */ - cur_endif = new_block(); + cur_endif = NULL; /* Set up our immediately following block, full of "then" * instructions. @@ -149,26 +146,39 @@ cfg_t::create(void *parent_mem_ctx, exec_list *instructions) break; case BRW_OPCODE_ELSE: - cur->add_successor(mem_ctx, cur_endif); + cur_else = cur; next = new_block(); next->start = (backend_instruction *)inst->next; cur_if->add_successor(mem_ctx, next); - cur_else = next; set_next_block(next); break; case BRW_OPCODE_ENDIF: { - cur_endif->start = (backend_instruction *)inst->next; - cur->add_successor(mem_ctx, cur_endif); - set_next_block(cur_endif); + if (cur->start == inst) { + /* New block was just created; use it. */ + cur_endif = cur; + } else { + cur_endif = new_block(); + cur_endif->start = inst; - if (!cur_else) - cur_if->add_successor(mem_ctx, cur_endif); + cur->end = (backend_instruction *)inst->prev; + cur->add_successor(mem_ctx, cur_endif); - backend_instruction *else_inst = cur_else ? - (backend_instruction *) cur_else->start->prev : NULL; + ip--; + set_next_block(cur_endif); + ip++; + } + + backend_instruction *else_inst = NULL; + if (cur_else) { + else_inst = (backend_instruction *)cur_else->end; + + cur_else->add_successor(mem_ctx, cur_endif); + } else { + cur_if->add_successor(mem_ctx, cur_endif); + } assert(cur_if->end->opcode == BRW_OPCODE_IF); assert(!else_inst || else_inst->opcode == BRW_OPCODE_ELSE); diff --git a/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp b/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp index 8bdf0943e2e..7de27e3b22e 100644 --- a/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp +++ b/src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp @@ -45,10 +45,10 @@ dead_control_flow_eliminate(backend_visitor *v) bblock_t *block = cfg.blocks[b]; bool found = false; - /* ENDIF instructions, by definition, can only be found at the ends of + /* ENDIF instructions, by definition, can only be found at the start of * basic blocks. */ - backend_instruction *endif_inst = block->end; + backend_instruction *endif_inst = block->start; if (endif_inst->opcode != BRW_OPCODE_ENDIF) continue;