You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scalarize small local arrays consumed through iterator adapters #399
codegenDevice code-generation pipeline (Rust MIR to IR to PTX)optional-optsOpt-in optimization passes for the oxide-owned opt registry (off by default)
After inlining and O2, LLVM retains an alloca [4 x float] and pointer-based iterator state. ScalarEvolution reports the loop trip count and constant maximum as unpredictable, so bounded loop-unroll with upperbound or runtime enabled does not expose the array to SROA. This produces ld.local / st.local despite the four-element bound.
#398 scalarizes direct runtime indexing and selected addresses for small compiler-owned arrays. Iterator pointer state is a separate case because the eventual load is visible only after helper inlining and its pointer provenance has passed through loop state.
Desired result
Keep small arrays used through standard iter, copied, take, skip, and enumerate chains in SSA without requiring source-level loop expansion or indexing rewrites. Add a GPU regression asserting correct runtime-level behavior and no PTX .local, ld.local, or st.local.
I built your repro on current main (nightly-2026-08-28, LLVM 23), and the picture has flipped since July.
.local here means per-thread stack memory in PTX (ld.local / st.local).
Your iterator form now compiles to register-only code. The index loop with a break, the form people usually reach for instead, is the one that keeps the array in memory.
let coefficients = [4.0_f32, -3.0,4.0 / 3.0, -0.25];let n = levels[i]asusize;// A: iterator adapters (this issue) -> 0 ld/st.local, 50 PTX instructionsfor(k, c)in coefficients.iter().copied().take(n.min(4)).enumerate(){ acc += c *(k asf32 + 1.0);}// B: index loop with break -> 4 st.local + 1 ld.local, 62 PTX instructionsfor k in0..4{if k >= n {break;} acc += coefficients[k]*(k asf32 + 1.0);}
Same result at --arch=sm_80 and sm_120a; both kernels compute the right values on an RTX 5090. CUDA_OXIDE_VERBOSE=1 (feat(codegen): diagnose locals that survive register promotion #758) names coefficients in B only: "indexed by a non-constant value; the allocation survives LLVM scalar replacement".
So the case this issue describes is handled by the current pipeline with no iterator-specific pass.
codegenDevice code-generation pipeline (Rust MIR to IR to PTX)optional-optsOpt-in optimization passes for the oxide-owned opt registry (off by default)
Activity
nihalpasham commentedon Sep 3, 2026
I built your repro on current main (nightly-2026-08-28, LLVM 23), and the picture has flipped since July.
.localhere means per-thread stack memory in PTX (ld.local/st.local).break, the form people usually reach for instead, is the one that keeps the array in memory.--arch=sm_80andsm_120a; both kernels compute the right values on an RTX 5090.CUDA_OXIDE_VERBOSE=1(feat(codegen): diagnose locals that survive register promotion #758) namescoefficientsin B only: "indexed by a non-constant value; the allocation survives LLVM scalar replacement".iter().copied().take()after inlining would tie the compiler to core's iterator internals on every nightly bump, and the two earlier attempts showed the cost: Scalarize small local arrays used by iterator adapters #636 removed the.localops and measured 16-19% slower on its own workload; perf(mir): scalarize bounded small-array iterator reads #1151 was not semantics-preserving.I consider this covered on main. One ask for future performance issues, per https://discord.com/channels/1515530041767759993/1515561621156663487/1540970771323551775: include the kernel where the traffic costs time and a before/after number.