Spill-range trimming introduces stack traffic in call-free loops

Aperta
#271 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start with the spill-range trimming logic and reproduce the reported case using the supplied CLIF with clif-util compile --target aarch64-apple-darwin --set opt_level=speed --set regalloc_checker=true -p -D one-loop-then-helper.clif. Trace how trimming moves live-range ends across loop depths and inspect whether block-argument uses and block-parameter definitions are included. Done means the reproductions no longer generate per-iteration stack traffic while the related split-limit behavior remains distinct.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

issue for poor allocation for the following pseudocode:

acc = 0
n = input_count
while n > 0:
    n -= 1
    acc += 1
helper()
return acc

CLIF concrete example with a float accumulator on aarch64 (which spills):

function %one_loop_then_helper(i64, i64) -> f64 apple_aarch64 {
    sig0 = () apple_aarch64

block0(v0: i64, v2: i64):
    v3 = f64const 0.0
    jump block1(v0, v3)

block1(v4: i64, v5: f64):
    v6 = iconst.i64 0
    v7 = icmp sgt v4, v6
    brif v7, block2, block3

block2:
    v8 = f64const 0x1.0000000000000p0
    v9 = fadd v5, v8
    v10 = iconst.i64 1
    v11 = isub v4, v10
    jump block1(v11, v9)

block3:
    call_indirect sig0, v2()
    return v5
}

(Compile with clif-util compile --target aarch64-apple-darwin --set opt_level=speed --set regalloc_checker=true -p -D one-loop-then-helper.clif)

This produces an unnecessary accumulator store on every loop iteration, in addition to a save immediately before the helper call. A second variant, where the accumulator controls loop termination and the helper is called afterward, produces both a store and a reload on every iteration.

Tracing these cases shows one split near the helper call. Trimming then moves the end of the live ranges back into the loop, introducing repeated stack traffic.

I’m not an expert on this code, but I’ve investigated it with GPT-6 Astra. Two possible improvements seem worth discussing:

  • Stop trimming when it would enter a deeper loop than the split point, to avoid turning preservation outside a loop into per-iteration traffic.
  • Account for block-argument uses and block-parameter definitions during trimming, rather than consulting only the instruction-use lists.

A small patch implementing the loop-depth restriction fixes both examples (and I'll post that PR soon). I had Astra prototype accounting for block-argument uses, and it also fixes this issue, though it requires more substantial work.

Related to #268/#270 in symptom, but these reproductions do not trigger the split-limit fallback. Neither approach removes the inner-loop spills in #268’s attached reproducer.

Lingua principale
Rust
Stelle
271
Fork
65
Merge medio
2g 22h
PR unite (30g)
8

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bytecodealliance/regalloc2

Tutte le issue di bytecodealliance/regalloc2

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.