From 5dcc65643ceb6d6bb875975dcdcbeb1d7987d70d Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 15 Sep 2025 10:19:22 -0700 Subject: [PATCH] nir/shrink_stores: Don't shrink stores to an invalid num_components. Avoids a regression in the CL CTS on the next commit. Fixes: 2dba7e60567f ("nir: split nir_opt_shrink_stores from nir_opt_shrink_vectors") (cherry picked from commit 537cc4e0ffc1b8c3f1b6a9857749102723775a78) Part-of: --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_shrink_stores.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 293f25654b0..99dfc8f162c 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -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 diff --git a/src/compiler/nir/nir_opt_shrink_stores.c b/src/compiler/nir/nir_opt_shrink_stores.c index 7fbea167b60..34a9fd0f48b 100644 --- a/src/compiler/nir/nir_opt_shrink_stores.c +++ b/src/compiler/nir/nir_opt_shrink_stores.c @@ -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);