From b8fa9daf0c2d0400703ffc9460a17e0e63428292 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Thu, 26 Dec 2024 18:57:09 +0100 Subject: [PATCH] nir: sink/move alu with two identical, non constant sources. Foz-DB Navi21: Totals from 32363 (40.76% of 79395) affected shaders: MaxWaves: 787499 -> 787675 (+0.02%); split: +0.02%, -0.00% Instrs: 28783404 -> 28783464 (+0.00%); split: -0.01%, +0.01% CodeSize: 156763536 -> 156765148 (+0.00%); split: -0.01%, +0.02% VGPRs: 1493304 -> 1492848 (-0.03%); split: -0.04%, +0.01% Latency: 243022511 -> 243051994 (+0.01%); split: -0.08%, +0.09% InvThroughput: 57827398 -> 57828129 (+0.00%); split: -0.05%, +0.05% VClause: 582208 -> 582298 (+0.02%); split: -0.07%, +0.08% SClause: 959634 -> 959312 (-0.03%); split: -0.07%, +0.04% Copies: 1965821 -> 1965826 (+0.00%); split: -0.17%, +0.17% Branches: 710593 -> 710596 (+0.00%); split: -0.00%, +0.01% PreSGPRs: 1313513 -> 1313632 (+0.01%); split: -0.00%, +0.01% PreVGPRs: 1210596 -> 1209103 (-0.12%); split: -0.12%, +0.00% VALU: 19463445 -> 19463497 (+0.00%); split: -0.02%, +0.02% SALU: 3319529 -> 3319500 (-0.00%); split: -0.01%, +0.01% Reviewed-by: Konstantin Seurer Part-of: --- src/compiler/nir/nir_opt_sink.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_opt_sink.c b/src/compiler/nir/nir_opt_sink.c index bc028226b4f..4205b04e790 100644 --- a/src/compiler/nir/nir_opt_sink.c +++ b/src/compiler/nir/nir_opt_sink.c @@ -76,21 +76,25 @@ can_sink_instr(nir_instr *instr, nir_move_options options, bool *can_mov_out_of_ return options & nir_move_comparisons; /* Assuming that constants do not contribute to register pressure, it is - * beneficial to sink ALU instructions where all but one source is - * constant. Detect that case last. + * beneficial to sink ALU instructions where all non constant sources + * are the same. */ if (!(options & nir_move_alu)) return false; unsigned inputs = nir_op_infos[alu->op].num_inputs; - unsigned constant_inputs = 0; + int non_const = -1; for (unsigned i = 0; i < inputs; ++i) { if (is_constant_like(&alu->src[i].src)) - constant_inputs++; + continue; + else if (non_const < 0) + non_const = i; + else if (!nir_alu_srcs_equal(alu, alu, non_const, i)) + return false; } - return (constant_inputs + 1 >= inputs); + return true; } case nir_instr_type_intrinsic: { nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);