[Mlir-commits] [mlir] af4dcbb - [mlir][affine] Verify `map` of affineMaxMinOp has at least one result (#108699)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 20 03:45:39 PDT 2024


Author: Longsheng Mou
Date: 2024-09-20T18:45:35+08:00
New Revision: af4dcbbfe6c7b2c7390a202580e0d2093d2aeb49

URL: https://github.com/llvm/llvm-project/commit/af4dcbbfe6c7b2c7390a202580e0d2093d2aeb49
DIFF: https://github.com/llvm/llvm-project/commit/af4dcbbfe6c7b2c7390a202580e0d2093d2aeb49.diff

LOG: [mlir][affine] Verify `map` of affineMaxMinOp has at least one result (#108699)

This PR fixes a bug in `verifyAffineMinMaxOp` that allowed `map` of
`affine.max` and `affine.min` to have an empty result. Fixes #108368.

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 11b6b7cf5fd5a7..b89888e6aa83f7 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -3214,6 +3214,9 @@ static LogicalResult verifyAffineMinMaxOp(T op) {
       op.getMap().getNumDims() + op.getMap().getNumSymbols())
     return op.emitOpError(
         "operand count and affine map dimension and symbol count must match");
+
+  if (op.getMap().getNumResults() == 0)
+    return op.emitOpError("affine map expect at least one result");
   return success();
 }
 

diff  --git a/mlir/test/Dialect/Affine/invalid.mlir b/mlir/test/Dialect/Affine/invalid.mlir
index 60f13102f55156..869ea712bb3690 100644
--- a/mlir/test/Dialect/Affine/invalid.mlir
+++ b/mlir/test/Dialect/Affine/invalid.mlir
@@ -178,6 +178,22 @@ func.func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) {
 
 // -----
 
+func.func @affine_min() {
+  // expected-error at +1 {{'affine.min' op affine map expect at least one result}}
+  %0 = affine.min affine_map<() -> ()> ()
+  return
+}
+
+// -----
+
+func.func @affine_min(%arg0 : index) {
+  // expected-error at +1 {{'affine.min' op affine map expect at least one result}}
+  %0 = affine.min affine_map<(d0) -> ()> (%arg0)
+  return
+}
+
+// -----
+
 func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {
   // expected-error at +1 {{operand count and affine map dimension and symbol count must match}}
   %0 = affine.max affine_map<(d0) -> (d0)> (%arg0, %arg1)
@@ -205,6 +221,22 @@ func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {
 
 // -----
 
+func.func @affine_max() {
+  // expected-error at +1 {{'affine.max' op affine map expect at least one result}}
+  %0 = affine.max affine_map<() -> ()> ()
+  return
+}
+
+// -----
+
+func.func @affine_max(%arg0 : index) {
+  // expected-error at +1 {{'affine.max' op affine map expect at least one result}}
+  %0 = affine.max affine_map<(d0) -> ()> (%arg0)
+  return
+}
+
+// -----
+
 func.func @affine_parallel(%arg0 : index, %arg1 : index, %arg2 : index) {
   // expected-error at +1 {{the number of region arguments (1) and the number of map groups for lower (2) and upper bound (2), and the number of steps (2) must all match}}
   affine.parallel (%i) = (0, 0) to (100, 100) step (10, 10) {


        


More information about the Mlir-commits mailing list