Skip to content

[MLIR][Affine] Add missing check in affine data copy nest generation #127809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

bondhugula
Copy link
Contributor

Handle case where no lower or upper bound could be found for a
dimension. Invalid IR was being generated silently for a test case.

Fixes: #127808

@llvmbot
Copy link
Member

llvmbot commented Feb 19, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-affine

Author: Uday Bondhugula (bondhugula)

Changes

Handle case where no lower or upper bound could be found for a
dimension. Invalid IR was being generated silently for a test case.

Fixes: #127808


Full diff: https://github.com/llvm/llvm-project/pull/127809.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp (+6-1)
  • (modified) mlir/test/Dialect/Affine/affine-data-copy.mlir (+6-5)
diff --git a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
index 4e02559a08949..c618671d07f1f 100644
--- a/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
+++ b/mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp
@@ -2001,8 +2001,13 @@ static LogicalResult generateCopy(
   }
 
   SmallVector<AffineMap, 4> lbMaps(rank), ubMaps(rank);
-  for (unsigned i = 0; i < rank; ++i)
+  for (unsigned i = 0; i < rank; ++i) {
     region.getLowerAndUpperBound(i, lbMaps[i], ubMaps[i]);
+    if (lbMaps[i].getNumResults() == 0 || ubMaps[i].getNumResults() == 0) {
+      LLVM_DEBUG(llvm::dbgs() << "Missing lower or upper bound for region\n");
+      return failure();
+    }
+  }
 
   const FlatAffineValueConstraints *cst = region.getConstraints();
   // 'regionSymbols' hold values that this memory region is symbolic/parametric
diff --git a/mlir/test/Dialect/Affine/affine-data-copy.mlir b/mlir/test/Dialect/Affine/affine-data-copy.mlir
index 330cf92bafba4..5615acae5ecc4 100644
--- a/mlir/test/Dialect/Affine/affine-data-copy.mlir
+++ b/mlir/test/Dialect/Affine/affine-data-copy.mlir
@@ -300,14 +300,15 @@ func.func @affine_parallel(%85:memref<2x5x4x2xi64>) {
       }
     }
   }
-  // CHECK:     affine.for
-  // CHECK-NEXT:  affine.for %{{.*}} = 0 to 5
-  // CHECK-NEXT:    affine.for %{{.*}} = 0 to 4
-  // CHECK-NEXT:      affine.for %{{.*}} = 0 to 2
-
+  // Lower and upper bounds for the region can't be determined for the outermost
+  // dimension. No fast buffer generation.
   // CHECK:     affine.for
   // CHECK-NEXT:  affine.parallel
   // CHECK-NEXT:    affine.parallel
+  // CHECK-NEXT:      affine.for
+  // CHECK-NOT:      affine.for
+
+
   return
 }
 

Handle case where no lower or upper bound could be found for a
dimension. Invalid IR was being generated silently for a test case.

Fixes: llvm#127808
Copy link
Contributor

@CoTinker CoTinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@bondhugula bondhugula merged commit 1fd280d into llvm:main Feb 20, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MLIR][Affine] Loop with missing lower and upper bound from affine-data-copy-generate
3 participants