You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR is stacked on top of #1062; its actual delta is one commit touching 7 files. Once #1062 lands, I’ll rebase this PR onto main so the review diff contains only the LLVM attribute-emission changes.
This change emits LLVM noalias / readonly parameter attributes from Rust reference semantics that are proven during MIR import.
#1062 preserves source pointer/reference kind through dialect MIR. This PR builds on that information and captures the additional rustc semantic conditions required to safely emit LLVM parameter attributes.
The policy follows rustc conservatively:
MIR pointer kind
Additional condition
LLVM attributes
SharedRef
pointee is Freeze
noalias readonly
UniqueRef
pointee is Unpin
noalias
RawConst
—
none
RawMut
—
none
Erased
—
none
Design
The semantic decision is made at the MIR import boundary, where the original rustc type is still available.
For each source-level parameter, mir-importer records only the facts that rustc semantics justify.
These facts are then:
stored on MirFuncOp
propagated through MIR lowering
remapped from source arguments to physical LLVM arguments after ABI flattening
serialized mechanically by llvm-export
llvm-export deliberately performs no Rust-semantic inference.
For slices, only the physical pointer component receives the attributes. The length parameter remains unannotated.
Safety / conservative cases
This PR intentionally does not emit attributes for:
raw pointers
erased/compiler-generated pointers
&UnsafeCell<T> and other non-Freeze shared references
non-Unpin mutable references
DisjointSlice based solely on its lowered representation
This avoids deriving Rust aliasing semantics from LLVM pointer shape or mutability alone.
Validation
Focused tests cover:
valid SharedRef and UniqueRef attributes
rejection of attributes on raw pointers
rejection of invalid readonly combinations
rustc Freeze / Unpin behavior
source-to-physical LLVM argument remapping
slice pointer vs. metadata handling
LLVM textual export
legacy typed-pointer export
rejection of reference attributes on non-pointer LLVM parameters
nihalpasham
added
soundness-audit
Correctness case under active maintainer audit; not cleared for merge yet
perf
Performance of generated code or of the compiler itself
codegen
Device code-generation pipeline (Rust MIR to IR to PTX)
IR-lowering
Lowering between dialects (dialect-mir to LLVM dialect)
llvm-export
Textual LLVM/NVVM IR exporter (llvm-export crate)
Depends
Blocked on another PR/issue or an upstream dependency
labels
Aug 20, 2026
The policy table matches rustc's own (&T + Freeze pointee -> noalias readonly, &mut T + Unpin -> noalias, raw pointers and Erased -> nothing), the proof runs where the real Ty is available, and the MirFuncOp verifier plus the fail-closed argument remap reject anything malformed. Two changes were needed on top, done and held with the feat(mir): preserve Rust pointer and reference kind #1062 fixes.
The one smoketest failure is the optimization working, and the test couldn't see it. aligned_field_loads asserts fusion width in PTX; with noalias readonly on the parameter, llc routes the reads through the read-only cache:
Fusion held in both directions: align(8) kernels fuse to v2, the natural-align-4 controls stay scalar, and every read additionally became .nc. The shape check now accepts the optional nc. qualifier so it checks fusion width, not the full instruction spelling.
The behavior change has to be said where raw launches are documented: overlapping read/write buffers through a raw launch used to be latent UB and is now a real miscompile (loads hoisted or cached across stores). Typed launches already rule it out since writable parameters take &mut DeviceBuffer. Added that to the cuda_launch! module docs and the launching-kernels book page.
Spot-checks so far, evidence rather than sign-off: tiled_gemm's PTX keeps strict st.shared -> bar.sync -> ld.shared -> bar.sync -> st ordering, attrs land only on pointer halves (slice lengths, raw pointers, DisjointSlice stay bare), and &UnsafeCell<u32> / &mut PhantomPinned get nothing per the fixture test. With the fixes: 95 workspace suites, 216/216 compile smoketest, GPU execution on tiled_gemm, barrier, and aligned_field_loads, book builds under -W.
Closing this PR because it is explicitly stacked on #1062 and derives noalias / readonly from the pointer-kind model in that branch.
#1062 is now closed because that model is unsound as a proof source: it cannot establish, end to end, that each pointer label came from the exact Rust fact that justifies it. Emitting optimizer attributes from those labels could turn a classification mistake into an LLVM aliasing miscompile.
The replacement will keep pointer construction and alias proof separate. This work can be reconsidered after the new proof exists end to end.
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
codegenDevice code-generation pipeline (Rust MIR to IR to PTX)DependsBlocked on another PR/issue or an upstream dependencyIR-loweringLowering between dialects (dialect-mir to LLVM dialect)llvm-exportTextual LLVM/NVVM IR exporter (llvm-export crate)perfPerformance of generated code or of the compiler itselfsoundness-auditCorrectness case under active maintainer audit; not cleared for merge yet
2 participants
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 #1088
This PR is stacked on top of #1062; its actual delta is one commit touching 7 files. Once #1062 lands, I’ll rebase this PR onto
mainso the review diff contains only the LLVM attribute-emission changes.Summary
Part of #413.
This change emits LLVM
noalias/readonlyparameter attributes from Rust reference semantics that are proven during MIR import.#1062 preserves source pointer/reference kind through dialect MIR. This PR builds on that information and captures the additional rustc semantic conditions required to safely emit LLVM parameter attributes.
The policy follows rustc conservatively:
SharedRefFreezenoalias readonlyUniqueRefUnpinnoaliasRawConstRawMutErasedDesign
The semantic decision is made at the MIR import boundary, where the original rustc type is still available.
For each source-level parameter,
mir-importerrecords only the facts that rustc semantics justify.These facts are then:
MirFuncOpllvm-exportllvm-exportdeliberately performs no Rust-semantic inference.For slices, only the physical pointer component receives the attributes. The length parameter remains unannotated.
Safety / conservative cases
This PR intentionally does not emit attributes for:
&UnsafeCell<T>and other non-Freezeshared referencesUnpinmutable referencesDisjointSlicebased solely on its lowered representationThis avoids deriving Rust aliasing semantics from LLVM pointer shape or mutability alone.
Validation
Focused tests cover:
SharedRefandUniqueRefattributesreadonlycombinationsFreeze/UnpinbehaviorFull validation:
End-to-end pipeline validation also confirms that the attributes reach generated LLVM IR.
For example,
vecaddnow lowers to:This verifies that:
Freezereferences receivenoalias readonlyaddressof_sharedarrayalso confirms that shared-memory/raw pointer parameters do not acquire reference-derived attributes accidentally.Out of scope
dereferenceableDisjointSlicealias inference