summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>2020-11-06 16:43:41 +0100
committerMarge Bot <eric+marge@anholt.net>2020-11-09 19:51:27 +0000
commit1c5271346af77724f0462d1acafaa49142569006 (patch)
treead92fd34a7cad201f99e08e9ddd4da97ec81e055
parentd47969eb5ed87dcd2d16224f40c82c34c87b5c3c (diff)
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 <samuel.pitoiset@gmail.com> Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7479>
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py3
1 files changed, 3 insertions, 0 deletions
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')),