From bd8fb8a9301a63ba57fb18772ce41a33ee40455d Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Wed, 13 Nov 2024 18:38:00 +0100 Subject: [PATCH] nir/nir_opt_offsets: Do not fold load/store with const offset > max MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When (off_const > max) there is a wrap around uint when calling try_extract_const_addition. Exit early since folding doesn't make sense in this case. Cc: mesa-stable Signed-off-by: Danylo Piliaiev Reviewed-by: Georg Lehmann Reviewed-by: Timur Kristóf (cherry picked from commit b501cbf153552a27c9a58554716288609337b491) Part-of: --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_offsets.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 351957c525b..3484b6f32a5 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -94,7 +94,7 @@ "description": "nir/nir_opt_offsets: Do not fold load/store with const offset > max", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/compiler/nir/nir_opt_offsets.c b/src/compiler/nir/nir_opt_offsets.c index 687b3e8fa61..dc740a90be4 100644 --- a/src/compiler/nir/nir_opt_offsets.c +++ b/src/compiler/nir/nir_opt_offsets.c @@ -116,6 +116,9 @@ try_fold_load_store(nir_builder *b, if (off_src->ssa->bit_size != 32) return false; + if (off_const > max) + return false; + if (!nir_src_is_const(*off_src)) { uint32_t add_offset = 0; nir_scalar val = { .def = off_src->ssa, .comp = 0 }; @@ -125,7 +128,7 @@ try_fold_load_store(nir_builder *b, off_const += add_offset; b->cursor = nir_before_instr(&intrin->instr); replace_src = nir_channel(b, val.def, val.comp); - } else if (nir_src_as_uint(*off_src) && off_const + nir_src_as_uint(*off_src) <= max) { + } else if (nir_src_as_uint(*off_src) && nir_src_as_uint(*off_src) <= max - off_const) { off_const += nir_src_as_uint(*off_src); b->cursor = nir_before_instr(&intrin->instr); replace_src = nir_imm_zero(b, off_src->ssa->num_components, off_src->ssa->bit_size);