ir3: optimize more before opt_preamble
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

This prevents hoisting values to the preamble that might still get
optimized (away). This especially has a huge impact on binning variants
because many of their outputs got removed but we never optimized after
that.

fossildb stats:

Totals:
MaxWaves: 2765084 -> 2770308 (+0.19%); split: +0.19%, -0.00%
Instrs: 56289002 -> 56226045 (-0.11%); split: -0.13%, +0.02%
CodeSize: 118071672 -> 116551008 (-1.29%); split: -1.29%, +0.00%
NOPs: 9491112 -> 9477190 (-0.15%); split: -0.25%, +0.11%
MOVs: 1790085 -> 1789548 (-0.03%); split: -0.22%, +0.19%
Full: 2156693 -> 2140043 (-0.77%); split: -0.77%, +0.00%
(ss): 1329812 -> 1326394 (-0.26%); split: -0.66%, +0.40%
(sy): 686396 -> 686244 (-0.02%); split: -0.17%, +0.15%
(ss)-stall: 4995295 -> 4993233 (-0.04%); split: -0.69%, +0.65%
(sy)-stall: 19828966 -> 19833863 (+0.02%); split: -0.32%, +0.34%
STPs: 36271 -> 33249 (-8.33%)
LDPs: 45794 -> 42537 (-7.11%)
Preamble Instrs: 14467846 -> 13645555 (-5.68%); split: -5.69%, +0.01%
Early Preamble: 129346 -> 134346 (+3.87%); split: +3.89%, -0.02%
Cat0: 10450369 -> 10436616 (-0.13%); split: -0.23%, +0.10%
Cat1: 2787946 -> 2787085 (-0.03%); split: -0.15%, +0.12%
Cat2: 21265787 -> 21251803 (-0.07%); split: -0.07%, +0.01%
Cat3: 16207098 -> 16178995 (-0.17%); split: -0.17%, +0.00%
Cat5: 1596677 -> 1596707 (+0.00%)
Cat6: 854011 -> 848522 (-0.64%)
Cat7: 1597849 -> 1597052 (-0.05%); split: -0.13%, +0.08%

Totals from 22836 (11.41% of 200220) affected shaders:
MaxWaves: 335882 -> 341106 (+1.56%); split: +1.56%, -0.01%
Instrs: 6019621 -> 5956664 (-1.05%); split: -1.23%, +0.18%
CodeSize: 14192546 -> 12671882 (-10.71%); split: -10.74%, +0.03%
NOPs: 1107562 -> 1093640 (-1.26%); split: -2.18%, +0.92%
MOVs: 270465 -> 269928 (-0.20%); split: -1.43%, +1.23%
Full: 257820 -> 241170 (-6.46%); split: -6.47%, +0.01%
(ss): 156869 -> 153451 (-2.18%); split: -5.59%, +3.41%
(sy): 80161 -> 80009 (-0.19%); split: -1.46%, +1.27%
(ss)-stall: 573278 -> 571216 (-0.36%); split: -6.01%, +5.65%
(sy)-stall: 3537926 -> 3542823 (+0.14%); split: -1.78%, +1.92%
STPs: 30563 -> 27541 (-9.89%)
LDPs: 37112 -> 33855 (-8.78%)
Preamble Instrs: 2440099 -> 1617808 (-33.70%); split: -33.76%, +0.06%
Early Preamble: 9060 -> 14060 (+55.19%); split: +55.50%, -0.31%
Cat0: 1215965 -> 1202212 (-1.13%); split: -2.00%, +0.87%
Cat1: 475910 -> 475049 (-0.18%); split: -0.90%, +0.72%
Cat2: 1940479 -> 1926495 (-0.72%); split: -0.81%, +0.09%
Cat3: 1680902 -> 1652799 (-1.67%); split: -1.68%, +0.01%
Cat5: 151246 -> 151276 (+0.02%)
Cat6: 269190 -> 263701 (-2.04%)
Cat7: 174584 -> 173787 (-0.46%); split: -1.20%, +0.75%

Preamble improvements are even bigger on shaderdb:

total dwords in shared programs: 8800204 -> 8400960 (-4.54%)
dwords in affected programs: 1008384 -> 609140 (-39.59%)
helped: 3385
HURT: 14
helped stats (abs) min: 2 max: 1762 x̄: 118.02 x̃: 32
helped stats (rel) min: 0.21% max: 90.17% x̄: 32.93% x̃: 31.25%
HURT stats (abs)   min: 2 max: 32 x̄: 18.43 x̃: 26
HURT stats (rel)   min: 0.39% max: 16.67% x̄: 9.09% x̃: 13.13%
95% mean confidence interval for dwords value: -125.03 -109.88
95% mean confidence interval for dwords %-change: -33.46% -32.06%
Dwords are helped.

total preamble-inst in shared programs: 1274769 -> 1063479 (-16.57%)
preamble-inst in affected programs: 323660 -> 112370 (-65.28%)
helped: 3819
HURT: 5
helped stats (abs) min: 1 max: 1000 x̄: 55.33 x̃: 13
helped stats (rel) min: 0.61% max: 100.00% x̄: 53.55% x̃: 53.85%
HURT stats (abs)   min: 1 max: 9 x̄: 2.60 x̃: 1
HURT stats (rel)   min: 3.23% max: 6.34% x̄: 4.04% x̃: 3.70%
95% mean confidence interval for preamble-inst value: -58.84 -51.67
95% mean confidence interval for preamble-inst %-change: -54.22% -52.73%
Preamble-inst are helped.

total early-preamble in shared programs: 31297 -> 32057 (2.43%)
early-preamble in affected programs: 20 -> 780 (3800.00%)
helped: 780
HURT: 20
helped stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
helped stats (rel) min: 0.00% max: 0.00% x̄: 0.00% x̃: 0.00%
HURT stats (abs)   min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel)   min: 100.00% max: 100.00% x̄: 100.00% x̃: 100.00%
95% mean confidence interval for early-preamble value: 0.93 0.97
95% mean confidence interval for early-preamble %-change: -3.58% -1.42%
Inconclusive result (value mean confidence interval and %-change mean confidence interval disagree).

Signed-off-by: Job Noorman <jnoorman@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34311>
This commit is contained in:
Job Noorman 2025-04-01 12:00:15 +02:00 committed by Marge Bot
parent fca143946e
commit e31b1b649c

View file

@ -1163,11 +1163,6 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so,
progress |= OPT(s, ir3_nir_lower_64b_intrinsics);
progress |= OPT(s, nir_lower_64bit_phis);
/* Cleanup code leftover from lowering passes before opt_preamble */
if (progress) {
progress |= OPT(s, nir_opt_constant_folding);
}
progress |= OPT(s, ir3_nir_opt_subgroups, so);
if (so->compiler->load_shader_consts_via_preamble)
@ -1177,6 +1172,16 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so,
ir3_setup_const_state(s, so, ir3_const_state_mut(so));
}
/* Cleanup code leftover from lowering passes before opt_preamble */
if (progress) {
ir3_optimize_loop(so->compiler, options, s);
/* No need to run the optimize loop again if there's no progress after
* this point.
*/
progress = false;
}
/* Do the preamble before analysing UBO ranges, because it's usually
* higher-value and because it can result in eliminating some indirect UBO
* accesses where otherwise we'd have to push the whole range. However we