nir: implement loop invariant code motion (LICM) pass
Draft for now since checking for nir_intrinsic_can_reorder
is not sufficient and we first need to make use of ACCESS_CAN_SPECULATE
.
nir: implement loop invariant code motion (LICM) pass
This simple LICM pass hoists all loop-invariant instructions
from the loops' top-level control flow, skipping any nested CF.
The hoisted instructions are placed right before the loop.
Some GFX11 stats for the LICM pass. To me it looks quite beneficial.
Totals:
MaxWaves: 2415428 -> 2415370 (-0.00%); split: +0.00%, -0.00%
Instrs: 45343293 -> 45348124 (+0.01%); split: -0.01%, +0.02%
CodeSize: 235969680 -> 236004912 (+0.01%); split: -0.02%, +0.03%
VGPRs: 3093184 -> 3093604 (+0.01%); split: -0.01%, +0.02%
SpillSGPRs: 6739 -> 6266 (-7.02%); split: -14.39%, +7.37%
Latency: 298689752 -> 298154268 (-0.18%); split: -0.19%, +0.01%
InvThroughput: 48648767 -> 48517995 (-0.27%); split: -0.30%, +0.03%
VClause: 883754 -> 883291 (-0.05%); split: -0.07%, +0.01%
SClause: 1389428 -> 1388360 (-0.08%); split: -0.14%, +0.06%
Copies: 2927058 -> 2933079 (+0.21%); split: -0.09%, +0.29%
Branches: 894421 -> 894493 (+0.01%); split: -0.01%, +0.02%
PreSGPRs: 2445461 -> 2452543 (+0.29%); split: -0.02%, +0.31%
PreVGPRs: 2249733 -> 2250004 (+0.01%); split: -0.00%, +0.01%
VALU: 25275220 -> 25277648 (+0.01%); split: -0.00%, +0.01%
SALU: 4381250 -> 4386250 (+0.11%); split: -0.06%, +0.17%
VMEM: 1601083 -> 1601074 (-0.00%)
SMEM: 2469806 -> 2469239 (-0.02%)
VOPD: 8676 -> 8634 (-0.48%); split: +0.13%, -0.61%
Totals from 3028 (3.81% of 79395) affected shaders:
MaxWaves: 67564 -> 67506 (-0.09%); split: +0.03%, -0.12%
Instrs: 10937736 -> 10942567 (+0.04%); split: -0.05%, +0.10%
CodeSize: 56767708 -> 56802940 (+0.06%); split: -0.06%, +0.13%
VGPRs: 230816 -> 231236 (+0.18%); split: -0.09%, +0.27%
SpillSGPRs: 2957 -> 2484 (-16.00%); split: -32.80%, +16.81%
Latency: 126328770 -> 125793286 (-0.42%); split: -0.45%, +0.03%
InvThroughput: 24392034 -> 24261262 (-0.54%); split: -0.60%, +0.06%
VClause: 235601 -> 235138 (-0.20%); split: -0.24%, +0.05%
SClause: 300612 -> 299544 (-0.36%); split: -0.65%, +0.30%
Copies: 797707 -> 803728 (+0.75%); split: -0.32%, +1.08%
Branches: 316302 -> 316374 (+0.02%); split: -0.03%, +0.05%
PreSGPRs: 174184 -> 181266 (+4.07%); split: -0.25%, +4.32%
PreVGPRs: 201312 -> 201583 (+0.13%); split: -0.02%, +0.16%
VALU: 6094304 -> 6096732 (+0.04%); split: -0.02%, +0.06%
SALU: 1177225 -> 1182225 (+0.42%); split: -0.22%, +0.65%
VMEM: 392529 -> 392520 (-0.00%)
SMEM: 412587 -> 412020 (-0.14%)
VOPD: 2501 -> 2459 (-1.68%); split: +0.44%, -2.12%
PERCENTAGE DELTAS Shaders MaxWaves Instrs CodeSize VGPRs SpillSGPRs Latency InvThroughput VClause SClause Copies Branches PreSGPRs PreVGPRs VALU SALU VMEM SMEM VOPD
assassins_creed_valhalla 830 +0.03% -0.11% -0.17% -0.13% -53.73% -0.39% -0.76% +0.09% -0.53% +0.15% +0.04% +0.18% -0.02% -0.19% +0.31% . . -2.67%
control 4242 -0.01% -0.00% -0.03% +0.05% +7.58% -0.13% -0.07% +0.01% -0.08% +0.05% . +0.16% +0.03% +0.00% +0.03% . . .
cyberpunk_2077 2221 -0.00% -0.03% +0.08% +0.01% +6.41% -0.00% +0.20% -0.01% +0.39% -0.18% +0.01% +0.79% +0.02% +0.03% -0.24% . . .
dead_space 400 . -0.01% -0.03% . . -0.05% -0.02% . -0.02% . . +0.40% . . . . . .
deathloop 1130 +0.03% -0.01% -0.02% -0.05% +3.17% -0.33% -0.41% -0.02% +0.17% +0.19% +0.00% +3.82% -0.00% +0.02% +0.13% . . .
detroit_become_human 995 . . . . . . . . . . . . . . . . . .
deus_ex_md 8063 . -0.00% +0.00% . . -0.06% -0.02% . -0.02% -0.00% . -0.00% +0.00% . -0.00% . . .
doom_eternal 461 . +0.01% +0.04% . . -0.52% -1.13% -0.44% -1.11% +0.62% -0.01% +0.19% +0.15% +0.08% +0.15% . -0.46% -13.64%
dota2 3840 . . . . . . . . . . . . . . . . . .
dow3 280 . +0.00% +0.00% . . -0.00% -0.06% . . +0.01% . . . . +0.01% . . .
dredge 2517 . . . . . . . . . . . . . . . . . .
elden_ring 3733 -0.02% +0.03% +0.03% +0.20% +94.12% -0.21% -0.15% . +0.01% +0.35% +0.02% +0.23% +0.02% +0.01% +0.22% . . -0.24%
f1_23 4006 . -0.03% -0.03% . -11.11% -0.42% -0.28% +0.01% +0.24% -0.07% +0.02% +1.40% +0.00% +0.00% -0.16% . . .
farcry5 805 . +0.02% -0.01% . . -0.22% -1.04% . -0.49% +0.07% . +0.11% +0.00% +0.00% +0.06% . . .
god_of_war 1029 . +0.00% +0.00% +0.03% . -0.45% -0.28% . +0.03% -0.10% . +0.18% +0.03% -0.00% -0.04% . . .
gtav 2955 . . -0.00% . . -0.02% -0.01% . -0.01% . . +0.00% . . . . . .
heaven_d3d9_strict_float_ultra_4xaa 286 . +0.00% +0.01% . . -0.12% -0.05% . . . . . . . . . . .
hogwarts_legacy 887 . . +0.00% . . -0.02% -0.02% . . . . . . . . . . .
horizon_zero_dawn 1800 . +0.00% +0.00% . . -0.00% -0.00% . . +0.00% . . . +0.00% . . . .
madmax 922 . . . . . . . . . . . . . . . . . .
metro_exodus 2627 . -0.01% +0.00% . . -0.23% -0.30% -0.06% -0.06% -0.06% . +0.36% . -0.00% -0.05% . . +1.43%
PERCENTAGE DELTAS Shaders MaxWaves Instrs CodeSize VGPRs SpillSGPRs Latency InvThroughput VClause SClause Copies Branches PreSGPRs PreVGPRs VALU SALU VMEM SMEM VOPD
monster_hunter_world 1103 . -0.00% -0.01% . . -0.04% -0.03% . +0.05% +0.01% . -0.14% . -0.00% +0.01% . . .
nier 2422 . . . . . . . . . . . . . . . . . .
no_mans_sky 1978 . +0.00% -0.00% . . -0.00% -0.02% +0.01% . +0.00% . -0.01% . +0.00% . . . .
parallel_rdp 539 . . . . . . . . . . . . . . . . . .
persona_5 1566 . . . . . . . . . . . . . . . . . .
q2rtx 48 . +0.03% +0.06% . . -0.07% -0.47% . -0.07% +0.04% . +0.14% +0.86% +0.00% . . . .
rdr2 3649 . -0.00% -0.01% . -0.42% -0.26% -0.54% . -0.16% -0.03% . +0.16% +0.01% -0.00% -0.01% . . .
redout 2485 . -0.00% -0.00% . . -0.13% -0.00% . -0.01% . . +0.02% . . . . . .
resident_evil_village 1157 . -0.09% -0.07% +0.05% +2.90% -0.15% -0.06% +0.06% -1.04% -1.76% +0.06% +0.55% +0.02% +0.01% -0.85% . -0.22% .
second_extinction 437 . -0.00% -0.02% . . -0.04% -0.04% . -0.01% . . +0.03% . . . . . .
skyrim_dx9 3305 . -0.03% -0.03% +0.01% . -0.18% -0.41% . +0.02% -0.50% . +0.74% +0.02% -0.00% -0.24% . . .
sniper_elite_5 4278 . +0.12% +0.09% . . +0.01% +0.01% . . +1.25% -0.03% +0.03% +0.02% -0.01% +0.91% . . .
sottr 542 . . . . . . . . . . . . . . . . . .
spiderman_remastered 648 . -0.03% -0.02% . . -0.14% -0.14% . -0.34% -0.04% . -0.56% . -0.00% -0.02% . . .
talos_principle 1999 . +0.01% -0.03% . . -0.50% . . +0.08% +0.01% . +0.08% . . +0.02% . . .
the_last_of_us_part1 1198 -0.09% +0.23% +0.29% +0.24% +82.76% -0.63% +0.17% -0.15% -0.03% +1.29% +0.40% +1.67% +0.30% +0.19% +0.54% -0.05% -0.06% -1.85%
thewitness 3150 . . . . . . . . . . . . . . . . . .
total_warhammer_3 632 . -0.00% -0.00% . . -0.02% -0.00% . -0.08% . . +0.01% . . . . . .
war_thunder 2100 . -0.01% +0.02% . . -0.14% -0.13% -0.03% -0.15% -0.03% . +0.10% . -0.00% +0.01% . . .
worldofwarships 2130 . -0.00% -0.00% . . -0.02% . . -0.02% . . . . . . . . .
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
All affected 3028 -0.09% +0.04% +0.06% +0.18% -16.00% -0.42% -0.54% -0.20% -0.36% +0.75% +0.02% +4.07% +0.13% +0.04% +0.42% -0.00% -0.14% -1.68%
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 79395 -0.00% +0.01% +0.01% +0.01% -7.02% -0.18% -0.27% -0.05% -0.08% +0.21% +0.01% +0.29% +0.01% +0.01% +0.11% -0.00% -0.02% -0.48%
Edited by Daniel Schürmann