wraitii opened PR #15201 from wraitii:fix/licm-separate-loops to bytecodealliance:main:
The elaborator’s loop stack can include a loop that dominates the current block but has already exited. Treating the stack as a nested loop chain can hoist instructions across that unrelated loop, extending live ranges without reducing repeated work.
Pseudocode example of the issue:
hot = n do: hot -= 1 while hot != 0 cold = n do: step = unsigned(n) >> (n & 63) cold -= step while cold != 0Incorrect placement before the fix:
step = unsigned(n) >> (n & 63) // hoisted across the unrelated hot loop hot = n do: hot -= 1 while hot != 0 cold = n do: cold -= step while cold != 0The fix places step after the hot loop, before the cold loop. The code remains correct in both cases but the generation is significantly worse, especially as this increases register pressure.
wraitii removed the review request for wasmtime-compiler-reviewers from PR #15201.
wraitii requested alexcrichton for a review on PR #15201.
wraitii requested wasmtime-compiler-reviewers for a review on PR #15201.
wraitii edited PR #15201:
The elaborator’s loop stack can include a loop that dominates the current block but has already exited. Treating the stack as a nested loop chain can hoist instructions across that unrelated loop, extending live ranges without reducing repeated work.
Pseudocode example of the issue:
hot = n do: hot -= 1 if random() > 0.5: // Un-necessary but this shows that hoisting before is generally incorrect. return while hot != 0 cold = n do: step = unsigned(n) >> (n & 63) cold -= step while cold != 0Incorrect placement before the fix:
step = unsigned(n) >> (n & 63) // hoisted across the unrelated hot loop hot = n do: hot -= 1 if random() > 0.5: return while hot != 0 cold = n do: cold -= step while cold != 0The fix places step after the hot loop, before the cold loop. The code remains correct in both cases but the generation is significantly worse, especially as this increases register pressure.
github-actions[bot] added the label cranelift on PR #15201.
alexcrichton removed the review request for alexcrichton from PR #15201.
alexcrichton requested fitzgen for a review on PR #15201.
wraitii edited PR #15201:
The elaborator’s loop stack can include a loop that dominates the current block but has already exited. Treating the stack as a nested loop chain can hoist instructions across that unrelated loop, extending live ranges without reducing repeated work.
Pseudocode example of the issue:
hot = n do: hot -= 1 if random() > 0.5: // Un-necessary but this shows that hoisting before is generally incorrect. return while hot != 0 cold = n do: step = unsigned(n) >> (n & 63) cold -= step while cold != 0Incorrect placement before the fix:
step = unsigned(n) >> (n & 63) // hoisted across the unrelated hot loop hot = n do: hot -= 1 if random() > 0.5: return while hot != 0 cold = n do: cold -= step while cold != 0The fix places step after the hot loop, before the cold loop. The code remains correct in both cases but the generation is significantly worse, especially as this increases register pressure.
PR written by Astra, the diff reads correct to me for the issue but i've been peepholing these, so feel free to pong back.
wraitii commented on PR #15201:
Ran Sightglass, it reports no significant changes on 29 workloads, 20 samples per engine.
:thumbs_up: cfallin submitted PR review:
Thanks!
cfallin added PR #15201 cranelift: fix LICM hoisting across separate loops to the merge queue.
:check: cfallin merged PR #15201.
cfallin removed PR #15201 cranelift: fix LICM hoisting across separate loops from the merge queue.
Last updated: Nov 19 2026 at 20:05 UTC