From b6f9a9092a79f3b971c90b626c9359f8eb4e1c6f Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 31 Mar 2026 13:33:36 +0100 Subject: [PATCH] nir/propagate_invariant: include derefs In case an array index is calculated using floating point. fossil-db (navi21): Totals from 1339 (0.66% of 202427) affected shaders: MaxWaves: 30368 -> 30396 (+0.09%) Instrs: 805468 -> 817035 (+1.44%); split: -0.00%, +1.44% CodeSize: 4084432 -> 4130548 (+1.13%); split: -0.01%, +1.14% VGPRs: 62000 -> 61952 (-0.08%) Latency: 3885607 -> 3903915 (+0.47%); split: -0.01%, +0.48% InvThroughput: 726350 -> 742176 (+2.18%); split: -0.03%, +2.21% VClause: 22187 -> 22676 (+2.20%); split: -0.14%, +2.34% SClause: 14663 -> 14616 (-0.32%); split: -0.42%, +0.10% Copies: 65726 -> 65840 (+0.17%); split: -0.09%, +0.26% Branches: 21075 -> 21076 (+0.00%); split: -0.02%, +0.03% PreVGPRs: 48970 -> 48941 (-0.06%) VALU: 454510 -> 466082 (+2.55%); split: -0.01%, +2.55% SALU: 130543 -> 130521 (-0.02%); split: -0.03%, +0.01% VMEM: 43876 -> 43896 (+0.05%) Most of these changes are elden_ring shaders which can no longer optimize f2u32(u2f32()). Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Part-of: --- src/compiler/nir/nir_propagate_invariant.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_propagate_invariant.c b/src/compiler/nir/nir_propagate_invariant.c index d04ecd01ee3..fbe0a897b91 100644 --- a/src/compiler/nir/nir_propagate_invariant.c +++ b/src/compiler/nir/nir_propagate_invariant.c @@ -89,9 +89,9 @@ propagate_invariant_instr(nir_instr *instr, struct set *invariants) break; } - case nir_instr_type_tex: { - nir_tex_instr *tex = nir_instr_as_tex(instr); - if (def_is_invariant(&tex->def, invariants)) + case nir_instr_type_tex: + case nir_instr_type_deref: { + if (def_is_invariant(nir_instr_def(instr), invariants)) nir_foreach_src(instr, add_src_cb, invariants); break; } @@ -132,7 +132,6 @@ propagate_invariant_instr(nir_instr *instr, struct set *invariants) break; } - case nir_instr_type_deref: case nir_instr_type_jump: case nir_instr_type_undef: case nir_instr_type_load_const: