[Mlir-commits] [mlir] [MLIR][Affine] Add missing check in affine data copy nest generation (PR #127809)
Uday Bondhugula
llvmlistbot at llvm.org
Wed Feb 19 07:23:36 PST 2025
https://github.com/bondhugula created https://github.com/llvm/llvm-project/pull/127809
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: https://github.com/llvm/llvm-project/issues/127808
>From 565f83b222eb4470d8deb627ef75af1f2c314201 Mon Sep 17 00:00:00 2001
From: Uday Bondhugula <uday at polymagelabs.com>
Date: Wed, 19 Feb 2025 20:48:38 +0530
Subject: [PATCH] [MLIR][Affine] Add missing check in affine data copy nest
generation
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: https://github.com/llvm/llvm-project/issues/127808
---
mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp | 7 ++++++-
mlir/test/Dialect/Affine/affine-data-copy.mlir | 11 ++++++-----
2 files changed, 12 insertions(+), 6 deletions(-)
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
}
More information about the Mlir-commits
mailing list