Repository navigation
fix(mir-lower): preserve address spaces through typed enum fillers - #1332
Merged
Merged
Conversation
Signed-off-by: Yunus Mutlu <[email protected]>
YunusMutlu
force-pushed
the
fix/enum-filler-global-load
branch
from
October 13, 2026 10:51
c626c73 to
55b5c39
Compare
The 16-byte [2 x i64] filler fixed one width of a size-general loss. The block-argument scalarizer splits a merged aggregate only up to 16 leaves, and a [N x i8] filler costs one leaf per byte, so every run of 15 bytes or more beside a pointer and a length kept the enum join as one aggregate phi and lost the pointer's global address space. Pick the widest of 8, 4 and 2 bytes that divides the run's size and offset and does not exceed the enum alignment, and type the run as that integer or an array of it. This is the rule rustc uses for its own padding; i128 stays out because of its 16-byte natural alignment. 24-, 32- and 40-byte payloads beside a slice now reach ld.global and st.global, the 32- and 40-byte cases lose their .local spill, and align-4 and align-2 enums get [4 x i32] and [8 x i16]. The doc comment names the leaf budget, the builder tests cover the offset, alignment and size conditions plus 24- and 12-byte fillers, and a scalarizer test shows byte-array storage staying whole while typed storage splits. Signed-off-by: nihalpasham <[email protected]>
The two wide-option kernels of the vectorization example were inspected in the PTX but never run. Launch both with a round-trip check, take the None arm once and check that the output stays untouched, and add a 24-byte Option<([u64; 3], &[F32x4])> copy kernel with the same 128-bit global load check. That check fails with the 16-byte-only filler rule (a generic ld.v2.b64) and passes with the widest-integer rule, so the generalization cannot regress silently. Signed-off-by: nihalpasham <[email protected]>
The typed over-budget filler keeps an aggregate phi and a generic access but no local spill; only the bool-carrier byte array spills. Signed-off-by: nihalpasham <[email protected]>
Collaborator
|
/ok to test 878b53c |
Collaborator
|
Nice find. The 16-byte case was the symptom, so I went one step further before landing:
Checked at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Niche-encoded enums whose payload leaves a run of bytes that no typed slot claims now store that run as the widest layout-neutral integer array instead of
[N x i8]. The block-argument scalarizer in mir-lower splits a merged aggregate only up to 16 leaves.Option<([u64; 2], &[F32x4])>as{ [16 x i8], ptr, i64 }is 18 leaves, so theSome/Nonejoin stayed one aggregate phi,optcould not take it apart, and NVPTX address-space inference lost the slice pointer behind anextractvalue. As{ [2 x i64], ptr, i64 }it is 4 leaves, the join becomes scalar phis, and the 128-bit access lands in the global window again.What we fixed
[2 x i64];i128would impose 16-byte natural alignment and is not used.sizeandoffsetmultiples of w and w not above the enum alignment, the filler isiwwhensize == wand[size / w x iw]otherwise. 24-, 32- and 40-byte fillers beside a slice reachld.global/st.globaltoo, and the 32- and 40-byte cases lose their.localspill; align-4 and align-2 enums get[4 x i32]and[8 x i16]and lose theirs.vectorizationcarries load and store kernels through a wideOption, launched with a round-trip check and aNone-arm check, plus a 24-byte case, and asserts the 128-bit global access in the embedded PTX.Implementation
make_enum_filler_typeis the one builder both filler sites ofbuild_enum_slot_mapcall; the rule is the one rustc'stype_padding_filleruses for padding (largest of i64, i32, i16 whose alignment fits, i128 excluded).[0 x i128]anchor still raises 16-byte enum alignment where rustc requires it (u128 payload test).[4 x i32]), 24 bytes ([3 x i64]), 12 bytes at align 4 ([3 x i32]), byte-array fallbacks, and a scalarizer test showing{ [16 x i8], i64, i64 }stays one block argument while the typed storage splits.Verification
Checked at
878b53c98(the PR head merged with maine84e5b3d7):cargo test -p mir-lower --all-targets: 313 unit and 147 integration tests pass; three of the new builder tests fail at the PR head and the 24-byte example check fails there with exit 1. Workspace clippy with-D warnings, rustdoc,cargo oxide fmt --check, the example lock check and the 18 guards pass. All 60 CI checks passed.cargo oxide run vectorizationon an RTX 5090 (sm_120a): SUCCESS for 26 vector types; the wide-option kernels showld.global.v2.b64/st.global.v2.b64; compute-sanitizer memcheck 0 errors, 0 leaks.cargo oxide run vectorization --arch sm_86:ld.global.v4.b32/st.global.v4.b32; SASSLDG.E.128/STG.E.128. With main's backend the same example reports all three global accesses lost and exits 1.--emit-nvvm-ir --arch sm_120: SUCCESS through libNVVM.Option::map, by-value aggregate return) copy bit-exactly optimized, unoptimized and with main's backend; memcheck clean. 24-, 32- and 40-byte probes emitld.global.v2.b64/st.global.v2.b64with no aggregate phi after-O2and no.localframe.Caveats
Option<(bool, [u64; 2])>places 23 bytes at offset 1, so its merge stays one aggregate phi with a.localspill; no pointer is involved, so no address space is lost. The 16-leaf budget itself is a follow-up.(u32, u16, u8, u64, &[T]), gain the global access but keep a smaller spill.Closes #1331.