Skip to content

fix(mir-importer): type six intrinsic results from the projected destination - #780

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/projected-destination-result-types
Aug 10, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/projected-destination-result-types

Conversation

@vyncint

@vyncint vyncint commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Closes #773.

#769 taught store_result_to_place to write an intrinsic result through a
projected call destination and switched four sites to type the result from
Place::ty. The six you enumerated still typed it from
body.locals()[destination.local].ty, so with a projected destination the call
op got the whole aggregate's type (or the pointer's, for (*p)) and the store
then pushed that mistyped value through a correctly typed address.

All six converted, matching the four already fixed:

site intrinsic
float_math.rs placeholder calls, and the sincos tuple-result path
terminator/mod.rs select_unpredictable
memory.rs (x2) DynamicSharedArray::get / ::offset
generated.rs elect_sync, via the render.rs template

The two memory.rs sites match on the destination's RawPtr kind to pull out a
pointee, so as you noted they want 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 a place cannot be
resolved. The generated.rs hunk is regeneration output rather than a hand
edit; cargo run -p cuda-intrinsics-gen -- check passes.

No test, deliberately

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;
  • with the condition derived from an earlier custom-MIR result, it 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. 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_div sites presumably had one.

Gates: cargo fmt --check, clippy --all-targets -D warnings, and
-p mir-importer -p cuda-intrinsics-gen -p mir-lower unit 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). Neither
touches 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 -- generate on top — happy to rebase.

Aside, possibly worth its own issue

While probing, core::hint::black_box failed device codegen outright:

Translation failed: ...core/src/hint.rs: line: 491 Compilation error: invalid input program.

That is unrelated to this change and I have not investigated it; flagging it in
case it is news.

@vyncint
vyncint force-pushed the fix/projected-destination-result-types branch from 4f784d2 to 3f24194 Compare August 10, 2026 08:23
…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
nihalpasham force-pushed the fix/projected-destination-result-types branch from 3f24194 to 3195030 Compare August 10, 2026 09:07
@nihalpasham

Copy link
Copy Markdown
Collaborator

The typing fix is right;

I added the following:

  • completed the other half at 3 sites (sincos, fn-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 build on main's importer and pass here on sm_120).

Merging,

closes #773.

@nihalpasham

Copy link
Copy Markdown
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.

@nihalpasham nihalpasham added bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 10, 2026
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
nihalpasham force-pushed the fix/projected-destination-result-types branch from 3195030 to 6109dbd Compare August 10, 2026 09:49
@nihalpasham
nihalpasham merged commit 84e663e into NVIDIA:main Aug 10, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mir-importer: intrinsic sites that type the call result from the bare destination local fail as a verifier type-mismatch on a projected destination

2 participants