nir: Handle swizzle in nir_alu_srcs_negative_equal
When I added this function, I was not sure if swizzles of immediate values were a thing that occurred in NIR. The only existing user of these functions is the partial redundancy elimination for compares. Since comparison instructions are inherently scalar, this does not occur. However, a couple later patches, "nir/algebraic: Recognize open-coded flrp(-1, 1, a) and flrp(1, -1, a)" combined with "intel/vec4: Try to emit a single load for multiple 3-src instruction operands", collaborate to create a few thousand instances. No shader-db changes on any Intel platform. v2: Handle the swizzle in nir_alu_srcs_negative_equal and leave nir_const_value_negative_equal unchanged. Suggested by Jason. v3: Correctly handle write masks. Add note (and assertion) that the caller is responsible for various compatibility checks. The single existing caller only calls this for combinations of scalar fadd and float comparison instructions, so all of the requirements are met. A later patch (intel/vec4: Try to emit a single load for multiple 3-src instruction operands) will call this for sources of the same instruction, so all of the requirements are met. v4: Add unit test for nir_opt_comparison_pre that is fixed by this commit. Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
@@ -270,6 +270,42 @@ compare_with_negation(nir_type_uint32)
|
||||
compare_with_negation(nir_type_int64)
|
||||
compare_with_negation(nir_type_uint64)
|
||||
|
||||
TEST_F(alu_srcs_negative_equal_test, swizzle_scalar_to_vector)
|
||||
{
|
||||
nir_ssa_def *v = nir_imm_vec2(&bld, 1.0, -1.0);
|
||||
const uint8_t s0[4] = { 0, 0, 0, 0 };
|
||||
const uint8_t s1[4] = { 1, 1, 1, 1 };
|
||||
|
||||
/* We can't use nir_swizzle here because it inserts an extra MOV. */
|
||||
nir_alu_instr *instr = nir_alu_instr_create(bld.shader, nir_op_fadd);
|
||||
|
||||
instr->src[0].src = nir_src_for_ssa(v);
|
||||
instr->src[1].src = nir_src_for_ssa(v);
|
||||
|
||||
memcpy(&instr->src[0].swizzle, s0, sizeof(s0));
|
||||
memcpy(&instr->src[1].swizzle, s1, sizeof(s1));
|
||||
|
||||
nir_builder_alu_instr_finish_and_insert(&bld, instr);
|
||||
|
||||
EXPECT_TRUE(nir_alu_srcs_negative_equal(instr, instr, 0, 1));
|
||||
}
|
||||
|
||||
TEST_F(alu_srcs_negative_equal_test, unused_components_mismatch)
|
||||
{
|
||||
nir_ssa_def *v1 = nir_imm_vec4(&bld, -2.0, 18.0, 43.0, 1.0);
|
||||
nir_ssa_def *v2 = nir_imm_vec4(&bld, 2.0, 99.0, 76.0, -1.0);
|
||||
|
||||
nir_ssa_def *result = nir_fadd(&bld, v1, v2);
|
||||
|
||||
nir_alu_instr *instr = nir_instr_as_alu(result->parent_instr);
|
||||
|
||||
/* Disable the channels that aren't negations of each other. */
|
||||
instr->dest.dest.is_ssa = false;
|
||||
instr->dest.write_mask = 8 + 1;
|
||||
|
||||
EXPECT_TRUE(nir_alu_srcs_negative_equal(instr, instr, 0, 1));
|
||||
}
|
||||
|
||||
static void
|
||||
count_sequence(nir_const_value c[NIR_MAX_VEC_COMPONENTS],
|
||||
nir_alu_type full_type, int first)
|
||||
|
||||
Reference in New Issue
Block a user