From 35f27de9dace4ef4ac13a55c8e044e2c7edbe00d Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 19 Sep 2024 14:15:09 +0100 Subject: [PATCH] nir/opt_loop: rematerialize header block derefs in their use blocks Otherwise, we could end up with phis of derefs. Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Fixes: 6b4b04473986 ("nir/opt_loop: add loop peeling optimization") Part-of: (cherry picked from commit 0484044b1a1e9b54d05ffdcd74264b66d0187d29) --- .pick_status.json | 2 +- src/compiler/nir/nir_opt_loop.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index d8675043ecb..98caf3ebb9b 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -704,7 +704,7 @@ "description": "nir/opt_loop: rematerialize header block derefs in their use blocks", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "6b4b04473986c9b0e77c925a116be39f6ff3982f", "notes": null diff --git a/src/compiler/nir/nir_opt_loop.c b/src/compiler/nir/nir_opt_loop.c index 1588c13756b..b84f2fe2ec1 100644 --- a/src/compiler/nir/nir_opt_loop.c +++ b/src/compiler/nir/nir_opt_loop.c @@ -410,6 +410,12 @@ opt_loop_peel_initial_break(nir_loop *loop) /* We need LCSSA because we are going to wrap the loop into an IF. */ nir_convert_loop_to_lcssa(loop); + /* We can't lower some derefs to regs or create phis using them, so rematerialize them instead. */ + nir_foreach_instr_safe(instr, header_block) { + if (instr->type == nir_instr_type_deref) + nir_rematerialize_deref_in_use_blocks(nir_instr_as_deref(instr)); + } + /* Lower loop header and LCSSA-phis to regs. */ nir_lower_phis_to_regs_block(header_block); nir_lower_ssa_defs_to_regs_block(header_block);