Skip to content

Commit 989aadf

Browse files
authored
Revert "[mlir][affine] allow iter args as valid dims" (#140808)
Reverts #139069: the original change that got reverted by that PR was in fact correct. Since we don't know how secondary iteration args evolve with loop iterations (e.g., the loop may be yielding the result of a function call or the state of a PRNG), we cannot statically represent them as an integer set bound by affine constraints, unlike primary iteration args where the evolution is clear.
1 parent 6179131 commit 989aadf

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,12 @@ bool mlir::affine::isValidDim(Value value) {
294294
return isValidDim(value, getAffineScope(defOp));
295295

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

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

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

327328
// Affine apply operation is ok if all of its operands are ok.

mlir/test/Dialect/Affine/raise-memref.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func.func @symbols(%N : index) {
112112
// CHECK: %[[lhs5:.*]] = arith.addf %[[lhs]], %[[lhs4]]
113113
// CHECK: %[[lhs6:.*]] = arith.addi %[[a4]], %[[cst1]]
114114
// CHECK: affine.store %[[lhs5]], %{{.*}}[%[[a1]], symbol(%arg0) + 1] :
115-
// CHECK: affine.store %[[lhs5]], %{{.*}}[%[[a1]], %arg4 + 1] :
115+
// CHECK: memref.store %[[lhs5]], %{{.*}}[%[[a1]], %[[lhs6]]] :
116116
// CHECK: %[[lhs7:.*]] = "ab.v"
117117
// CHECK: memref.store %[[lhs5]], %{{.*}}[%[[a1]], %[[lhs7]]] :
118118
// CHECK: affine.yield %[[lhs6]]

0 commit comments

Comments
 (0)