Repository navigation
Conversation
Signed-off-by: Raul Estrada <[email protected]>
Signed-off-by: Raul Estrada <[email protected]>
uurl
force-pushed
the
perf/399-typed-array-iterator-scalarization
branch
from
August 23, 2026 05:36
abd7169 to
06ecacb
Compare
Collaborator
|
Closing this PR because the optimization is not semantics-preserving.
A replacement needs exact layout semantics and adversarial escape controls, consistent with the root-cause and full-path requirements in the Discord announcement. |
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.
Summary
Addresses #399.
This PR handles the memory-resident
Take<Copied<slice::Iter<_>>>form. Other iterator-adapter shapes remaintracked by #399.
This adds a typed-MIR canonicalization for the memory-resident iterator state
produced by bounded iteration over small local arrays.
The transformation recognizes the structural form emitted for cases such as:
and replaces the final pointer-backed element load with a bounded SSA array
extraction.
The resulting
mir.extract_array_elementcan then use the existing aggregatescalarization/lowering path instead of preserving the source array as local
memory.
Implementation
The pass recognizes a narrow structural pattern rather than matching Rust type
names.
For a candidate memory-resident iterator, it proves that:
state;
base + N;current pointer.
For a successful match, the pass reconstructs the array value in SSA and derives
the element index from the iterator count:
The index is bounded before emitting
mir.extract_array_element.Unsupported or ambiguous shapes are left unchanged.
Scope
This intentionally does not attempt to recognize arbitrary Rust iterators.
It targets the memory-resident pointer-walk form generated for bounded
Take<Copied<slice::Iter<_>>>-like iteration over small local arrays.The implementation does not add:
Tests
Added transform coverage for:
Regression suites:
cargo clippy -- -D warningsandgit diff --checkalso pass.End-to-end result
For the Rust reproducer, the preparation pipeline reports:
The local-memory diagnostic for
coefficientsdisappears.The resulting target kernel contains no:
The optimized PTX keeps the operation register-resident and reduces the bounded
iteration to runtime selection over the four scalar values.
Runtime correctness
Validated on a real CUDA device for runtime levels
0..=4:Performance
CUDA-event timings were collected with a runtime
runtime_levelsparameter,20 warmup launches, and 51 timed launches per level.
Median-of-five process runs:
A final post-cleanup smoke run remained in the same range.
This is also materially different from the earlier textual-LLVM approach, which
removed local memory but regressed runtime performance.
Result
The change eliminates stack-backed iterator access for this bounded local-array
case while keeping the transformation in typed MIR and reusing the existing
bounded aggregate scalarization path.