Skip to content

[mlir][affine] allow iter args as valid dims #139069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,10 @@ bool mlir::affine::isValidDim(Value value) {
return isValidDim(value, getAffineScope(defOp));

// This value has to be a block argument for an op that has the
// `AffineScope` trait or an induction var of an affine.for or
// affine.parallel.
if (isAffineInductionVar(value))
return true;
// `AffineScope` trait or for an affine.for or affine.parallel.
auto *parentOp = llvm::cast<BlockArgument>(value).getOwner()->getParentOp();
return parentOp && parentOp->hasTrait<OpTrait::AffineScope>();
return parentOp && (parentOp->hasTrait<OpTrait::AffineScope>() ||
isa<AffineForOp, AffineParallelOp>(parentOp));
}

// Value can be used as a dimension id iff it meets one of the following
Expand All @@ -318,9 +316,10 @@ bool mlir::affine::isValidDim(Value value, Region *region) {

auto *op = value.getDefiningOp();
if (!op) {
// This value has to be an induction var for an affine.for or an
// This value has to be a block argument for an affine.for or an
// affine.parallel.
return isAffineInductionVar(value);
auto *parentOp = llvm::cast<BlockArgument>(value).getOwner()->getParentOp();
return isa<AffineForOp, AffineParallelOp>(parentOp);
}

// Affine apply operation is ok if all of its operands are ok.
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Dialect/Affine/raise-memref.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func.func @symbols(%N : index) {
// CHECK: %[[lhs5:.*]] = arith.addf %[[lhs]], %[[lhs4]]
// CHECK: %[[lhs6:.*]] = arith.addi %[[a4]], %[[cst1]]
// CHECK: affine.store %[[lhs5]], %{{.*}}[%[[a1]], symbol(%arg0) + 1] :
// CHECK: memref.store %[[lhs5]], %{{.*}}[%[[a1]], %[[lhs6]]] :
// CHECK: affine.store %[[lhs5]], %{{.*}}[%[[a1]], %arg4 + 1] :
// CHECK: %[[lhs7:.*]] = "ab.v"
// CHECK: memref.store %[[lhs5]], %{{.*}}[%[[a1]], %[[lhs7]]] :
// CHECK: affine.yield %[[lhs6]]
Expand Down