nir/builder: Emit x != 0 for nir_i2b
There are a lot of optimizations in opt_algebraic that match ('ine', a,
0), but there are almost none that match i2b. Instead of adding a huge
pile of additional patterns (including variation that include both ine
and i2b), just emit a != 0 instead of i2b(a).
I think that the changes to the unit tests weaken them slightly, but
perhaps that's okay?
No shader-db changes on any Intel platform. The GLSL paths use other
means to generate i2b operations, but the SPIR-V paths use nir_i2b.
Presumably since 4676b3d3dd (nir: Use nir_test_mask instead of
i2b(iand)), no fossil-db changes either.
v2: Use nir_ine_imm. Suggested by Jesse.
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tested-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15121>
This commit is contained in:
@@ -413,7 +413,7 @@ nir_f2b(nir_builder *b, nir_ssa_def *src)
|
||||
static inline nir_ssa_def *
|
||||
nir_i2b(nir_builder *b, nir_ssa_def *src)
|
||||
{
|
||||
return nir_type_convert(b, src, nir_type_int, nir_type_bool1);
|
||||
return nir_ine(b, src, nir_imm_intN_t(b, 0, src->bit_size));
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
|
||||
@@ -1461,8 +1461,9 @@ TEST_F(nir_load_store_vectorize_test, shared_load_bool)
|
||||
ASSERT_EQ(deref->deref_type, nir_deref_type_var);
|
||||
ASSERT_EQ(deref->var, var);
|
||||
|
||||
ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_i2b1));
|
||||
ASSERT_TRUE(test_alu(loads[0x2]->src.ssa->parent_instr, nir_op_i2b1));
|
||||
/* The loaded value is converted to Boolean by (loaded != 0). */
|
||||
ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_ine));
|
||||
ASSERT_TRUE(test_alu(loads[0x2]->src.ssa->parent_instr, nir_op_ine));
|
||||
ASSERT_TRUE(test_alu_def(loads[0x1]->src.ssa->parent_instr, 0, &load->dest.ssa, 0));
|
||||
ASSERT_TRUE(test_alu_def(loads[0x2]->src.ssa->parent_instr, 0, &load->dest.ssa, 1));
|
||||
}
|
||||
@@ -1500,7 +1501,8 @@ TEST_F(nir_load_store_vectorize_test, shared_load_bool_mixed)
|
||||
ASSERT_EQ(deref->deref_type, nir_deref_type_var);
|
||||
ASSERT_EQ(deref->var, var);
|
||||
|
||||
ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_i2b1));
|
||||
/* The loaded value is converted to Boolean by (loaded != 0). */
|
||||
ASSERT_TRUE(test_alu(loads[0x1]->src.ssa->parent_instr, nir_op_ine));
|
||||
ASSERT_TRUE(test_alu_def(loads[0x1]->src.ssa->parent_instr, 0, &load->dest.ssa, 0));
|
||||
|
||||
EXPECT_INSTR_SWIZZLES(movs[0x2], load, "y");
|
||||
|
||||
Reference in New Issue
Block a user