From ee63933a73653564c490cff1f841d98e6265df97 Mon Sep 17 00:00:00 2001 From: Ian Romanick <ian.d.romanick@intel.com> Date: Wed, 2 Mar 2016 15:39:09 -0800 Subject: [PATCH] nir: Distribute binary operations with constants into bcsel MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This was specifically designed to simplify 1+mix(0, a-1, condition) to mix(1, a, condition) by pushing the 1+ inside. Skylake, Broadwell, and Haswell had similar results. Skylake shown. total instructions in shared programs: 14521753 -> 14521716 (<.01%) instructions in affected programs: 10619 -> 10582 (-0.35%) helped: 51 HURT: 14 helped stats (abs) min: 1 max: 12 xÌ: 1.43 xÌ: 1 helped stats (rel) min: 0.20% max: 3.58% xÌ: 1.01% xÌ: 0.95% HURT stats (abs) min: 1 max: 11 xÌ: 2.57 xÌ: 1 HURT stats (rel) min: 0.22% max: 1.75% xÌ: 1.20% xÌ: 1.32% 95% mean confidence interval for instructions value: -1.31 0.17 95% mean confidence interval for instructions %-change: -0.80% -0.27% Inconclusive result (value mean confidence interval includes 0). total cycles in shared programs: 533000205 -> 533003533 (<.01%) cycles in affected programs: 110610 -> 113938 (3.01%) helped: 43 HURT: 28 helped stats (abs) min: 6 max: 440 xÌ: 27.12 xÌ: 16 helped stats (rel) min: 0.39% max: 4.84% xÌ: 1.60% xÌ: 1.67% HURT stats (abs) min: 2 max: 3066 xÌ: 160.50 xÌ: 14 HURT stats (rel) min: 0.08% max: 77.78% xÌ: 5.16% xÌ: 0.62% 95% mean confidence interval for cycles value: -43.81 137.56 95% mean confidence interval for cycles %-change: -1.47% 3.60% Inconclusive result (value mean confidence interval includes 0). Ivy Bridge total instructions in shared programs: 10018840 -> 10018713 (<.01%) instructions in affected programs: 9431 -> 9304 (-1.35%) helped: 51 HURT: 3 helped stats (abs) min: 1 max: 80 xÌ: 2.76 xÌ: 1 helped stats (rel) min: 0.20% max: 16.43% xÌ: 1.16% xÌ: 0.81% HURT stats (abs) min: 1 max: 12 xÌ: 4.67 xÌ: 1 HURT stats (rel) min: 0.22% max: 1.33% xÌ: 0.59% xÌ: 0.22% 95% mean confidence interval for instructions value: -5.36 0.66 95% mean confidence interval for instructions %-change: -1.66% -0.46% Inconclusive result (value mean confidence interval includes 0). total cycles in shared programs: 87571944 -> 87572785 (<.01%) cycles in affected programs: 117234 -> 118075 (0.72%) helped: 42 HURT: 23 helped stats (abs) min: 2 max: 114 xÌ: 51.90 xÌ: 30 helped stats (rel) min: 0.11% max: 11.01% xÌ: 4.45% xÌ: 2.74% HURT stats (abs) min: 1 max: 2341 xÌ: 131.35 xÌ: 10 HURT stats (rel) min: 0.06% max: 37.11% xÌ: 2.75% xÌ: 0.61% 95% mean confidence interval for cycles value: -61.05 86.93 95% mean confidence interval for cycles %-change: -3.47% -0.33% Inconclusive result (value mean confidence interval includes 0). Sandy Bridge total instructions in shared programs: 10542933 -> 10542844 (<.01%) instructions in affected programs: 11487 -> 11398 (-0.77%) helped: 52 HURT: 3 helped stats (abs) min: 1 max: 40 xÌ: 1.96 xÌ: 1 helped stats (rel) min: 0.08% max: 8.16% xÌ: 0.90% xÌ: 0.72% HURT stats (abs) min: 1 max: 11 xÌ: 4.33 xÌ: 1 HURT stats (rel) min: 0.22% max: 1.22% xÌ: 0.55% xÌ: 0.22% 95% mean confidence interval for instructions value: -3.17 -0.07 95% mean confidence interval for instructions %-change: -1.13% -0.52% Instructions are helped. total cycles in shared programs: 146098397 -> 146097094 (<.01%) cycles in affected programs: 128140 -> 126837 (-1.02%) helped: 47 HURT: 8 helped stats (abs) min: 2 max: 333 xÌ: 29.21 xÌ: 18 helped stats (rel) min: 0.13% max: 5.04% xÌ: 1.18% xÌ: 0.95% HURT stats (abs) min: 1 max: 16 xÌ: 8.75 xÌ: 9 HURT stats (rel) min: 0.08% max: 0.43% xÌ: 0.30% xÌ: 0.34% 95% mean confidence interval for cycles value: -37.49 -9.90 95% mean confidence interval for cycles %-change: -1.22% -0.71% Cycles are helped. Iron Lake total instructions in shared programs: 7886711 -> 7886509 (<.01%) instructions in affected programs: 10425 -> 10223 (-1.94%) helped: 50 HURT: 2 helped stats (abs) min: 1 max: 78 xÌ: 4.08 xÌ: 1 helped stats (rel) min: 0.34% max: 15.38% xÌ: 1.12% xÌ: 0.54% HURT stats (abs) min: 1 max: 1 xÌ: 1.00 xÌ: 1 HURT stats (rel) min: 0.86% max: 0.91% xÌ: 0.89% xÌ: 0.89% 95% mean confidence interval for instructions value: -8.05 0.28 95% mean confidence interval for instructions %-change: -1.83% -0.26% Inconclusive result (value mean confidence interval includes 0). total cycles in shared programs: 178115324 -> 178114612 (<.01%) cycles in affected programs: 765726 -> 765014 (-0.09%) helped: 39 HURT: 1 helped stats (abs) min: 2 max: 276 xÌ: 18.31 xÌ: 8 helped stats (rel) min: <.01% max: 8.47% xÌ: 0.39% xÌ: 0.04% HURT stats (abs) min: 2 max: 2 xÌ: 2.00 xÌ: 2 HURT stats (rel) min: 0.03% max: 0.03% xÌ: 0.03% xÌ: 0.03% 95% mean confidence interval for cycles value: -32.07 -3.53 95% mean confidence interval for cycles %-change: -0.86% 0.10% Inconclusive result (%-change mean confidence interval includes 0). GM45 total instructions in shared programs: 4857762 -> 4857661 (<.01%) instructions in affected programs: 5523 -> 5422 (-1.83%) helped: 25 HURT: 1 helped stats (abs) min: 1 max: 78 xÌ: 4.08 xÌ: 1 helped stats (rel) min: 0.34% max: 13.61% xÌ: 1.04% xÌ: 0.52% HURT stats (abs) min: 1 max: 1 xÌ: 1.00 xÌ: 1 HURT stats (rel) min: 0.86% max: 0.86% xÌ: 0.86% xÌ: 0.86% 95% mean confidence interval for instructions value: -9.99 2.22 95% mean confidence interval for instructions %-change: -2.01% 0.08% Inconclusive result (value mean confidence interval includes 0). total cycles in shared programs: 122179674 -> 122179194 (<.01%) cycles in affected programs: 530162 -> 529682 (-0.09%) helped: 22 HURT: 1 helped stats (abs) min: 2 max: 292 xÌ: 21.91 xÌ: 7 helped stats (rel) min: <.01% max: 8.65% xÌ: 0.44% xÌ: 0.04% HURT stats (abs) min: 2 max: 2 xÌ: 2.00 xÌ: 2 HURT stats (rel) min: 0.03% max: 0.03% xÌ: 0.03% xÌ: 0.03% 95% mean confidence interval for cycles value: -46.56 4.82 95% mean confidence interval for cycles %-change: -1.20% 0.36% Inconclusive result (value mean confidence interval includes 0). Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> Reviewed-by: Elie Tournier <elie.tournier@collabora.com> --- src/compiler/nir/nir_opt_algebraic.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 3cc910a8a60..6dc19d9b121 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -604,6 +604,21 @@ for op in ['flt', 'fge', 'feq', 'fne', ('bcsel', 'a', (op, 'd', 'b'), (op, 'd', 'c'))), ] + +# For example, this converts things like +# +# 1 + mix(0, a - 1, condition) +# +# into +# +# mix(1, (a-1)+1, condition) +# +# Other optimizations will rearrange the constants. +for op in ['fadd', 'fmul', 'iadd', 'imul']: + optimizations += [ + ((op, ('bcsel(is_used_once)', a, '#b', c), '#d'), ('bcsel', a, (op, b, d), (op, c, d))) + ] + # This section contains "late" optimizations that should be run before # creating ffmas and calling regular optimizations for the final time. # Optimizations should go here if they help code generation and conflict -- 2.30.2