... to eliminate an ELSE instruction followed immediately by an ENDIF.
instructions in affected programs: 704 -> 700 (-0.57%)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
/* Look for and eliminate dead control flow:
*
* - if/endif
+ * . else in else/endif
* - if/else/endif
*/
bool
backend_instruction *if_inst = NULL, *else_inst = NULL;
backend_instruction *prev_inst = (backend_instruction *) endif_inst->prev;
- if (prev_inst->opcode == BRW_OPCODE_IF) {
- if_inst = prev_inst;
- found = true;
- } else if (prev_inst->opcode == BRW_OPCODE_ELSE) {
+ if (prev_inst->opcode == BRW_OPCODE_ELSE) {
else_inst = prev_inst;
+ found = true;
prev_inst = (backend_instruction *) prev_inst->prev;
- if (prev_inst->opcode == BRW_OPCODE_IF) {
- if_inst = prev_inst;
- found = true;
- }
+ }
+
+ if (prev_inst->opcode == BRW_OPCODE_IF) {
+ if_inst = prev_inst;
+ found = true;
+ } else {
+ /* Don't remove the ENDIF if we didn't find a dead IF. */
+ endif_inst = NULL;
}
if (found) {
- if_inst->remove();
+ if (if_inst)
+ if_inst->remove();
if (else_inst)
else_inst->remove();
- endif_inst->remove();
+ if (endif_inst)
+ endif_inst->remove();
progress = true;
}
}