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 c7c6accebf618b05e58c90a98cff3af67bba82a3..0f1300c1cc6961f94324b83e0276fd30fe9216ec 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 fda8552d841e136c1e59609b16ec31558e9cc762..58828c3f320b347e6f3e49058296a3e24c194b77 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: