summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2020-03-05 13:32:07 -0800
committerIan Romanick <ian.d.romanick@intel.com>2020-05-07 10:55:50 -0700
commit3b6449d45317f4441eef464b415f5c65e5103dab (patch)
tree4f3688c4d22c86916d10f765b90afe48469cb099
parentf46eabf84e6a3227ce846f6725ad16517d146dae (diff)
nir/algebraic: Optimize some bfe patterns
v2: Use -x instead of 32-x in shift counts. Tiger Lake total instructions in shared programs: 17597691 -> 17597405 (<.01%) instructions in affected programs: 224557 -> 224271 (-0.13%) helped: 74 HURT: 17 helped stats (abs) min: 1 max: 71 x̄: 14.36 x̃: 7 helped stats (rel) min: 0.08% max: 1.80% x̄: 0.50% x̃: 0.37% HURT stats (abs) min: 1 max: 141 x̄: 45.71 x̃: 40 HURT stats (rel) min: 0.03% max: 3.55% x̄: 1.20% x̃: 1.14% 95% mean confidence interval for instructions value: -10.53 4.24 95% mean confidence interval for instructions %-change: -0.38% 0.01% Inconclusive result (value mean confidence interval includes 0). total cycles in shared programs: 333595656 -> 333180770 (-0.12%) cycles in affected programs: 70056467 -> 69641581 (-0.59%) helped: 91 HURT: 4 helped stats (abs) min: 1 max: 25174 x̄: 4571.40 x̃: 400 helped stats (rel) min: <.01% max: 2.23% x̄: 0.40% x̃: 0.21% HURT stats (abs) min: 1 max: 370 x̄: 277.75 x̃: 370 HURT stats (rel) min: 0.01% max: 0.04% x̄: 0.04% x̃: 0.04% 95% mean confidence interval for cycles value: -5981.55 -2752.89 95% mean confidence interval for cycles %-change: -0.48% -0.29% Cycles are helped. Ice Lake, Skylake, Broadwell, and Haswell had similar results. (Ice Lake shown) total instructions in shared programs: 16117204 -> 16116723 (<.01%) instructions in affected programs: 207109 -> 206628 (-0.23%) helped: 100 HURT: 0 helped stats (abs) min: 1 max: 9 x̄: 4.81 x̃: 7 helped stats (rel) min: 0.10% max: 1.58% x̄: 0.23% x̃: 0.20% 95% mean confidence interval for instructions value: -5.51 -4.11 95% mean confidence interval for instructions %-change: -0.27% -0.19% Instructions are helped. total cycles in shared programs: 330487341 -> 330082421 (-0.12%) cycles in affected programs: 68037050 -> 67632130 (-0.60%) helped: 89 HURT: 7 helped stats (abs) min: 2 max: 24610 x̄: 4567.07 x̃: 400 helped stats (rel) min: <.01% max: 1.52% x̄: 0.39% x̃: 0.22% HURT stats (abs) min: 1 max: 370 x̄: 221.29 x̃: 170 HURT stats (rel) min: 0.01% max: 1.66% x̄: 0.58% x̃: 0.04% 95% mean confidence interval for cycles value: -5780.79 -2655.05 95% mean confidence interval for cycles %-change: -0.42% -0.22% Cycles are helped. Ivy Bridge total instructions in shared programs: 11873641 -> 11873137 (<.01%) instructions in affected programs: 147464 -> 146960 (-0.34%) helped: 54 HURT: 0 helped stats (abs) min: 9 max: 10 x̄: 9.33 x̃: 9 helped stats (rel) min: 0.29% max: 0.41% x̄: 0.34% x̃: 0.34% 95% mean confidence interval for instructions value: -9.46 -9.20 95% mean confidence interval for instructions %-change: -0.35% -0.33% Instructions are helped. total cycles in shared programs: 175769085 -> 175549519 (-0.12%) cycles in affected programs: 60770592 -> 60551026 (-0.36%) helped: 54 HURT: 0 helped stats (abs) min: 252 max: 13434 x̄: 4066.04 x̃: 1290 helped stats (rel) min: 0.02% max: 0.74% x̄: 0.34% x̃: 0.26% 95% mean confidence interval for cycles value: -5323.59 -2808.48 95% mean confidence interval for cycles %-change: -0.41% -0.27% Cycles are helped. No changes on any earlier Intel platforms. Reviewed-by: Matt Turner <mattst88@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4156>
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 2d74a85711d..f9ebd5af4ad 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -1230,6 +1230,24 @@ optimizations.extend([
(('bfm', 'bits', ('iand', 31, 'offset')), ('bfm', 'bits', 'offset')),
(('bfm', ('iand', 31, 'bits'), 'offset'), ('bfm', 'bits', 'offset')),
+ # Section 8.8 (Integer Functions) of the GLSL 4.60 spec says:
+ #
+ # If bits is zero, the result will be zero.
+ #
+ # These patterns prevent other patterns from generating invalid results
+ # when count is zero.
+ (('ubfe', a, b, 0), 0),
+ (('ibfe', a, b, 0), 0),
+
+ (('ubfe', a, 0, '#b'), ('iand', a, ('ushr', 0xffffffff, ('ineg', b)))),
+
+ (('b2i32', ('i2b', ('ubfe', a, b, 1))), ('ubfe', a, b, 1)),
+ (('b2i32', ('i2b', ('ibfe', a, b, 1))), ('ubfe', a, b, 1)), # ubfe in the replacement is correct
+ (('ine', ('ibfe(is_used_once)', a, '#b', '#c'), 0), ('ine', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
+ (('ieq', ('ibfe(is_used_once)', a, '#b', '#c'), 0), ('ieq', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
+ (('ine', ('ubfe(is_used_once)', a, '#b', '#c'), 0), ('ine', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
+ (('ieq', ('ubfe(is_used_once)', a, '#b', '#c'), 0), ('ieq', ('iand', a, ('ishl', ('ushr', 0xffffffff, ('ineg', c)), b)), 0)),
+
(('ibitfield_extract', 'value', 'offset', 'bits'),
('bcsel', ('ieq', 0, 'bits'),
0,