Repository navigation
fix(mir-importer): type six intrinsic results from the projected destination - #780
Merged
nihalpasham merged 2 commits intoAug 10, 2026
Merged
Conversation
vyncint
force-pushed
the
fix/projected-destination-result-types
branch
from
August 10, 2026 08:23
4f784d2 to
3f24194
Compare
…ination NVIDIA#769 taught `store_result_to_place` to write an intrinsic result through a projected call destination and switched the bitops/saturating/bigint/exact_div sites to type the result from `Place::ty`. Six sites still typed it from `body.locals()[destination.local].ty`, i.e. the bare local, so with a projected destination the call op was created with the whole aggregate's type (or the pointer's, for `(*p)`) and `store_result_to_place` then stored that mistyped value through a correctly typed projected address. Converted, matching what the four fixed sites already do: float_math.rs placeholder calls, and the sincos tuple-result path terminator/mod.rs select_unpredictable memory.rs DynamicSharedArray::get / ::offset generated.rs elect_sync, via its render.rs template The two memory.rs sites match on the destination's `RawPtr` kind to pull out a pointee, so they need the projected *rustc* type rather than the dialect one: they take `destination.ty(body.locals())` before the match, with the same diagnostic `translate_destination_type` emits when the place cannot be resolved. The generated.rs hunk is regeneration output, not a hand edit; `cuda-intrinsics-gen -- check` passes. No test accompanies this, and that is deliberate rather than an omission. I tried to build a `#[custom_mir]` reproducer for the `select_unpredictable` site -- `RET.1 = select_unpredictable(..)` on a `(u64, u32)` -- and could not make it fail on main: with a literal condition rustc folds the call before the importer sees it, and with the condition derived from an earlier custom-MIR result it still compiles clean both before and after. A case that passes either way would sit in the suite guarding nothing, so I left it out rather than claim coverage it does not provide. The change is the same mechanical alignment NVIDIA#769 applied to its four siblings, and the four unit-test suites above stay green. Closes NVIDIA#773 Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham
force-pushed
the
fix/projected-destination-result-types
branch
from
August 10, 2026 09:07
3f24194 to
3195030
Compare
Collaborator
|
The typing fix is right; I added the following:
Merging, closes #773. |
Collaborator
|
Thanks @vyncint! The six-site typing fix is right; we completed the other half at three sites (sincos, function-item, closure) where the result was typed from the projection but still stored to the bare local, and added four optimizer-proof regression cases to the example (they hard-fail the device build on main's importer and pass here on sm_120). Merging, closes #773. |
Three translation paths typed their result from the projected destination but still stored it with value_map.store_local on the bare local: the sincos emitter (whose (sin, cos) tuple the parent commit types from the projection), the function-item call path, and the closure call path. A projected destination therefore kept failing at each of them, and worse than before at sincos: (*p) = sincosf(x) went from a clean "libm::sincos destination is not a tuple" diagnostic to a MirStoreOp verifier abort, because the value was typed from the pointee while the store aimed at the pointer's slot. For a pointer-typed function return with a (*p) destination the bare-local store was even silent: maybe_ptr_coerce papered over the type mismatch with a PtrToPtr cast and overwrote the pointer instead of the pointee. All three now route through store_result_to_place, the same projection-aware helper every emit_function_call result already uses; unsupported projections keep failing closed with a diagnostic. mir_projected_call_destination gains four cases covering the paths with their own store sites: RET.1 = sqrtf32(x) and RET[i] = sqrtf32(x) for the float-math placeholder (typed from the projected place, not the whole local), RET.1 = double_it(x) for the function-item path, and (*p) = sincosf(x) for the tuple-pack emitter. Writing shapes that actually reach the importer under -O took care: inlining rewrites a projected call destination into a temporary plus a store, and GVN rewrites a deref of a locally-taken pointer back to the plain local, so the new bodies are inline(never) and the sincos pointer arrives as an opaque argument. Inputs (sqrt(2), angle 0, integer doubling) are exact on host and device, keeping the bit-exact comparison safe. Verified both ways on an RTX 5090: against this branch all seven projections run and agree; against main's importer the device build hard-fails with a verification error on the ConstantIndex sqrtf32 copy the inliner leaves inside case_results.
nihalpasham
force-pushed
the
fix/projected-destination-result-types
branch
from
August 10, 2026 09:49
3195030 to
6109dbd
Compare
nihalpasham
approved these changes
Aug 10, 2026
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 #773.
#769 taught
store_result_to_placeto write an intrinsic result through aprojected call destination and switched four sites to type the result from
Place::ty. The six you enumerated still typed it frombody.locals()[destination.local].ty, so with a projected destination the callop got the whole aggregate's type (or the pointer's, for
(*p)) and the storethen pushed that mistyped value through a correctly typed address.
All six converted, matching the four already fixed:
float_math.rssincostuple-result pathterminator/mod.rsselect_unpredictablememory.rs(x2)DynamicSharedArray::get/::offsetgenerated.rselect_sync, via therender.rstemplateThe two
memory.rssites match on the destination'sRawPtrkind to pull out apointee, so as you noted they want the projected rustc type rather than the
dialect one — they take
destination.ty(body.locals())before the match, withthe same diagnostic
translate_destination_typeemits when a place cannot beresolved. The
generated.rshunk is regeneration output rather than a handedit;
cargo run -p cuda-intrinsics-gen -- checkpasses.No test, deliberately
I tried to build a
#[custom_mir]reproducer for theselect_unpredictablesite —
RET.1 = select_unpredictable(..)on a(u64, u32)— and could notmake it fail on
main:clean both before and after.
A case that passes either way would sit in the suite guarding nothing, so I left
it out rather than claim coverage it does not provide. If you know a shape that
does reach these six with a projection, I am happy to add it — the four
bitops/saturating/bigint/exact_divsites presumably had one.Gates:
cargo fmt --check,clippy --all-targets -D warnings, and-p mir-importer -p cuda-intrinsics-gen -p mir-lowerunit tests (930 / 288 /182 / 102, all green). No GPU needed — this is importer typing only.
Merge order
#770 and #721 both regenerate
generated.rs(they add intrinsics). Neithertouches the typing pattern, so there is no semantic conflict, but whichever
lands last will collide textually in that file. If this goes second, the fix is
just
cargo run -p cuda-intrinsics-gen -- generateon top — happy to rebase.Aside, possibly worth its own issue
While probing,
core::hint::black_boxfailed device codegen outright:That is unrelated to this change and I have not investigated it; flagging it in
case it is news.