Split hoisting can select unrelated loops / has bad edge cases
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start by tracing split hoisting and trimming in the register allocator, then compare their control-flow decisions against the examples in the issue and the attached CLIF repro. Check how candidate blocks relate to loop membership, dominance, and intervening uses. Done means the chosen fix handles the reported conditional and separate-loop cases without regressing the neutral and beneficial cases.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
When splitting lifetimes for register allocations, 'split hoisting' starts with a split at a register conflict. If that point is deeper than the bundle’s earliest range, it scans forward from the bundle start and selects the first block deeper than that start. It checks neither loop membership nor dominance, and ignores intervening uses.
There are a few cases:
Bad: conditional call that rejoins - identical with trimming only
As pseudocode:
acc = 0
for k in 0..n:
if k == 17:
helper()
acc += 1
return acc
Split hoisting decides to put the split before the loop, leading to a store/load around acc += 1. Trimming does the same thing independently.
In both cases this is arguably bad - only the if-branch should spill.
Bad: a later loop can spill in an earlier loop - trimming also unless #272
Slightly contrived example, but it's not implausible either:
if fast_path:
acc = 0
while n-- != 0:
acc += 1
else:
acc = 1
while n-- != 0:
helper() // opaque, clobbers acc
acc += 1
return acc
here the join at the end puts both loop acc in the same bundle, and hoisting ends up putting the split before the fast-path loop. This leads to spills in both loops, even though only the slow path would need them.
Neutral: loop with one use or a later use - trimming is identical
acc = n * n;
for a in 0..3:
opaque_call()
return acc;
Here both hoisting and trimming end up with the same logic: store once before, reload once after (of if used after call(), reload in the loop).
Good case: use before a call in a loop - beats trimming (depending)
x = argument
for n 0..times:
observe(x)
helper()
return x
Here hoisting leads to a store before the loop and a reload before the observe call. Trimming instead stores before helper and reloads after helper. Note that this leads to hoisting always having at least one store even if times == 0, in my contrived example.
There might be a few more situations, but that's what I found so far. See attachment for CLIF: split-hoisting-repro.md
Hoisting predates trimming in this codebase, so the partial redundancy probably comes from there.
There are a couple possible fixes:
- Remove hoisting. It's slightly faster to run and occasionally a little worse than just trimming, but maybe not enough to really matter?
- Remove hoisting and separately try to improve stores - this would make trimming equivalent to hoisting. Trimming separately probably should be smarter around control-flow, see #272 .
- Restrict hoisting candidates to the loop & its parents. This solves case 2 but not case 1.
- Fancier fix that tries to account for conditionals.
- Maybe other ideas I haven't had.
I ran into both of the early cases while working on a JIT, hence the 'fallback with similar structure' pattern, but none seem that outlandish that common code wouldn't also trigger them to me.
- Vorherrschende Sprache
- Rust
- Sterne
- 271
- Forks
- 65
- Ø Merge
- 2 T. 22 Std.
- Gemergte PRs (30 T.)
- 8
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus bytecodealliance/regalloc2
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
bytecodealliance/regalloc2#271 ·
-
A bundle split twice around call clobbers spills in the call-free loops it spansEvtl. vergeben @EvanCarroll hat das vor 36 Tagen übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
bytecodealliance/regalloc2#268 · 4 Kommentare ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
bytecodealliance/regalloc2#265 · 9 Kommentare ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
bytecodealliance/regalloc2#247 · 3 Kommentare ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
bytecodealliance/regalloc2#206 · 2 Kommentare ·
Alle Issues in bytecodealliance/regalloc2
Ähnliche Issues
-
Test connection's password prompt says the password is never saved, also for a keychain profileOffenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
area: settings bug Haiku review: no-score ui
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
MMFoundation/WallpaperMachine#346 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Make the HTTP server's keep-alive and headers timeouts configurableEvtl. vergeben @mattgodbolt hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
compiler-explorer/compiler-explorer#9902 ·
Maintainer antworten meist innerhalb von 1 Tag
-
documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
jonathanong/no-mistakes#5490 ·
-
follow-up
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag