Stream: git-wasmtime

Topic: wasmtime / PR #15161 cranelift: Group blocks belonging to...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 13:20):

Amanieu opened PR #15161 from Amanieu:group_loops to bytecodealliance:main:

This significantly helps register allocators that only split live ranges linearly since it avoids live range splits in the middle of a loop when this is not necessary.

Sightglass benchmarks on my system are quite noisy, but there is a geomean 2-3% speedup in compilation time due to reduced time spent in regalloc. Execution time speedup is around geomean 1%, with some benchmarks getting over 10% speedup. The actual time spent in group_loops is tiny, only 0.1% of total compilation time (measured using a sampling profiler).

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 13:20):

Amanieu requested wasmtime-compiler-s390x-reviewers for a review on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 13:20):

Amanieu removed the review request for wasmtime-compiler-reviewers from PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 13:20):

Amanieu requested cfallin for a review on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 13:20):

Amanieu requested wasmtime-compiler-reviewers for a review on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 13:58):

fitzgen commented on PR #15161:

Thanks!

Sightglass benchmarks on my system are quite noisy, but there is a geomean 2-3% speedup in compilation time due to reduced time spent in regalloc. Execution time speedup is around geomean 1%, with some benchmarks getting over 10% speedup. The actual time spent in group_loops is tiny, only 0.1% of total compilation time (measured using a sampling profiler).

Clarification: is this when running default.suite?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:00):

Amanieu commented on PR #15161:

Yes, this was with default.suite. I can re-run some specific benchmarks if you want particular numbers.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

:memo: fitzgen submitted PR review:

LGTM modulo a few nitpicks below -- thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

:speech_balloon: fitzgen created PR review comment:

This should already be available if we changed the above

                    let r = loop_index(loops.innermost_loop(block));

to

                    let lp = loops.innermost_loop(block);
                    let r = loop_index(lp);

which maybe LLVM could figure out on its own, but additionally lets readers not have to double check whether they should be concerned about subtraction overflow.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

:speech_balloon: fitzgen created PR review comment:

To check my understanding: this is not a SecondaryMap because we want to effectively key on Option<Loop> rather than the Loop entity itself?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

:speech_balloon: fitzgen created PR review comment:

Shouldn't this be provided already by Context::clear? This seems like something we should be able to assert, because the only way this wouldn't be the case was if someone reused a context without clearing it first, which is an API contract violation.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

:speech_balloon: fitzgen created PR review comment:

Would it be possible to make this something like

let mut stack: SmallVec<[_; 8]> = smallvec![(0usize, loop_blocks[0].iter())];

or even just

let mut stack: SmallVec<[_; 8]> = smallvec![loop_blocks[0].iter()];

?

I think that would make this a little easier on code readers (and also same nitpick about the r variable name, but I think the iterator version makes it go away completely).

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

:speech_balloon: fitzgen created PR review comment:

nitpick: can we name this loop_idx or something instead of r?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:26):

fitzgen commented on PR #15161:

Yes, this was with default.suite. I can re-run some specific benchmarks if you want particular numbers.

Nope, default.suite is fine! Was just curious

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 14:29):

fitzgen commented on PR #15161:

Ah, well, also double checking: was this a recent-ish checkout of Sightglass? Like within the last ~month? Specifically, is default.suite a symlink to pca-20-min.suite in your checkout? If so then all good. If not, then pulling and rebenching would be appreciated.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:15):

:memo: cfallin submitted PR review:

Some thoughts below -- thanks for this!

Also a high-level thought/question: did you consider approaches that worked in a more "inline" way, by altering the choice order of the initial DFS that computes the block lowering order? I ask because it seems to me that at least in principle, visiting edges to successors that have the same inner loop first-in-RPO (so last-in-DFS-computing-PO I think?) should give a similar effect, and would be cheaper still. To be clear I'm not overly concerned about your measured average overhead, but I am concerned about (i) pathological worst-case behavior when we are allocating based on CFG shape, and (ii) complexity of the code, where, all else equal, it'd be great to avoid a pass with a subtle design. If not that, at least it'd be good to understand the worst-case memory behavior here: it should be linear because blocks only accumulate into the list for their innermost loop, not all containing loops, right? And the stack has depth at most O(blocks)?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:15):

:speech_balloon: cfallin created PR review comment:

Let's add a clarification here (at least this addresses a concern I had initially): while CLIF may have irreducible loops (in the sense of cycles in the CFG), the loop analysis does not classify these as loops, because it only finds natural loops (those with a single entry); and by definition, the DFS will find the header first, so this statement is true.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:15):

:speech_balloon: cfallin created PR review comment:

regalloc2 doesn't have any requirements on block order; perhaps you're thinking of the lowering algorithm, which does require seeing uses before defs?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:15):

:speech_balloon: cfallin created PR review comment:

regalloc2 doesn't have any requirements on block order; perhaps you're thinking of the lowering algorithm, which does require seeing uses before defs?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:38):

:memo: Amanieu submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:38):

:speech_balloon: Amanieu created PR review comment:

Yes. We could also do this with a SecondaryMap and a separate Vec for the non-loop blocks, but I felt a single Vec was cleaner.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:39):

:memo: Amanieu submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:39):

:speech_balloon: Amanieu created PR review comment:

I wasn't sure about the exact API contract. If we can safely assume that the loop analysis results are never stale then it should be safe to remove this.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 16:54):

Amanieu commented on PR #15161:

Regarding the DFS idea: this is actually something that I used to do in my compiler. However it turns out that this doesn't work in all cases.

Consider the test case in blockorder.rs: the only DFS choice here is whether you visit 2 or 3 first. This means that the only 2 RPOs that it can produce are:

Regarding complexity, this pass is linear and uses O(blocks) time and memory. The stack size is the maximum loop depth, and the total set of Items are one for each block and one for each loop.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 18:14):

cfallin commented on PR #15161:

Regarding the DFS idea: this is actually something that I used to do in my compiler. However it turns out that this doesn't work in all cases.

Consider the test case in blockorder.rs: the only DFS choice here is whether you visit 2 or 3 first. This means that the only 2 RPOs that it can produce are:

* 0, 1, 3, 5, 2, 4, 6

* 0, 1, 2, 4, 3, 5, 6

(assuming you're referring to this CFG)

Ah, I see, yeah -- the fundamental issue is that we would need to interleave the DFS subtrees because each contains "in-loop" and "out-of-loop" blocks. I guess one could somehow "defer" blocks but at that point the complexity tradeoff becomes a lot less clear. Separate from-the-top sort pass as you've done seems fine, then. Thanks for clarifying!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 18:16):

:thumbs_up: cfallin submitted PR review:

LGTM from me, once my nits above and Nick's comments are addressed too.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:44):

github-actions[bot] added the label cranelift:area:machinst on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:44):

github-actions[bot] added the label cranelift on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:44):

github-actions[bot] added the label cranelift:area:aarch64 on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:44):

github-actions[bot] added the label cranelift:area:x64 on PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 20:57):

Amanieu updated PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 21:45):

:thumbs_up: fitzgen submitted PR review:

Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 21:45):

fitzgen added PR #15161 cranelift: Group blocks belonging to the same loop together during lowering to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 22:09):

:check: fitzgen merged PR #15161.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 05 2026 at 22:09):

fitzgen removed PR #15161 cranelift: Group blocks belonging to the same loop together during lowering from the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 06 2026 at 21:23):

fitzgen commented on PR #15161:

Some nice compilation speedups from (I'm assuming) this PR: https://github.com/bytecodealliance/are-we-fast-yet/actions/runs/42120691141

(No execution difference though)


Last updated: Nov 19 2026 at 20:05 UTC