i965: Optimize multiplication by -1 into a negated MOV.
authorMatt Turner <mattst88@gmail.com>
Thu, 5 Feb 2015 02:08:30 +0000 (18:08 -0800)
committerMatt Turner <mattst88@gmail.com>
Sun, 15 Feb 2015 20:24:10 +0000 (12:24 -0800)
instructions in affected programs:     968 -> 942 (-2.69%)
helped:                                4

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_vec4.cpp

index c7c6acc..0f1300c 100644 (file)
@@ -2325,6 +2325,15 @@ fs_visitor::opt_algebraic()
            break;
         }
 
+         /* a * -1.0 = -a */
+         if (inst->src[1].is_negative_one()) {
+            inst->opcode = BRW_OPCODE_MOV;
+            inst->src[0].negate = !inst->src[0].negate;
+            inst->src[1] = reg_undef;
+            progress = true;
+            break;
+         }
+
          /* a * 0.0 = 0.0 */
          if (inst->src[1].is_zero()) {
             inst->opcode = BRW_OPCODE_MOV;
index fda8552..58828c3 100644 (file)
@@ -725,6 +725,11 @@ vec4_visitor::opt_algebraic()
            inst->opcode = BRW_OPCODE_MOV;
            inst->src[1] = src_reg();
            progress = true;
+         } else if (inst->src[1].is_negative_one()) {
+            inst->opcode = BRW_OPCODE_MOV;
+            inst->src[0].negate = !inst->src[0].negate;
+            inst->src[1] = src_reg();
+            progress = true;
         }
         break;
       case BRW_OPCODE_CMP: