[Mlir-commits] [mlir] [mlir][affine] allow iter args as valid dims (PR #139069)
Mikhail Goncharov
llvmlistbot at llvm.org
Thu May 8 06:00:30 PDT 2025
https://github.com/metaflow updated https://github.com/llvm/llvm-project/pull/139069
>From 868524453893a47623ff60d44bfd4ccd8dd4f6e9 Mon Sep 17 00:00:00 2001
From: Mikhail Goncharov <goncharov.mikhail at gmail.com>
Date: Thu, 8 May 2025 15:00:05 +0200
Subject: [PATCH] [mlir][affine] allow iter args as valid dims
that is effectivevely a revert of
7aabf47522625e227433cc9603e0b6858c5dd66d for
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
As iter args can be used as a dims is some
situations. For example in
[heir PolynomialToModArith](https://github.com/google/heir/blob/main/lib/Dialect/Polynomial/Conversions/PolynomialToModArith/PolynomialToModArith.cpp#L1036)
`rootExp`` and `batchSize`` are iter args that are
being used as dims and from the point of internal
loops they are fixed.
---
mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 13 ++++++-------
mlir/test/Dialect/Affine/raise-memref.mlir | 2 +-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index 65f85444e70db..eb23403a68813 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -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
@@ -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.
diff --git a/mlir/test/Dialect/Affine/raise-memref.mlir b/mlir/test/Dialect/Affine/raise-memref.mlir
index 8dc24d99db3e2..98c54e3998b73 100644
--- a/mlir/test/Dialect/Affine/raise-memref.mlir
+++ b/mlir/test/Dialect/Affine/raise-memref.mlir
@@ -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]]
More information about the Mlir-commits
mailing list