From 0d255011aebe03d13458dbe7928ea71421f62da3 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 2 Jan 2026 09:58:34 +0100 Subject: [PATCH] nir/search: respect sign of zero when comparing floats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Floating point comparison treats -0.0 and 0.0 as equal, but do this in nir_search makes patterns signed zero incorrect. Foz-DB Navi21: Totals from 1460 (1.16% of 125360) affected shaders: MaxWaves: 33704 -> 33710 (+0.02%) Instrs: 2559362 -> 2558823 (-0.02%); split: -0.02%, +0.00% CodeSize: 14502684 -> 14496352 (-0.04%); split: -0.05%, +0.00% VGPRs: 71800 -> 71776 (-0.03%) Latency: 19274782 -> 19274267 (-0.00%); split: -0.01%, +0.00% InvThroughput: 3307870 -> 3299091 (-0.27%); split: -0.27%, +0.00% SClause: 158698 -> 158703 (+0.00%); split: -0.00%, +0.00% Copies: 240291 -> 241003 (+0.30%); split: -0.03%, +0.32% PreSGPRs: 73203 -> 73206 (+0.00%); split: -0.00%, +0.01% PreVGPRs: 62515 -> 62508 (-0.01%) VALU: 1564970 -> 1564331 (-0.04%); split: -0.04%, +0.00% SALU: 378546 -> 378654 (+0.03%); split: -0.00%, +0.03% This difference is suprisingly positive, the only patterns affected did previously signed zero incorrect bcsel -> b2f. Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir_search.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 10f0d26c85c..671a0b75415 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -334,6 +334,12 @@ match_value(const nir_algebraic_table *table, new_swizzle[i]); if (val != const_val->data.d) return false; + + /* The comparison above does not check the sign bit for 0.0, + * so do it manually. + */ + if ((dui(val) == 0) != (dui(const_val->data.d) == 0)) + return false; } return true; }