Repository navigation
feat(codegen): forward bounded dynamic result-bundle indexing - #1005
Merged
nihalpasham merged 2 commits intoAug 20, 2026
Merged
Conversation
nihalpasham
requested changes
Aug 19, 2026
Collaborator
There was a problem hiding this comment.
The select-chain rewrite is sound and everything fails closed, but the feature is unreachable from real compiler output:
validate_bounded_dynamic_indexrequires the index's defining op to beMirRemOpdirectly. The pass runs pre-mem2reg, where a source-levelregs[i % 4]arrives as amir.loadfrom the index's temp slot, so the gate never fires outside the hand-built test IR. Confirmed against the importer'stranslate_placeaddress path.- Two ways to fix:
- trace the index through its slot (a load from an alloca with a single dominating rem store, mirroring the bundle proof this pass already does), or
- run the recognition again post-mem2reg where the rem is a direct operand;
canonicalize_bounded_borrowed_pointer_argumentsalready lives there.
- Add an end-to-end test through the real pipeline showing
st.local/ld.localdisappear for a source-level modulo index, not just hand-built IR. - Another point while you're there: assert-derived bounds (the Asserted form the sibling pass supports) can carry the same proof when no rem is present.
uurl
force-pushed
the
feat/bounded-compiler-result-indexing
branch
from
August 19, 2026 22:47
856f63b to
0d1565b
Compare
Contributor
Author
|
Addressed the reachability issue by rerunning compiler-result forwarding immediately after mem2reg, where the source-level modulo index is available directly in SSA. Added an end-to-end Verified on sm_120: The existing unit tests and mir/codegen suites remain green. I kept assert-derived bounds outside this PR for now so #1004 remains scoped to the |
Signed-off-by: Raul Estrada <[email protected]>
Signed-off-by: Raul Estrada <[email protected]>
uurl
force-pushed
the
feat/bounded-compiler-result-indexing
branch
from
August 20, 2026 10:31
b87c6fb to
df21553
Compare
Collaborator
|
nihalpasham
approved these changes
Aug 20, 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 #1004
Summary
Extend compiler-result bundle forwarding to handle bounded dynamic array indexing.
forward_compiler_result_bundlespreviously required every array projection to use a constant index. As a result, accesses such as:kept the importer-created aggregate on the memory path even though the bundle boundary had already been proven safe.
This PR recognizes a narrow bounded dynamic form and rewrites it to the existing SSA aggregate extraction operation.
What changed
forward_compiler_result_bundlesnow accepts a terminal dynamic array projection when:mir.rem(value, constant);MAX_SCALARIZED_CANDIDATES.For accepted accesses, the pass emits:
instead of preserving the
alloca -> store -> array_element_addr -> loadpath.The existing
mir.extract_array_elementlowering already recognizes bounded unsigned remainder indices and lowers them to fixedextractvaluecandidates plus a select chain when profitable.No second scalarization implementation is introduced here.
Source-level dynamic indices may initially reach this transform through temporary MIR slots, so the direct
mir.remshape is not always visible before mem2reg.To make the optimization reachable from real compiler output, the same fail-closed compiler-result forwarding pass is run again immediately after mem2reg. At that point, promotable index temporaries have been converted to SSA and bounded forms such as
index % Care directly visible to the existing recognition logic.The original pre-mem2reg invocation remains in place for constant/static result bundle forwarding.
Fail-closed behavior
The pass still leaves the complete memory path untouched for:
MAX_SCALARIZED_CANDIDATES;Constant-index forwarding is unchanged.
Constructor lifetime
Dynamic extraction retains the SSA
mir.construct_arrayneeded bymir.extract_array_element.Bundle constructors are now erased only when their result has no remaining uses, while constant forwarding continues to eliminate the complete aggregate construction when possible.
Tests
Added transform coverage for:
Added an end-to-end
generated_ldmatrixregression using a source-level bounded dynamic access:This exercises the complete rustc -> MIR -> mem2reg -> compiler-result forwarding -> LLVM/PTX pipeline.
Validation performed:
End-to-end validation on sm_120:
With LLVM optimization disabled:
The generated PTX for the bounded dynamic result-bundle path contains no local memory round trip: