[Mesa-dev] [PATCH 07/13] nir: Transform expressions of b2f(a) and b2f(b) to a || b

Thomas Helland thomashelland90 at gmail.com
Thu Aug 2 21:10:45 UTC 2018


2018-08-02 20:19 GMT+02:00 Ian Romanick <idr at freedesktop.org>:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> 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).
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/compiler/nir/nir_opt_algebraic.py | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 8300d6d01f5..4d60467fbac 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', ('fmin', ('b2f', a), ('b2f', b)), 0.0), ('ior', a, b)),

Maybe I'm just too sleepy, but shouldn't this be either

(('fne', ('fmax', ('b2f', a), ('b2f', b)), 0.0), ('ior', a, b)),

or

(('fne', ('fmin', ('b2f', a), ('b2f', b)), 0.0), ('iand', 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)),
> --
> 2.14.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list