From 8f094a7762603918903fed0db09607584828aa02 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 25 Oct 2024 15:48:24 +0200 Subject: [PATCH] nir: handle fmul(a,a)/ffma(a,a,b) in nir_def_all_uses_ignore_sign_bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foz-DB Navi31: Totals from 436 (0.55% of 79395) affected shaders: Instrs: 808917 -> 805868 (-0.38%) CodeSize: 4269056 -> 4246512 (-0.53%) Latency: 5827077 -> 5819815 (-0.12%); split: -0.13%, +0.00% InvThroughput: 625482 -> 622959 (-0.40%); split: -0.41%, +0.00% SClause: 21797 -> 21756 (-0.19%); split: -0.23%, +0.04% Copies: 48502 -> 48505 (+0.01%); split: -0.04%, +0.05% VALU: 481686 -> 479074 (-0.54%); split: -0.54%, +0.00% SALU: 76699 -> 76700 (+0.00%) Reviewed-by: Alyssa Rosenzweig Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 2946a515dc7..02f3c948e65 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1714,9 +1714,21 @@ nir_def_all_uses_ignore_sign_bit(const nir_def *def) return false; nir_instr *instr = nir_src_parent_instr(use); - if (instr->type != nir_instr_type_alu || - nir_instr_as_alu(instr)->op != nir_op_fabs) + if (instr->type != nir_instr_type_alu) return false; + + nir_alu_instr *alu = nir_instr_as_alu(instr); + if (alu->op == nir_op_fabs) { + continue; + } else if (alu->op == nir_op_fmul || alu->op == nir_op_ffma) { + nir_alu_src *alu_src = list_entry(use, nir_alu_src, src); + unsigned src_index = alu_src - alu->src; + /* a * a doesn't care about sign of a. */ + if (src_index < 2 && nir_alu_srcs_equal(alu, alu, 0, 1)) + continue; + } + + return false; } return true; }