From dcf2960733efce0a0fb6e547c7812fb66a3b17fd Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Thu, 1 Dec 2022 14:01:57 +0100 Subject: [PATCH] nir/nir_opt_offsets: Prevent offsets going above max MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In try_fold_load_store when trying to extract const addition from non-const offset source, we should take into account that there is already a constant base offset, which should count towards the limit. The issue was found in "Monster Hunter: World" running on Turnip. Fixes: cac6f633b21799bd1ecc35471d73a0bd190ccada ("nir/opt_offsets: Use nir_ssa_scalar to chase offset additions.") Well, the issue was present before this commit but it made a lot of changes in surrounding code. Signed-off-by: Danylo Piliaiev Reviewed-by: Timur Kristóf Part-of: (cherry picked from commit 5d025f4003b34c3540b62f9146a5e68da7756cf2) --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_offsets.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 08b74ca..4f8f8d5 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4333,7 +4333,7 @@ "description": "nir/nir_opt_offsets: Prevent offsets going above max", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "cac6f633b21799bd1ecc35471d73a0bd190ccada" }, diff --git a/src/compiler/nir/nir_opt_offsets.c b/src/compiler/nir/nir_opt_offsets.c index 2c8a2f9..025d311 100644 --- a/src/compiler/nir/nir_opt_offsets.c +++ b/src/compiler/nir/nir_opt_offsets.c @@ -123,7 +123,7 @@ try_fold_load_store(nir_builder *b, if (!nir_src_is_const(*off_src)) { uint32_t add_offset = 0; nir_ssa_scalar val = {.def = off_src->ssa, .comp = 0}; - val = try_extract_const_addition(b, val, state, &add_offset, max); + val = try_extract_const_addition(b, val, state, &add_offset, max - off_const); if (add_offset == 0) return false; off_const += add_offset; @@ -139,6 +139,8 @@ try_fold_load_store(nir_builder *b, return false; nir_instr_rewrite_src(&intrin->instr, &intrin->src[offset_src_idx], nir_src_for_ssa(replace_src)); + + assert(off_const <= max); nir_intrinsic_set_base(intrin, off_const); return true; } -- 2.7.4