i965/fs: Use fs_inst::overwrites_reg() in saturate propagation.
authorMatt Turner <mattst88@gmail.com>
Wed, 28 Jan 2015 06:43:28 +0000 (22:43 -0800)
committerMatt Turner <mattst88@gmail.com>
Fri, 20 Feb 2015 05:16:43 +0000 (21:16 -0800)
This is safer and matches the conditional_mod propagation pass.

Cc: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_fs_saturate_propagation.cpp
src/mesa/drivers/dri/i965/test_fs_saturate_propagation.cpp

index a9966a4d6486d15d29494d59f167737dcd104dbb..bc516618c3d3cd983e5e8c07258a61f65f87e803 100644 (file)
@@ -64,10 +64,10 @@ opt_saturate_propagation_local(fs_visitor *v, bblock_t *block)
 
       bool interfered = false;
       foreach_inst_in_block_reverse_starting_from(fs_inst, scan_inst, inst, block) {
-         if (scan_inst->dst.file == GRF &&
-             scan_inst->dst.reg == inst->src[0].reg &&
-             scan_inst->dst.reg_offset == inst->src[0].reg_offset &&
-             !scan_inst->is_partial_write()) {
+         if (scan_inst->overwrites_reg(inst->src[0])) {
+            if (scan_inst->is_partial_write())
+               break;
+
             if (scan_inst->saturate) {
                inst->saturate = false;
                progress = true;
index 2000830cc67293d56e115f812276f65276989016..f897bddb7aaee2247f257e385732e24da0de5b01 100644 (file)
@@ -353,3 +353,43 @@ TEST_F(saturate_propagation_test, intervening_saturating_copy)
    EXPECT_EQ(BRW_OPCODE_MOV, instruction(block0, 2)->opcode);
    EXPECT_FALSE(instruction(block0, 2)->saturate);
 }
+
+TEST_F(saturate_propagation_test, intervening_dest_write)
+{
+   fs_reg dst0 = v->vgrf(glsl_type::vec4_type);
+   fs_reg dst1 = v->vgrf(glsl_type::float_type);
+   fs_reg src0 = v->vgrf(glsl_type::float_type);
+   fs_reg src1 = v->vgrf(glsl_type::float_type);
+   fs_reg src2 = v->vgrf(glsl_type::vec2_type);
+   v->emit(BRW_OPCODE_ADD, offset(dst0, 2), src0, src1);
+   v->emit(SHADER_OPCODE_TEX, dst0, src2)
+      ->regs_written = 4;
+   v->emit(BRW_OPCODE_MOV, dst1, offset(dst0, 2))
+      ->saturate = true;
+
+   /* = Before =
+    *
+    * 0: add(8)        dst0+2  src0    src1
+    * 1: tex(8) rlen 4 dst0+0  src2
+    * 2: mov.sat(8)    dst1    dst0+2
+    *
+    * = After =
+    * (no changes)
+    */
+
+   v->calculate_cfg();
+   bblock_t *block0 = v->cfg->blocks[0];
+
+   EXPECT_EQ(0, block0->start_ip);
+   EXPECT_EQ(2, block0->end_ip);
+
+   EXPECT_FALSE(saturate_propagation(v));
+   EXPECT_EQ(0, block0->start_ip);
+   EXPECT_EQ(2, block0->end_ip);
+   EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
+   EXPECT_FALSE(instruction(block0, 0)->saturate);
+   EXPECT_EQ(SHADER_OPCODE_TEX, instruction(block0, 1)->opcode);
+   EXPECT_FALSE(instruction(block0, 0)->saturate);
+   EXPECT_EQ(BRW_OPCODE_MOV, instruction(block0, 2)->opcode);
+   EXPECT_TRUE(instruction(block0, 2)->saturate);
+}