<div dir="ltr">re-associating based on whether or not something has a constant value of 1.0 seems a bit sneaky.  I think it's well within the rules but it seems like something that could bite you.<br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 13, 2018 at 6:35 PM Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><br>
<br>
Instead of lowering as (a + c(b - a)), lower as (a(1 - c) + bc).  Since<br>
either a or b is 1.0, some of the multiplications drop out.<br>
<br>
I am CC'ing people who are responsible for drivers that set lower_flrp32<br>
as this patch will likely affect shader-db results for those drivers.<br>
<br>
No changes on any Gen6+ platform.<br>
<br>
Iron Lake<br>
total instructions in shared programs: 7745041 -> 7731595 (-0.17%)<br>
instructions in affected programs: 1647106 -> 1633660 (-0.82%)<br>
helped: 5522<br>
HURT: 281<br>
helped stats (abs) min: 1 max: 12 x̄: 2.53 x̃: 2<br>
helped stats (rel) min: 0.14% max: 12.00% x̄: 1.45% x̃: 0.99%<br>
HURT stats (abs)   min: 1 max: 5 x̄: 1.94 x̃: 2<br>
HURT stats (rel)   min: 0.13% max: 4.17% x̄: 0.74% x̃: 0.68%<br>
95% mean confidence interval for instructions value: -2.35 -2.28<br>
95% mean confidence interval for instructions %-change: -1.38% -1.31%<br>
Instructions are helped.<br>
<br>
total cycles in shared programs: 178004318 -> 177937186 (-0.04%)<br>
cycles in affected programs: 31813800 -> 31746668 (-0.21%)<br>
helped: 5420<br>
HURT: 631<br>
helped stats (abs) min: 2 max: 168 x̄: 13.15 x̃: 12<br>
helped stats (rel) min: 0.01% max: 6.37% x̄: 0.67% x̃: 0.30%<br>
HURT stats (abs)   min: 2 max: 328 x̄: 6.57 x̃: 4<br>
HURT stats (rel)   min: 0.01% max: 2.78% x̄: 0.16% x̃: 0.11%<br>
95% mean confidence interval for cycles value: -11.35 -10.84<br>
95% mean confidence interval for cycles %-change: -0.60% -0.56%<br>
Cycles are helped.<br>
<br>
GM45<br>
total instructions in shared programs: 4777279 -> 4770160 (-0.15%)<br>
instructions in affected programs: 928555 -> 921436 (-0.77%)<br>
helped: 2902<br>
HURT: 149<br>
helped stats (abs) min: 1 max: 12 x̄: 2.55 x̃: 2<br>
helped stats (rel) min: 0.14% max: 11.11% x̄: 1.38% x̃: 0.91%<br>
HURT stats (abs)   min: 1 max: 5 x̄: 1.93 x̃: 2<br>
HURT stats (rel)   min: 0.13% max: 4.00% x̄: 0.72% x̃: 0.68%<br>
95% mean confidence interval for instructions value: -2.38 -2.28<br>
95% mean confidence interval for instructions %-change: -1.33% -1.23%<br>
Instructions are helped.<br>
<br>
total cycles in shared programs: 122063992 -> 122021958 (-0.03%)<br>
cycles in affected programs: 20838672 -> 20796638 (-0.20%)<br>
helped: 2921<br>
HURT: 454<br>
helped stats (abs) min: 2 max: 168 x̄: 15.40 x̃: 14<br>
helped stats (rel) min: 0.01% max: 6.37% x̄: 0.67% x̃: 0.29%<br>
HURT stats (abs)   min: 2 max: 328 x̄: 6.49 x̃: 4<br>
HURT stats (rel)   min: 0.02% max: 2.78% x̄: 0.16% x̃: 0.11%<br>
95% mean confidence interval for cycles value: -12.86 -12.04<br>
95% mean confidence interval for cycles %-change: -0.59% -0.53%<br>
Cycles are helped.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><br>
Cc: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>><br>
Cc: Rob Clark <<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>><br>
Cc: Eric Anholt <<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>><br>
---<br>
 src/compiler/nir/nir_opt_algebraic.py | 6 ++++++<br>
 1 file changed, 6 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py<br>
index e770a61d9ff..f11a987c462 100644<br>
--- a/src/compiler/nir/nir_opt_algebraic.py<br>
+++ b/src/compiler/nir/nir_opt_algebraic.py<br>
@@ -116,6 +116,10 @@ optimizations = [<br>
    (('~flrp', 0.0, a, b), ('fmul', a, b)),<br>
    (('~flrp', a, b, ('b2f', c)), ('bcsel', c, b, a), 'options->lower_flrp32'),<br>
    (('~flrp', a, 0.0, c), ('fadd', ('fmul', ('fneg', a), c), a)),<br>
+   (('flrp@32', 1.0, b, c), ('fadd', ('fsub', 1.0, c), ('fmul', b, c)), 'options->lower_flrp32'),<br>
+   (('flrp@64', 1.0, b, c), ('fadd', ('fsub', 1.0, c), ('fmul', b, c)), 'options->lower_flrp64'),<br>
+   (('flrp@32', a, 1.0, c), ('fadd', a, ('fmul', c, ('fsub', 1.0, a))), 'options->lower_flrp32'),<br>
+   (('flrp@64', a, 1.0, c), ('fadd', a, ('fmul', c, ('fsub', 1.0, a))), 'options->lower_flrp64'),<br>
    (('flrp@32', a, b, c), ('fadd', ('fmul', c, ('fsub', b, a)), a), 'options->lower_flrp32'),<br>
    (('flrp@64', a, b, c), ('fadd', ('fmul', c, ('fsub', b, a)), a), 'options->lower_flrp64'),<br>
    (('ffract', a), ('fsub', a, ('ffloor', a)), 'options->lower_ffract'),<br>
@@ -125,6 +129,8 @@ optimizations = [<br>
    (('~fadd', a, ('fmul', ('b2f', c), ('fadd', b, ('fneg', a)))), ('bcsel', c, b, a), 'options->lower_flrp32'),<br>
    (('~fadd@32', a, ('fmul',         c , ('fadd', b, ('fneg', a)))), ('flrp', a, b, c), '!options->lower_flrp32'),<br>
    (('~fadd@64', a, ('fmul',         c , ('fadd', b, ('fneg', a)))), ('flrp', a, b, c), '!options->lower_flrp64'),<br>
+   (('~fadd@32', 1.0, ('fmul',       c , ('fadd', b,       -1.0 ))), ('fadd', ('fsub', 1.0, c), ('fmul', b, c)), 'options->lower_flrp32'),<br>
+   (('~fadd@64', 1.0, ('fmul',       c , ('fadd', b,       -1.0 ))), ('fadd', ('fsub', 1.0, c), ('fmul', b, c)), 'options->lower_flrp64'),<br>
    (('ffma', a, b, c), ('fadd', ('fmul', a, b), c), 'options->lower_ffma'),<br>
    (('~fadd', ('fmul', a, b), c), ('ffma', a, b, c), 'options->fuse_ffma'),<br>
<br>
-- <br>
2.14.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>