nir/opt_shrink_vectors: fix re-using of components for vecN

Cc: mesa-stable
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17276>
(cherry picked from commit 862f1eacb2)
This commit is contained in:
Daniel Schürmann 2022-06-28 11:13:54 +02:00 committed by Dylan Baker
parent e1cf74f53b
commit af9b753318
2 changed files with 5 additions and 3 deletions

View file

@ -1030,7 +1030,7 @@
"description": "nir/opt_shrink_vectors: fix re-using of components for vecN",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -120,10 +120,12 @@ opt_shrink_vector(nir_builder *b, nir_alu_instr *instr)
if (!((mask >> i) & 0x1))
continue;
nir_ssa_scalar scalar = nir_get_ssa_scalar(instr->src[i].src.ssa, instr->src[i].swizzle[0]);
/* Try reuse a component with the same value */
unsigned j;
for (j = 0; j < num_components; j++) {
if (nir_alu_srcs_equal(instr, instr, i, j)) {
if (scalar.def == srcs[j].def && scalar.comp == srcs[j].comp) {
reswizzle[i] = j;
break;
}
@ -131,7 +133,7 @@ opt_shrink_vector(nir_builder *b, nir_alu_instr *instr)
/* Otherwise, just append the value */
if (j == num_components) {
srcs[num_components] = nir_get_ssa_scalar(instr->src[i].src.ssa, instr->src[i].swizzle[0]);
srcs[num_components] = scalar;
reswizzle[i] = num_components++;
}
}