i965/fs: Add a couple more algebraic cases that help some ARB_fp patterns.
authorEric Anholt <eric@anholt.net>
Thu, 20 Sep 2012 09:06:07 +0000 (11:06 +0200)
committerEric Anholt <eric@anholt.net>
Mon, 8 Oct 2012 15:38:49 +0000 (08:38 -0700)
ARB_fp doesn't go through the GLSL optimizer, and these were things you see
frequently thanks to conditionals being lowered to SLT/SGE and MUL.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_fs.cpp

index 9ac2a49d94830e5a604f27c2fc2595dc5a4bce82..fea598025eff3043d8a46ffd7d001dec61d2f686 100644 (file)
@@ -1435,7 +1435,30 @@ fs_visitor::opt_algebraic()
            break;
         }
 
+         /* a * 0.0 = 0.0 */
+         if (inst->src[1].type == BRW_REGISTER_TYPE_F &&
+             inst->src[1].imm.f == 0.0) {
+            inst->opcode = BRW_OPCODE_MOV;
+            inst->src[0] = fs_reg(0.0f);
+            inst->src[1] = reg_undef;
+            progress = true;
+            break;
+         }
+
         break;
+      case BRW_OPCODE_ADD:
+         if (inst->src[1].file != IMM)
+            continue;
+
+         /* a + 0.0 = a */
+         if (inst->src[1].type == BRW_REGISTER_TYPE_F &&
+             inst->src[1].imm.f == 0.0) {
+            inst->opcode = BRW_OPCODE_MOV;
+            inst->src[1] = reg_undef;
+            progress = true;
+            break;
+         }
+         break;
       default:
         break;
       }