From aa6d3636349929bfca95ec8b6f6495d5f34e793b Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Wed, 17 Jul 2024 22:42:33 +0200 Subject: [PATCH] nir: constant fold inverse_ballot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foz-DB Navi21: Totals from 210 (0.26% of 79395) affected shaders: Instrs: 79583 -> 78892 (-0.87%) CodeSize: 435636 -> 431680 (-0.91%) VGPRs: 7208 -> 7224 (+0.22%) Latency: 660376 -> 658808 (-0.24%); split: -0.38%, +0.14% InvThroughput: 127489 -> 127544 (+0.04%); split: -0.35%, +0.39% VClause: 1503 -> 1504 (+0.07%) SClause: 3970 -> 3947 (-0.58%) Copies: 4932 -> 4682 (-5.07%); split: -5.17%, +0.10% Branches: 2411 -> 2406 (-0.21%); split: -0.33%, +0.12% PreSGPRs: 6395 -> 6434 (+0.61%); split: -0.31%, +0.92% PreVGPRs: 4100 -> 4103 (+0.07%) VALU: 48484 -> 48145 (-0.70%); split: -0.70%, +0.00% SALU: 12499 -> 12202 (-2.38%); split: -2.41%, +0.03% SMEM: 6448 -> 6420 (-0.43%) Reviewed-by: Alyssa Rosenzweig Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_opt_constant_folding.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c index e1b73554f58..31db1fbb44f 100644 --- a/src/compiler/nir/nir_opt_constant_folding.c +++ b/src/compiler/nir/nir_opt_constant_folding.c @@ -281,6 +281,23 @@ try_fold_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin, } return false; + case nir_intrinsic_inverse_ballot: { + if (!nir_src_is_const(intrin->src[0])) + return false; + bool constant_true = true; + bool constant_false = true; + for (unsigned i = 0; i < nir_src_num_components(intrin->src[0]); i++) { + int64_t value = nir_src_comp_as_int(intrin->src[0], i); + constant_true &= value == -1; + constant_false &= value == 0; + } + if (!constant_true && !constant_false) + return false; + b->cursor = nir_before_instr(&intrin->instr); + nir_def_replace(&intrin->def, nir_imm_bool(b, constant_true)); + return true; + } + default: return false; }