fix(structured): correct memref pointer and wraparound lowering#43
Merged
WuXintong123 merged 1 commit intoJul 17, 2026
Merged
Conversation
maochuanjun
force-pushed
the
fix/structured-to-memref-lowering
branch
from
July 12, 2026 12:23
8b1bd72 to
8910b4e
Compare
Collaborator
|
The rank-1 lowering represents the access with exactly two strided memrefs, which is only correct when the sequence wraps at most once. For example, start=8, modulo=10, stride=3, size=8 should access 8,1,4,7,0,3,6,9, but the second memref accesses 1,4,7,10,13,16,19. Please either support repeated wraparound or explicitly reject/prove impossible cases before applying this lowering, and add a regression test covering a second wrap. |
Scope: StructuredToMemref lowering plus supporting analysis and regression coverage.
maochuanjun
force-pushed
the
fix/structured-to-memref-lowering
branch
from
July 16, 2026 12:22
8910b4e to
0cf35f5
Compare
Author
|
Thanks for pointing this out. I have replaced the two-memref rank-1 lowering, which could only represent one wrap, with elementwise lowering. Also I added regression tests for repeated-wrap loads/stores, negative strides, negative initial offsets, and runtime zero stride. PTAL,thx. |
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
Fix StructuredToMemref pointer analysis and lowering for rank-1 wraparound, non-unit and zero strides, side-by-side accesses, and masked gather/scatter paths.
The previous implementation was primarily shaped around rank-2 split pointers and unit-stride assumptions. It could compute incorrect offsets for linear or side-by-side wraparound, use invalid mask dimensions, or apply fusion patterns whose address assumptions were not valid.
Problems addressed
Changes
Harden analysis helpers:
nulloptfor emptyOpFoldResultinteger queries;AndOprestriction through an absent structured dimension;GatherScatterPtrandMakeTensorPtr.Add explicit linear wraparound support:
WRAP_LINEARrepresentation;Correct side-by-side wraparound:
Restrict unsafe fusions:
rank-1 pointer has a statically unit stride.
Extend split/gather/scatter lowering:
tensor.empty,linalg.fill,scf.for, andtensor.insert;Regression coverage
New tests:
wraparound_linear_stride.mlirwraparound_linear_zero_stride.mlirselectanddivsipaths.wraparound_side_by_side_non_unit_stride.mlirtensor_first_vector_cpu_strided_load.mlirUpdated tests cover: