[Mesa-dev] [PATCH 13/16] i965/fs: Propagate cmod across flag read if it contains the same value.
Matt Turner
mattst88 at gmail.com
Mon Jan 19 15:31:12 PST 2015
total instructions in shared programs: 5959463 -> 5958900 (-0.01%)
instructions in affected programs: 70031 -> 69468 (-0.80%)
---
.../drivers/dri/i965/brw_fs_cmod_propagation.cpp | 16 +++++++--
.../drivers/dri/i965/test_fs_cmod_propagation.cpp | 41 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp b/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp
index 5ba2fd6..4f350c6 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_cmod_propagation.cpp
@@ -37,6 +37,15 @@
* we can do the comparison as part of the ADD instruction directly:
*
* add.ge.f0(8) g70<1>F g69<8,8,1>F 4096F
+ *
+ * If there had been a use of the flag register and another CMP using g70
+ *
+ * add.ge.f0(8) g70<1>F g69<8,8,1>F 4096F
+ * (+f0) sel(8) g71<F> g72<8,8,1>F g73<8,8,1>F
+ * cmp.ge.f0(8) null g70<8,8,1>F 0F
+ *
+ * we can recognize that the CMP is generating the flag value that already
+ * exists and therefore remove the instruction.
*/
static bool
@@ -57,6 +66,7 @@ opt_cmod_propagation_local(fs_visitor *v, bblock_t *block)
!inst->src[1].is_zero())
continue;
+ bool read_flag = false;
foreach_inst_in_block_reverse_starting_from(fs_inst, scan_inst, inst,
block) {
if (scan_inst->dst.file == GRF &&
@@ -64,7 +74,7 @@ opt_cmod_propagation_local(fs_visitor *v, bblock_t *block)
scan_inst->dst.reg_offset == inst->src[0].reg_offset &&
!scan_inst->is_partial_write()) {
if (scan_inst->can_do_cmod() &&
- (scan_inst->conditional_mod == BRW_CONDITIONAL_NONE ||
+ ((!read_flag && scan_inst->conditional_mod == BRW_CONDITIONAL_NONE) ||
scan_inst->conditional_mod == inst->conditional_mod)) {
scan_inst->conditional_mod = inst->conditional_mod;
inst->remove(block);
@@ -73,8 +83,10 @@ opt_cmod_propagation_local(fs_visitor *v, bblock_t *block)
break;
}
- if (scan_inst->reads_flag() || scan_inst->writes_flag())
+ if (scan_inst->writes_flag())
break;
+
+ read_flag = read_flag || scan_inst->reads_flag();
}
}
diff --git a/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp b/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
index daac9e6..624e0b3 100644
--- a/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
+++ b/src/mesa/drivers/dri/i965/test_fs_cmod_propagation.cpp
@@ -269,3 +269,44 @@ TEST_F(cmod_propagation_test, intervening_flag_read)
EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 2)->opcode);
EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
}
+
+TEST_F(cmod_propagation_test, intervening_flag_read_same_value)
+{
+ fs_reg dest0(v, glsl_type::float_type);
+ fs_reg dest1(v, glsl_type::float_type);
+ fs_reg src0(v, glsl_type::float_type);
+ fs_reg src1(v, glsl_type::float_type);
+ fs_reg src2(v, glsl_type::float_type);
+ fs_reg zero(0.0f);
+ v->emit(BRW_OPCODE_ADD, dest0, src0, src1)
+ ->conditional_mod = BRW_CONDITIONAL_GE;
+ v->emit(BRW_OPCODE_SEL, dest1, src2, zero)
+ ->predicate = BRW_PREDICATE_NORMAL;
+ v->emit(BRW_OPCODE_CMP, v->reg_null_f, dest0, zero)
+ ->conditional_mod = BRW_CONDITIONAL_GE;
+
+ /* = Before =
+ *
+ * 0: add.ge.f0(8) dest0 src0 src1
+ * 1: (+f0) sel(8) dest1 src2 0.0f
+ * 2: cmp.ge.f0(8) null dest0 0.0f
+ *
+ * = After =
+ * 0: add.ge.f0(8) dest0 src0 src1
+ * 1: (+f0) sel(8) dest1 src2 0.0f
+ */
+
+ v->calculate_cfg();
+ bblock_t *block0 = v->cfg->blocks[0];
+
+ EXPECT_EQ(0, block0->start_ip);
+ EXPECT_EQ(2, block0->end_ip);
+
+ EXPECT_TRUE(cmod_propagation(v));
+ EXPECT_EQ(0, block0->start_ip);
+ EXPECT_EQ(1, block0->end_ip);
+ EXPECT_EQ(BRW_OPCODE_ADD, instruction(block0, 0)->opcode);
+ EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 0)->conditional_mod);
+ EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
+}
--
2.0.4
More information about the mesa-dev
mailing list