EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
}
+TEST_F(cmod_propagation_test, intervening_mismatch_flag_write)
+{
+ const fs_builder &bld = v->bld;
+ fs_reg dest = 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::float_type);
+ fs_reg zero(brw_imm_f(0.0f));
+ bld.ADD(dest, src0, src1);
+ bld.CMP(bld.null_reg_f(), src2, zero, BRW_CONDITIONAL_GE)
+ ->flag_subreg = 1;
+ bld.CMP(bld.null_reg_f(), dest, zero, BRW_CONDITIONAL_GE);
+
+ /* = Before =
+ *
+ * 0: add(8) dest src0 src1
+ * 1: cmp.ge.f0.1(8) null src2 0.0f
+ * 2: cmp.ge.f0(8) null dest 0.0f
+ *
+ * = After =
+ * 0: add.ge.f0(8) dest src0 src1
+ * 1: cmp.ge.f0.1(8) null 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(0, instruction(block0, 0)->flag_subreg);
+ EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 1)->conditional_mod);
+ EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
+}
+
TEST_F(cmod_propagation_test, intervening_flag_read)
{
const fs_builder &bld = v->bld;
EXPECT_EQ(BRW_CONDITIONAL_GE, instruction(block0, 2)->conditional_mod);
}
+TEST_F(cmod_propagation_test, intervening_mismatch_flag_read)
+{
+ const fs_builder &bld = v->bld;
+ fs_reg dest0 = v->vgrf(glsl_type::float_type);
+ fs_reg dest1 = 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::float_type);
+ fs_reg zero(brw_imm_f(0.0f));
+ bld.ADD(dest0, src0, src1);
+ set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero))
+ ->flag_subreg = 1;
+ bld.CMP(bld.null_reg_f(), dest0, zero, BRW_CONDITIONAL_GE);
+
+ /* = Before =
+ *
+ * 0: add(8) dest0 src0 src1
+ * 1: (+f0.1) 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.1) 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(0, instruction(block0, 0)->flag_subreg);
+ EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
+ EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
+}
+
TEST_F(cmod_propagation_test, intervening_dest_write)
{
const fs_builder &bld = v->bld;
EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
}
+TEST_F(cmod_propagation_test,
+ subtract_merge_with_compare_intervening_mismatch_flag_write)
+{
+ const fs_builder &bld = v->bld;
+ fs_reg dest0 = v->vgrf(glsl_type::float_type);
+ fs_reg src0 = v->vgrf(glsl_type::float_type);
+ fs_reg src1 = v->vgrf(glsl_type::float_type);
+
+ bld.ADD(dest0, src0, negate(src1));
+ bld.CMP(bld.null_reg_f(), src0, src1, BRW_CONDITIONAL_L)
+ ->flag_subreg = 1;
+ bld.CMP(bld.null_reg_f(), src0, src1, BRW_CONDITIONAL_L);
+
+ /* = Before =
+ * 0: add(8) dest0:F src0:F -src1:F
+ * 1: cmp.l.f0.1(8) null:F src0:F src1:F
+ * 2: cmp.l.f0(8) null:F src0:F src1:F
+ *
+ * = After =
+ * 0: add.l.f0(8) dest0:F src0:F -src1:F
+ * 1: cmp.l.f0.1(8) null:F src0:F src1:F
+ *
+ * NOTE: Another perfectly valid after sequence would be:
+ *
+ * 0: add.f0.1(8) dest0:F src0:F -src1:F
+ * 1: cmp.l.f0(8) null:F src0:F src1:F
+ *
+ * However, the optimization pass starts at the end of the basic block.
+ * Because of this, the cmp.l.f0 will always be chosen. If the pass
+ * changes its strategy, this test will also need to change.
+ */
+ 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_L, instruction(block0, 0)->conditional_mod);
+ EXPECT_EQ(0, instruction(block0, 0)->flag_subreg);
+ EXPECT_EQ(BRW_OPCODE_CMP, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_CONDITIONAL_L, instruction(block0, 1)->conditional_mod);
+ EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
+}
+
+TEST_F(cmod_propagation_test,
+ subtract_merge_with_compare_intervening_mismatch_flag_read)
+{
+ const fs_builder &bld = v->bld;
+ fs_reg dest0 = v->vgrf(glsl_type::float_type);
+ fs_reg dest1 = 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::float_type);
+ fs_reg zero(brw_imm_f(0.0f));
+
+ bld.ADD(dest0, src0, negate(src1));
+ set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero))
+ ->flag_subreg = 1;
+ bld.CMP(bld.null_reg_f(), src0, src1, BRW_CONDITIONAL_L);
+
+ /* = Before =
+ * 0: add(8) dest0:F src0:F -src1:F
+ * 1: (+f0.1) sel(8) dest1 src2 0.0f
+ * 2: cmp.l.f0(8) null:F src0:F src1:F
+ *
+ * = After =
+ * 0: add.l.f0(8) dest0:F src0:F -src1:F
+ * 1: (+f0.1) 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_L, instruction(block0, 0)->conditional_mod);
+ EXPECT_EQ(0, instruction(block0, 0)->flag_subreg);
+ EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
+ EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
+}
+
TEST_F(cmod_propagation_test, subtract_delete_compare_derp)
{
const fs_builder &bld = v->bld;
EXPECT_EQ(BRW_OPCODE_NOT, instruction(block0, 2)->opcode);
EXPECT_EQ(BRW_CONDITIONAL_NZ, instruction(block0, 2)->conditional_mod);
}
+
+TEST_F(cmod_propagation_test, not_to_or_intervening_mismatch_flag_write)
+{
+ /* Exercise propagation of conditional modifier from a NOT instruction to
+ * another ALU instruction as performed by cmod_propagate_not.
+ */
+ const fs_builder &bld = v->bld;
+ fs_reg dest0 = v->vgrf(glsl_type::uint_type);
+ fs_reg dest1 = v->vgrf(glsl_type::uint_type);
+ fs_reg src0 = v->vgrf(glsl_type::uint_type);
+ fs_reg src1 = v->vgrf(glsl_type::uint_type);
+
+ bld.OR(dest0, src0, src1);
+ set_condmod(BRW_CONDITIONAL_Z, bld.OR(dest1, src0, src1))
+ ->flag_subreg = 1;
+ set_condmod(BRW_CONDITIONAL_NZ, bld.NOT(bld.null_reg_ud(), dest0));
+
+ /* = Before =
+ *
+ * 0: or(8) dest0 src0 src1
+ * 1: or.z.f0.1(8) dest1 src0 src1
+ * 2: not.nz.f0(8) null dest0
+ *
+ * = After =
+ * 0: or.z.f0(8) dest0 src0 src1
+ * 1: or.z.f0.1(8) dest1 src0 src1
+ */
+
+ 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_OR, instruction(block0, 0)->opcode);
+ EXPECT_EQ(BRW_CONDITIONAL_Z, instruction(block0, 0)->conditional_mod);
+ EXPECT_EQ(0, instruction(block0, 0)->flag_subreg);
+ EXPECT_EQ(BRW_OPCODE_OR, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_CONDITIONAL_Z, instruction(block0, 1)->conditional_mod);
+ EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
+}
+
+TEST_F(cmod_propagation_test, not_to_or_intervening_mismatch_flag_read)
+{
+ /* Exercise propagation of conditional modifier from a NOT instruction to
+ * another ALU instruction as performed by cmod_propagate_not.
+ */
+ const fs_builder &bld = v->bld;
+ fs_reg dest0 = v->vgrf(glsl_type::uint_type);
+ fs_reg dest1 = v->vgrf(glsl_type::float_type);
+ fs_reg src0 = v->vgrf(glsl_type::uint_type);
+ fs_reg src1 = v->vgrf(glsl_type::uint_type);
+ fs_reg src2 = v->vgrf(glsl_type::float_type);
+ fs_reg zero(brw_imm_f(0.0f));
+
+ bld.OR(dest0, src0, src1);
+ set_predicate(BRW_PREDICATE_NORMAL, bld.SEL(dest1, src2, zero))
+ ->flag_subreg = 1;
+ set_condmod(BRW_CONDITIONAL_NZ, bld.NOT(bld.null_reg_ud(), dest0));
+
+ /* = Before =
+ *
+ * 0: or(8) dest0 src0 src1
+ * 1: (+f0.1) sel(8) dest1 src2 0.0f
+ * 2: not.nz.f0(8) null dest0
+ *
+ * = After =
+ * 0: or.z.f0(8) dest0 src0 src1
+ * 1: (+f0.1) 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_OR, instruction(block0, 0)->opcode);
+ EXPECT_EQ(BRW_CONDITIONAL_Z, instruction(block0, 0)->conditional_mod);
+ EXPECT_EQ(0, instruction(block0, 0)->flag_subreg);
+ EXPECT_EQ(BRW_OPCODE_SEL, instruction(block0, 1)->opcode);
+ EXPECT_EQ(BRW_PREDICATE_NORMAL, instruction(block0, 1)->predicate);
+ EXPECT_EQ(1, instruction(block0, 1)->flag_subreg);
+}