From b77070e293cda240a3326ff33e8f48c005ca0c25 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 23 Jan 2018 10:00:55 +0800 Subject: [PATCH] nir/algebraic: Use value range analysis to eliminate tautological compares MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It's only one application on one platform (Haswell) that's affected, but spills and fills increase quite dramatically. :( All Gen8+ platforms had similar results. (Ice Lake shown) total instructions in shared programs: 16320850 -> 16297320 (-0.14%) instructions in affected programs: 448012 -> 424482 (-5.25%) helped: 1938 HURT: 0 helped stats (abs) min: 2 max: 264 x̄: 12.14 x̃: 10 helped stats (rel) min: 0.35% max: 43.75% x̄: 5.85% x̃: 5.38% 95% mean confidence interval for instructions value: -12.80 -11.48 95% mean confidence interval for instructions %-change: -5.99% -5.72% Instructions are helped. total cycles in shared programs: 367496943 -> 367221624 (-0.07%) cycles in affected programs: 8557232 -> 8281913 (-3.22%) helped: 1907 HURT: 26 helped stats (abs) min: 4 max: 12802 x̄: 147.21 x̃: 48 helped stats (rel) min: 0.03% max: 75.85% x̄: 5.55% x̃: 3.94% HURT stats (abs) min: 4 max: 1870 x̄: 208.23 x̃: 20 HURT stats (rel) min: 0.16% max: 32.11% x̄: 8.31% x̃: 0.79% 95% mean confidence interval for cycles value: -165.38 -119.48 95% mean confidence interval for cycles %-change: -5.68% -5.04% Cycles are helped. LOST: 1 GAINED: 0 Haswell total instructions in shared programs: 13374211 -> 13353925 (-0.15%) instructions in affected programs: 349868 -> 329582 (-5.80%) helped: 1669 HURT: 1 helped stats (abs) min: 1 max: 264 x̄: 12.57 x̃: 10 helped stats (rel) min: 0.12% max: 46.81% x̄: 6.86% x̃: 6.49% HURT stats (abs) min: 700 max: 700 x̄: 700.00 x̃: 700 HURT stats (rel) min: 64.34% max: 64.34% x̄: 64.34% x̃: 64.34% 95% mean confidence interval for instructions value: -13.25 -11.04 95% mean confidence interval for instructions %-change: -7.01% -6.63% Instructions are helped. total cycles in shared programs: 375763544 -> 375535444 (-0.06%) cycles in affected programs: 6932686 -> 6704586 (-3.29%) helped: 1622 HURT: 48 helped stats (abs) min: 2 max: 12229 x̄: 148.31 x̃: 68 helped stats (rel) min: 0.06% max: 74.03% x̄: 5.94% x̃: 4.12% HURT stats (abs) min: 3 max: 7451 x̄: 259.44 x̃: 41 HURT stats (rel) min: 0.05% max: 54.99% x̄: 8.52% x̃: 2.88% 95% mean confidence interval for cycles value: -159.86 -113.31 95% mean confidence interval for cycles %-change: -5.86% -5.18% Cycles are helped. total spills in shared programs: 23258 -> 23401 (0.61%) spills in affected programs: 54 -> 197 (264.81%) helped: 4 HURT: 2 total fills in shared programs: 34775 -> 34850 (0.22%) fills in affected programs: 52 -> 127 (144.23%) helped: 4 HURT: 1 LOST: 5 GAINED: 0 Ivy Bridge total instructions in shared programs: 11996051 -> 11977964 (-0.15%) instructions in affected programs: 346679 -> 328592 (-5.22%) helped: 1508 HURT: 0 helped stats (abs) min: 2 max: 198 x̄: 11.99 x̃: 10 helped stats (rel) min: 0.26% max: 19.83% x̄: 5.73% x̃: 5.43% 95% mean confidence interval for instructions value: -12.65 -11.34 95% mean confidence interval for instructions %-change: -5.86% -5.60% Instructions are helped. total cycles in shared programs: 179891389 -> 179691339 (-0.11%) cycles in affected programs: 7869479 -> 7669429 (-2.54%) helped: 1485 HURT: 23 helped stats (abs) min: 1 max: 12615 x̄: 136.16 x̃: 54 helped stats (rel) min: 0.02% max: 71.84% x̄: 4.69% x̃: 3.49% HURT stats (abs) min: 1 max: 403 x̄: 93.48 x̃: 6 HURT stats (rel) min: 0.04% max: 34.01% x̄: 8.68% x̃: 0.81% 95% mean confidence interval for cycles value: -154.59 -110.73 95% mean confidence interval for cycles %-change: -4.79% -4.19% Cycles are helped. Sandy Bridge total instructions in shared programs: 10829247 -> 10828844 (<.01%) instructions in affected programs: 21258 -> 20855 (-1.90%) helped: 88 HURT: 0 helped stats (abs) min: 2 max: 17 x̄: 4.58 x̃: 5 helped stats (rel) min: 0.52% max: 3.92% x̄: 2.05% x̃: 2.21% 95% mean confidence interval for instructions value: -5.03 -4.13 95% mean confidence interval for instructions %-change: -2.21% -1.89% Instructions are helped. total cycles in shared programs: 154035437 -> 154024591 (<.01%) cycles in affected programs: 430176 -> 419330 (-2.52%) helped: 78 HURT: 10 helped stats (abs) min: 2 max: 4649 x̄: 143.06 x̃: 32 helped stats (rel) min: 0.05% max: 6.02% x̄: 2.03% x̃: 1.07% HURT stats (abs) min: 3 max: 265 x̄: 31.30 x̃: 6 HURT stats (rel) min: 0.10% max: 8.67% x̄: 1.03% x̃: 0.21% 95% mean confidence interval for cycles value: -232.53 -13.97 95% mean confidence interval for cycles %-change: -2.13% -1.23% Cycles are helped. Iron Lake and GM45 had similar results. (Iron Lake shown) total instructions in shared programs: 8137402 -> 8137248 (<.01%) instructions in affected programs: 2280 -> 2126 (-6.75%) helped: 10 HURT: 0 helped stats (abs) min: 12 max: 19 x̄: 15.40 x̃: 15 helped stats (rel) min: 3.90% max: 11.73% x̄: 7.19% x̃: 6.95% 95% mean confidence interval for instructions value: -17.69 -13.11 95% mean confidence interval for instructions %-change: -8.99% -5.39% Instructions are helped. total cycles in shared programs: 188538716 -> 188583424 (0.02%) cycles in affected programs: 69326 -> 114034 (64.49%) helped: 0 HURT: 10 HURT stats (abs) min: 2068 max: 7686 x̄: 4470.80 x̃: 4870 HURT stats (rel) min: 27.20% max: 173.66% x̄: 69.55% x̃: 59.41% 95% mean confidence interval for cycles value: 2830.86 6110.74 95% mean confidence interval for cycles %-change: 39.18% 99.91% Cycles are HURT. Reviewed-by: Caio Marcelo de Oliveira Filho --- src/compiler/nir/nir_opt_algebraic.py | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index d3f6c196e3b..0711f491a4c 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -798,33 +798,33 @@ optimizations = [ (('fmax', ('fadd', ('fmul', ('fsat', a), ('fneg', ('fsat', a))), 1.0), 0.0), ('fadd', ('fmul', ('fsat', a), ('fneg', ('fsat', a))), 1.0)), (('fmax', ('fadd', ('fneg', ('fmul', ('fsat', a), ('fsat', a))), 1.0), 0.0), ('fadd', ('fneg', ('fmul', ('fsat', a), ('fsat', a))), 1.0)), - (('fne(is_not_used_by_if)', 'a(is_not_zero)', 0.0), True), - (('feq(is_not_used_by_if)', 'a(is_not_zero)', 0.0), False), + (('fne', 'a(is_not_zero)', 0.0), True), + (('feq', 'a(is_not_zero)', 0.0), False), - (('fge(is_not_used_by_if)', 'a(is_not_negative)', 'b(is_not_positive)'), True), - (('fge(is_not_used_by_if)', 'b(is_not_positive)', 'a(is_gt_zero)'), False), - (('fge(is_not_used_by_if)', 'a(is_lt_zero)', 'b(is_not_negative)'), False), - (('fge(is_not_used_by_if)', 'b(is_not_negative)', 'a(is_not_positive)'), True), + (('fge', 'a(is_not_negative)', 'b(is_not_positive)'), True), + (('fge', 'b(is_not_positive)', 'a(is_gt_zero)'), False), + (('fge', 'a(is_lt_zero)', 'b(is_not_negative)'), False), + (('fge', 'b(is_not_negative)', 'a(is_not_positive)'), True), - (('flt(is_not_used_by_if)', 'a(is_not_negative)', 'b(is_not_positive)'), False), - (('flt(is_not_used_by_if)', 'b(is_not_positive)', 'a(is_gt_zero)'), True), - (('flt(is_not_used_by_if)', 'a(is_lt_zero)', 'b(is_not_negative)'), True), - (('flt(is_not_used_by_if)', 'b(is_not_negative)', 'a(is_not_positive)'), False), + (('flt', 'a(is_not_negative)', 'b(is_not_positive)'), False), + (('flt', 'b(is_not_positive)', 'a(is_gt_zero)'), True), + (('flt', 'a(is_lt_zero)', 'b(is_not_negative)'), True), + (('flt', 'b(is_not_negative)', 'a(is_not_positive)'), False), - (('ine(is_not_used_by_if)', 'a(is_not_zero)', 0), True), - (('ieq(is_not_used_by_if)', 'a(is_not_zero)', 0), False), + (('ine', 'a(is_not_zero)', 0), True), + (('ieq', 'a(is_not_zero)', 0), False), - (('ige(is_not_used_by_if)', 'a(is_not_negative)', 'b(is_not_positive)'), True), - (('ige(is_not_used_by_if)', 'b(is_not_positive)', 'a(is_gt_zero)'), False), - (('ige(is_not_used_by_if)', 'a(is_lt_zero)', 'b(is_not_negative)'), False), - (('ige(is_not_used_by_if)', 'b(is_not_negative)', 'a(is_not_positive)'), True), + (('ige', 'a(is_not_negative)', 'b(is_not_positive)'), True), + (('ige', 'b(is_not_positive)', 'a(is_gt_zero)'), False), + (('ige', 'a(is_lt_zero)', 'b(is_not_negative)'), False), + (('ige', 'b(is_not_negative)', 'a(is_not_positive)'), True), - (('ilt(is_not_used_by_if)', 'a(is_not_negative)', 'b(is_not_positive)'), False), - (('ilt(is_not_used_by_if)', 'b(is_not_positive)', 'a(is_gt_zero)'), True), - (('ilt(is_not_used_by_if)', 'a(is_lt_zero)', 'b(is_not_negative)'), True), - (('ilt(is_not_used_by_if)', 'b(is_not_negative)', 'a(is_not_positive)'), False), + (('ilt', 'a(is_not_negative)', 'b(is_not_positive)'), False), + (('ilt', 'b(is_not_positive)', 'a(is_gt_zero)'), True), + (('ilt', 'a(is_lt_zero)', 'b(is_not_negative)'), True), + (('ilt', 'b(is_not_negative)', 'a(is_not_positive)'), False), - (('ult(is_not_used_by_if)', 0, 'a(is_gt_zero)'), True), + (('ult', 0, 'a(is_gt_zero)'), True), # Packing and then unpacking does nothing (('unpack_64_2x32_split_x', ('pack_64_2x32_split', a, b)), a), -- 2.30.2