From 1c5271346af77724f0462d1acafaa49142569006 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 6 Nov 2020 16:43:41 +0100 Subject: [PATCH] nir/algebraic: optimize bitfield_select(a, b, 0) to iand(a, b) (src0 & src1) | (~src0 & src2) to (src0 & src1). fossils-db (Polaris10): Totals from 873 (0.63% of 138014) affected shaders: SGPRs: 33781 -> 33733 (-0.14%) VGPRs: 37704 -> 37520 (-0.49%); split: -0.51%, +0.02% CodeSize: 3861460 -> 3853424 (-0.21%); split: -0.21%, +0.00% MaxWaves: 5306 -> 5305 (-0.02%) Instrs: 743798 -> 743486 (-0.04%); split: -0.04%, +0.00% Cycles: 10962244 -> 10960936 (-0.01%); split: -0.01%, +0.00% VMEM: 128309 -> 128350 (+0.03%); split: +0.33%, -0.30% SMEM: 44797 -> 44113 (-1.53%); split: +0.02%, -1.54% Copies: 71875 -> 71674 (-0.28%); split: -0.31%, +0.03% PreSGPRs: 23484 -> 23479 (-0.02%) PreVGPRs: 34582 -> 34529 (-0.15%) Signed-off-by: Samuel Pitoiset Reviewed-by: Rhys Perry Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 987965d23d6..3112623d9ff 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1399,6 +1399,9 @@ optimizations.extend([ ('ubfe', 'value', 'offset', 'bits')), 'options->lower_bitfield_extract'), + # (src0 & src1) | (~src0 & src2). Constant fold if src2 is 0. + (('bitfield_select', a, b, 0), ('iand', a, b)), + # Note that these opcodes are defined to only use the five least significant bits of 'offset' and 'bits' (('ubfe', 'value', 'offset', ('iand', 31, 'bits')), ('ubfe', 'value', 'offset', 'bits')), (('ubfe', 'value', ('iand', 31, 'offset'), 'bits'), ('ubfe', 'value', 'offset', 'bits')),