Mesa (master): nir/algebraic: optimize bitfield_select(a, b, 0) to iand(a, b)

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Nov 9 20:06:00 UTC 2020


Module: Mesa
Branch: master
Commit: 1c5271346af77724f0462d1acafaa49142569006
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1c5271346af77724f0462d1acafaa49142569006

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Fri Nov  6 16:43:41 2020 +0100

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 at gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7479>

---

 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')),



More information about the mesa-commit mailing list