OSDN Git Service

i965/cfg: Eliminate an empty then-branch of an if/else/endif
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 25 Feb 2016 03:11:39 +0000 (19:11 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Sat, 27 Feb 2016 00:51:27 +0000 (16:51 -0800)
On BDW,

total instructions in shared programs: 8448571 -> 8448367 (-0.00%)
instructions in affected programs: 21000 -> 20796 (-0.97%)
helped: 116
HURT: 0

v2: Remove spurious attempt to combine the if_block with the (removed!)
else_block.  Suggested by Matt and Curro.  Correct the comment
describing what the new pass does.  Suggested by Matt.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/mesa/drivers/dri/i965/brw_dead_control_flow.cpp

index 7aa72b1..b42e6a3 100644 (file)
@@ -34,6 +34,7 @@
  *   - if/endif
  *   . else in else/endif
  *   - if/else/endif
+ *   - else in if/else
  */
 bool
 dead_control_flow_eliminate(backend_shader *s)
@@ -114,6 +115,19 @@ dead_control_flow_eliminate(backend_shader *s)
 
             progress = true;
          }
+      } else if (inst->opcode == BRW_OPCODE_ELSE &&
+                 prev_inst->opcode == BRW_OPCODE_IF) {
+         bblock_t *const else_block = block;
+         backend_instruction *const if_inst = prev_inst;
+         backend_instruction *const else_inst = inst;
+
+         /* Since the else-branch is becoming the new then-branch, the
+          * condition has to be inverted.
+          */
+         if_inst->predicate_inverse = !if_inst->predicate_inverse;
+         else_inst->remove(else_block);
+
+         progress = true;
       }
    }