[Mlir-commits] [mlir] [mlir][Affine] take strides into account for contiguity check (PR #177756)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jan 24 04:07:08 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
index 87efbb428..3c2cd2e45 100644
--- a/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
@@ -319,19 +319,23 @@ DenseSet<Value> mlir::affine::getInvariantAccesses(Value iv,
}
/// Check that x is an offset in resultExpr
-/// That is, check that the result is of the shape x + ...
-static bool isOffset(AffineExpr resultExpr, int numDims, ArrayRef<Value> operands, Value offset) {
+/// That is, check that the result is of the shape x + ...
+static bool isOffset(AffineExpr resultExpr, int numDims,
+ ArrayRef<Value> operands, Value offset) {
// Check if the expression is only the offset
if (isa<AffineDimExpr>(resultExpr))
return operands[cast<AffineDimExpr>(resultExpr).getPosition()] == offset;
if (isa<AffineSymbolExpr>(resultExpr))
- return operands[cast<AffineSymbolExpr>(resultExpr).getPosition() + numDims] == offset;
+ return operands[cast<AffineSymbolExpr>(resultExpr).getPosition() +
+ numDims] == offset;
- // Otherwise, walk through the expression and check that it's of one of the shapes:
+ // Otherwise, walk through the expression and check that it's of one of the
+ // shapes:
// - x + ...
// - (x + ...) mod ...
- // The second pattern leads to piecewise contiguous accesses which can be considered contiguous
- // for vectorization if the vectorization factor is a divisor of the modulo's left-hand-side
+ // The second pattern leads to piecewise contiguous accesses which can be
+ // considered contiguous for vectorization if the vectorization factor is a
+ // divisor of the modulo's left-hand-side
WalkResult walkRes = resultExpr.walk([&](AffineExpr expr) {
if (!isa<AffineBinaryOpExpr>(expr))
return WalkResult::skip();
@@ -341,15 +345,13 @@ static bool isOffset(AffineExpr resultExpr, int numDims, ArrayRef<Value> operand
if (auto dimExpr = dyn_cast<AffineDimExpr>(lhs)) {
if (operands[dimExpr.getPosition()] == offset)
return WalkResult::interrupt();
- }
- else if (auto symExpr = dyn_cast<AffineSymbolExpr>(lhs))
+ } else if (auto symExpr = dyn_cast<AffineSymbolExpr>(lhs))
if (operands[symExpr.getPosition() + numDims])
return WalkResult::interrupt();
if (auto dimExpr = dyn_cast<AffineDimExpr>(rhs)) {
if (operands[dimExpr.getPosition()] == offset)
return WalkResult::interrupt();
- }
- else if (auto symExpr = dyn_cast<AffineSymbolExpr>(rhs))
+ } else if (auto symExpr = dyn_cast<AffineSymbolExpr>(rhs))
if (operands[symExpr.getPosition() + numDims])
return WalkResult::interrupt();
return WalkResult::advance();
@@ -359,8 +361,7 @@ static bool isOffset(AffineExpr resultExpr, int numDims, ArrayRef<Value> operand
if (auto dimExpr = dyn_cast<AffineDimExpr>(lhs)) {
if (operands[dimExpr.getPosition()] == offset)
return WalkResult::interrupt();
- }
- else if (auto symExpr = dyn_cast<AffineSymbolExpr>(lhs))
+ } else if (auto symExpr = dyn_cast<AffineSymbolExpr>(lhs))
if (operands[symExpr.getPosition() + numDims])
return WalkResult::interrupt();
}
@@ -397,15 +398,18 @@ bool mlir::affine::isContiguousAccess(Value iv, LoadOrStoreOp memoryOp,
});
// Check access invariance of each operand in 'exprOperands'.
for (Value exprOperand : exprOperands) {
- // Verify that the access is contiguous along the induction variable if it depends on it
- // by checking that at most one of the op's access map's result is of the shape IV + constant
- auto map = AffineMap::getMultiDimIdentityMap(/*numDims=*/1, iv.getContext());
+ // Verify that the access is contiguous along the induction variable if it
+ // depends on it by checking that at most one of the op's access map's
+ // result is of the shape IV + constant
+ auto map =
+ AffineMap::getMultiDimIdentityMap(/*numDims=*/1, iv.getContext());
SmallVector<Value> operands = {exprOperand};
AffineValueMap avm(map, operands);
avm.composeSimplifyAndCanonicalize();
if (avm.isFunctionOf(0, iv)) {
- if (!isOffset(resultExpr, numDims, mapOperands, exprOperand) ||
- !isOffset(avm.getResult(0), avm.getNumDims(), avm.getOperands(), iv)) {
+ if (!isOffset(resultExpr, numDims, mapOperands, exprOperand) ||
+ !isOffset(avm.getResult(0), avm.getNumDims(), avm.getOperands(),
+ iv)) {
return false;
}
if (uniqueVaryingIndexAlongIv != -1) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/177756
More information about the Mlir-commits
mailing list