[Mlir-commits] [mlir] dc72a93 - [MLIR][Affine] Add check for 'affine.for' Bound Map Results (#127105)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Feb 21 22:02:25 PST 2025
Author: Ayokunle Amodu
Date: 2025-02-22T11:32:22+05:30
New Revision: dc72a93d2b4c80d93d51a4de83d2c0080be19742
URL: https://github.com/llvm/llvm-project/commit/dc72a93d2b4c80d93d51a4de83d2c0080be19742
DIFF: https://github.com/llvm/llvm-project/commit/dc72a93d2b4c80d93d51a4de83d2c0080be19742.diff
LOG: [MLIR][Affine] Add check for 'affine.for' Bound Map Results (#127105)
Fixes issue #120001.
Add missing check in affine.for op's verifier for lower/upper bound maps
to have at least one result.
Added:
Modified:
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
mlir/test/Dialect/Affine/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index cfc51ad2a1524..c4891614662a1 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,6 +1902,10 @@ LogicalResult AffineForOp::verifyRegions() {
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
getUpperBoundMap().getNumDims())))
return failure();
+ if (getLowerBoundMap().getNumResults() < 1)
+ return emitOpError("expected lower bound map to have at least one result");
+ if (getUpperBoundMap().getNumResults() < 1)
+ return emitOpError("expected upper bound map to have at least one result");
unsigned opNumResults = getNumResults();
if (opNumResults == 0)
diff --git a/mlir/test/Dialect/Affine/invalid.mlir b/mlir/test/Dialect/Affine/invalid.mlir
index da2913e3fec28..69d58ce1b5265 100644
--- a/mlir/test/Dialect/Affine/invalid.mlir
+++ b/mlir/test/Dialect/Affine/invalid.mlir
@@ -541,3 +541,25 @@ func.func @dynamic_dimension_index() {
}) : () -> ()
return
}
+
+// -----
+
+#map = affine_map<() -> ()>
+#map1 = affine_map<() -> (1)>
+func.func @no_lower_bound() {
+ // expected-error at +1 {{'affine.for' op expected lower bound map to have at least one result}}
+ affine.for %i = max #map() to min #map1() {
+ }
+ return
+}
+
+// -----
+
+#map = affine_map<() -> ()>
+#map1 = affine_map<() -> (1)>
+func.func @no_upper_bound() {
+ // expected-error at +1 {{'affine.for' op expected upper bound map to have at least one result}}
+ affine.for %i = max #map1() to min #map() {
+ }
+ return
+}
More information about the Mlir-commits
mailing list