Skip to content

fix(mir-lower): give an aggregate niche payload's leaves typed slots - #1591

Open
midagedev wants to merge 1 commit into
NVIDIA:mainfrom
midagedev:fix/niche-payload-leaf-slots
Open

midagedev wants to merge 1 commit into
NVIDIA:mainfrom
midagedev:fix/niche-payload-leaf-slots

Conversation

@midagedev

Copy link
Copy Markdown
Contributor

Fixes #1590.

A niche enum payload with a pointer carrier and non-pointer leaves gave only the pointer a typed slot. The rest became filler bytes, and the payload went through a .local depot.

Now every leaf gets a typed slot at its rustc offset. Size, alignment, field offsets and the niche encoding do not change. A payload the rule cannot prove keeps the old lowering.

Evidence (sm_86, ptxas 13.3, llc 21 and 23):

One test changes: #1332's u128 slot-map test now expects one i128 slot under the carrier instead of [2 x i64] filler. Alignment is still 16.

I used an AI assistant (Claude) to write and check this change. I reviewed and measured it.

An enum payload that is a struct or tuple with a pointer niche carrier and
non-pointer leaves (`Option<(f32, f32, &mut T)>`, `Option<{&mut T, u64, u64}>`)
gave only the pointer leaf a typed slot. The other leaves fell into
`[N x i8]` filler bytes, so construct spilled the payload through a slot and
the payload read loaded it back at another width. SROA cannot rebuild
mixed-type slices, and the slot reached PTX as a local depot.

Every leaf of such a payload now claims a typed slot at its rustc offset,
reusing the carrier's slot where the types match, with construct and payload
reads using insertvalue/extractvalue; size, alignment, field offsets and the
niche encoding are unchanged, and a payload the rule cannot prove keeps the
old lowering.

Measured with one device-only probe source against each tree's backend:
parent e027ac3 emits a 16 B `.local` depot in the `smooth_triplets` entry
plus 16 B in the outlined `Cells::next_cell`; this commit emits none.
`lease_borrow` and `lease_raw` emit none on either commit.
Across the 241 examples under rustc-codegen-cuda/examples, only
enum_niche_payload and set_discriminant_niche change PTX, and both lose
their 16 B depot; vectorization and repr_u32_enum_stride are unchanged per
entry.

The NVIDIA#1332 slot-map test now expects the 16 bytes under the carrier as one
i128 slot instead of [2 x i64] filler; alignment stays 16.

Adds the enum_niche_payload example and the leaf-slot unit tests.

Signed-off-by: midagedev <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mir-lower: niche enum payload with mixed leaves lowers to a local depot

1 participant