[Mlir-commits] [mlir] [mlir][affine] Add Check for 'affine.for' Bound Map Results (PR #127105)

Ayokunle Amodu llvmlistbot at llvm.org
Thu Feb 20 16:53:44 PST 2025


https://github.com/ayokunle321 updated https://github.com/llvm/llvm-project/pull/127105

>From b59c62e5122e0fac4f530fb0000f732607f95147 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 11:23:53 -0700
Subject: [PATCH 1/6] added check for affine.for bounds

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp |  6 ++++++
 mlir/test/Dialect/Affine/invalid.mlir    | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index cfc51ad2a1524..b79cc6850b6e0 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1903,6 +1903,12 @@ LogicalResult AffineForOp::verifyRegions() {
                                              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)
     return success();
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
+}

>From 7aa091fa5c40b855c152f540107954551791cae8 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 11:52:48 -0700
Subject: [PATCH 2/6] added comments

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index b79cc6850b6e0..e044470cb451c 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,13 +1902,14 @@ LogicalResult AffineForOp::verifyRegions() {
     if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
                                              getUpperBoundMap().getNumDims())))
       return failure();
-
+  // Verify that the bound maps produce at least one result.
+  /// Lower bound.
   if (getLowerBoundMap().getNumResults() < 1)
     return emitOpError("expected lower bound map to have at least one result");
-
+  /// Upper bound.
   if (getUpperBoundMap().getNumResults() < 1)
     return emitOpError("expected upper bound map to have at least one result");
-    
+
   unsigned opNumResults = getNumResults();
   if (opNumResults == 0)
     return success();

>From b95f0e57d11978a5e1524c9432062400453e4712 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 11:59:08 -0700
Subject: [PATCH 3/6] fixed code style

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index e044470cb451c..ee7b1ac385304 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,6 +1902,7 @@ LogicalResult AffineForOp::verifyRegions() {
     if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
                                              getUpperBoundMap().getNumDims())))
       return failure();
+      
   // Verify that the bound maps produce at least one result.
   /// Lower bound.
   if (getLowerBoundMap().getNumResults() < 1)

>From 302c2ec95446013da6270bf7b2ff51d32fa3b117 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 12:03:34 -0700
Subject: [PATCH 4/6] fix style

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index ee7b1ac385304..aa1d97dbbd23b 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1901,8 +1901,7 @@ LogicalResult AffineForOp::verifyRegions() {
   if (getUpperBoundMap().getNumInputs() > 0)
     if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
                                              getUpperBoundMap().getNumDims())))
-      return failure();
-      
+      return failure();    
   // Verify that the bound maps produce at least one result.
   /// Lower bound.
   if (getLowerBoundMap().getNumResults() < 1)

>From 20a24fc6deaddfac0b268e1393790ebae8926eb8 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 12:11:59 -0700
Subject: [PATCH 5/6] format code properly

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index aa1d97dbbd23b..e044470cb451c 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1901,7 +1901,7 @@ LogicalResult AffineForOp::verifyRegions() {
   if (getUpperBoundMap().getNumInputs() > 0)
     if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
                                              getUpperBoundMap().getNumDims())))
-      return failure();    
+      return failure();
   // Verify that the bound maps produce at least one result.
   /// Lower bound.
   if (getLowerBoundMap().getNumResults() < 1)

>From 6cead0b19f7f6b1f00f1671a56c48b0515e60f29 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <121697771+ayokunle321 at users.noreply.github.com>
Date: Thu, 13 Feb 2025 12:52:40 -0700
Subject: [PATCH 6/6] removed unnecessary comments

---
 mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index e044470cb451c..c4891614662a1 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1902,11 +1902,8 @@ LogicalResult AffineForOp::verifyRegions() {
     if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
                                              getUpperBoundMap().getNumDims())))
       return failure();
-  // Verify that the bound maps produce at least one result.
-  /// Lower bound.
   if (getLowerBoundMap().getNumResults() < 1)
     return emitOpError("expected lower bound map to have at least one result");
-  /// Upper bound.
   if (getUpperBoundMap().getNumResults() < 1)
     return emitOpError("expected upper bound map to have at least one result");
 



More information about the Mlir-commits mailing list