From: Ian Romanick Date: Thu, 2 Aug 2018 00:18:07 +0000 (-0700) Subject: nir: Transform expressions of b2f(a) and b2f(b) to a || b X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=46e7c340d4939cf6b63b1301eb18647424a58837;p=mesa.git nir: Transform expressions of b2f(a) and b2f(b) to a || b All Gen6+ platforms had pretty similar results. (Skylake shown) total instructions in shared programs: 14277184 -> 14276964 (<.01%) instructions in affected programs: 10082 -> 9862 (-2.18%) helped: 37 HURT: 1 helped stats (abs) min: 1 max: 30 x̄: 5.97 x̃: 4 helped stats (rel) min: 0.14% max: 16.00% x̄: 5.23% x̃: 2.04% HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1 HURT stats (rel) min: 0.70% max: 0.70% x̄: 0.70% x̃: 0.70% 95% mean confidence interval for instructions value: -7.87 -3.71 95% mean confidence interval for instructions %-change: -6.98% -3.16% Instructions are helped. total cycles in shared programs: 532577990 -> 532577062 (<.01%) cycles in affected programs: 170959 -> 170031 (-0.54%) helped: 33 HURT: 9 helped stats (abs) min: 2 max: 120 x̄: 30.91 x̃: 30 helped stats (rel) min: 0.02% max: 7.65% x̄: 2.66% x̃: 1.13% HURT stats (abs) min: 2 max: 24 x̄: 10.22 x̃: 8 HURT stats (rel) min: 0.09% max: 1.79% x̄: 0.61% x̃: 0.22% 95% mean confidence interval for cycles value: -31.23 -12.96 95% mean confidence interval for cycles %-change: -2.90% -1.02% Cycles are helped. Iron Lake and GM45 had similar results. (Iron Lake shown) total instructions in shared programs: 7781539 -> 7781301 (<.01%) instructions in affected programs: 10169 -> 9931 (-2.34%) helped: 32 HURT: 0 helped stats (abs) min: 2 max: 20 x̄: 7.44 x̃: 6 helped stats (rel) min: 0.47% max: 17.02% x̄: 4.03% x̃: 1.88% 95% mean confidence interval for instructions value: -9.53 -5.34 95% mean confidence interval for instructions %-change: -5.94% -2.12% Instructions are helped. total cycles in shared programs: 177878590 -> 177878932 (<.01%) cycles in affected programs: 78706 -> 79048 (0.43%) helped: 7 HURT: 21 helped stats (abs) min: 6 max: 34 x̄: 24.57 x̃: 28 helped stats (rel) min: 0.15% max: 8.33% x̄: 4.66% x̃: 6.37% HURT stats (abs) min: 2 max: 86 x̄: 24.48 x̃: 22 HURT stats (rel) min: 0.01% max: 4.28% x̄: 1.21% x̃: 0.70% 95% mean confidence interval for cycles value: 0.30 24.13 95% mean confidence interval for cycles %-change: -1.52% 1.01% Inconclusive result (%-change mean confidence interval includes 0). v2: s/fmin/fmax/. Noticed by Thomas Helland. Signed-off-by: Ian Romanick Reviewed-by: Thomas Helland --- diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 8300d6d01f5..5ba469f5f65 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -166,6 +166,25 @@ optimizations = [ (('fge', ('fneg', ('b2f', a)), 0.0), ('inot', a)), + (('fne', ('fadd', ('b2f', a), ('b2f', b)), 0.0), ('ior', a, b)), + (('fne', ('fmax', ('b2f', a), ('b2f', b)), 0.0), ('ior', a, b)), + (('fne', ('bcsel', a, 1.0, ('b2f', b)) , 0.0), ('ior', a, b)), + (('fne', ('b2f', a), ('fneg', ('b2f', b))), ('ior', a, b)), + + # -(b2f(a) + b2f(b)) < 0 + # 0 < b2f(a) + b2f(b) + # 0 != b2f(a) + b2f(b) b2f must be 0 or 1, so the sum is non-negative + # a || b + (('flt', ('fneg', ('fadd', ('b2f', a), ('b2f', b))), 0.0), ('ior', a, b)), + (('flt', 0.0, ('fadd', ('b2f', a), ('b2f', b))), ('ior', a, b)), + + # Some optimizations (below) convert things like (a < b || c < b) into + # (min(a, c) < b). However, this interfers with the previous optimizations + # that try to remove comparisons with negated sums of b2f. This just + # breaks that apart. + (('flt', ('fmin', c, ('fneg', ('fadd', ('b2f', a), ('b2f', b)))), 0.0), + ('ior', ('flt', c, 0.0), ('ior', a, b))), + (('~flt', ('fadd', a, b), a), ('flt', b, 0.0)), (('~fge', ('fadd', a, b), a), ('fge', b, 0.0)), (('~feq', ('fadd', a, b), a), ('feq', b, 0.0)),