nir/shrink_stores: Don't shrink stores to an invalid num_components.

Avoids a regression in the CL CTS on the next commit.

Fixes: 2dba7e6056 ("nir: split nir_opt_shrink_stores from nir_opt_shrink_vectors")
(cherry picked from commit 537cc4e0ff)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38010>
This commit is contained in:
Emma Anholt 2025-09-15 10:19:22 -07:00 committed by Dylan Baker
parent ab7bda0a1b
commit 5dcc65643c
2 changed files with 4 additions and 2 deletions

View file

@ -1024,7 +1024,7 @@
"description": "nir/shrink_stores: Don't shrink stores to an invalid num_components.",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "2dba7e60567fe0b2742a0a4b4bba618123153757",
"notes": null

View file

@ -82,7 +82,9 @@ opt_shrink_store_instr(nir_builder *b, nir_intrinsic_instr *instr, bool shrink_i
/* Trim the num_components stored according to the write mask. */
unsigned write_mask = nir_intrinsic_write_mask(instr);
unsigned last_bit = util_last_bit(write_mask);
/* Don't trim down to an invalid number of components, though. */
unsigned last_bit = nir_round_up_components(util_last_bit(write_mask));
if (last_bit < instr->num_components) {
nir_def *def = nir_trim_vector(b, instr->src[0].ssa, last_bit);
nir_src_rewrite(&instr->src[0], def);