Repository navigation
fix(mir-lower): support packed aggregates by value - #941
Merged
Merged
Conversation
Signed-off-by: Raul Estrada <[email protected]>
nihalpasham
force-pushed
the
fix/packed-aggregate-by-value-abi
branch
from
August 17, 2026 09:33
5a489f4 to
7495e43
Compare
Collaborator
|
Gist: by-value packed aggregates get the correct param ABI: What I verified and did:
Closes #940 on merge. |
nihalpasham
previously approved these changes
Aug 17, 2026
… scalar peel takes priority over packed by-value conversion)
nihalpasham
approved these changes
Aug 17, 2026
This was referenced Aug 18, 2026
Merged
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.
Closes #940
Dependency
This PR is stacked on #931, which in turn is stacked on #919.
#919 updates cuda-oxide to the explicit
StructLayout::{Packed, Unpacked}API, and #931 adds the packed LLVM struct sizing/export infrastructure reused by this change.Once the prerequisite PRs land, this branch will be rebased onto
main, leaving only the packed aggregate by-value and ABI alignment changes in this PR.Summary
Adds by-value support for Rust packed aggregates while preserving their physical rustc layout through MIR lowering, LLVM export, and the NVVM kernel ABI.
This extends the existing packed-field addressing support to whole aggregate values.
What changed
Packed aggregate representation
Struct lowering now distinguishes between:
A divergent layout is lowered as
StructLayout::Packedonly when sequential LLVM packed layout reproduces the recorded rustc field offsets and total size exactly.This avoids incorrectly treating overlapping or union-like layouts as ordinary packed structs.
For example:
lowers to:
<{ i8, i32 }>with size 5.
And:
lowers to:
<{ i8, [1 x i8], i32 }>with size 6.
The explicit byte slot preserves the rustc field offset of
b.By-value operations
Packed aggregates are now supported through:
Layouts that cannot be represented faithfully still fail closed.
Kernel ABI alignment
LLVM packed structs have natural alignment 1, which is insufficient for layouts such as:
#[repr(C, packed(2))]whose Rust ABI alignment is 2.
MIR lowering now records non-natural source ABI alignment when it exceeds the natural alignment of the lowered LLVM type.
The LLVM exporter translates that into NVVM's
"align"function property annotation.NVVM encodes this as:
where argument positions are 1-based and position 0 denotes the return value.
For the first
Packed2kernel parameter:This produces the expected PTX:
rather than the previous:
Shared-memory pointer aggregates
Packed aggregates containing address-space-3/shared pointers remain unsupported by value.
Their physical pointer width is target-dependent between the rustc NVPTX model and modern NVVM, so these cases continue to fail closed rather than silently producing an incorrect ABI.
This does not affect existing packed field addressing.
End-to-end coverage
Adds the
packed_aggregate_abiexample covering:repr(C, packed);repr(C, packed(2));The runtime test executes successfully on CUDA and verifies:
with generated PTX including:
Validation
End-to-end:
PTX ABI checks:
Out of scope
This PR does not attempt to support: