[Mlir-commits] [mlir] [MLIR][Affine]Fixed crash with invalid cachesize (Issue #64979) (PR #114722)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Nov 4 06:01:01 PST 2024


https://github.com/SwapnilGhanshyala updated https://github.com/llvm/llvm-project/pull/114722

>From 314c8528c76f747b2f23cc4b77da721daebebc86 Mon Sep 17 00:00:00 2001
From: "swapnilghanshyala at gmail.com" <chaudhari.ha at FACC02G93B4Q05P.tld>
Date: Mon, 4 Nov 2024 13:49:15 +0000
Subject: [PATCH] [MLIR][Affine]Fixed crash with invalid cachesize (Issue
 #64979)

Updated LoopTiling::runOnOperation() to signal pass failure incase the set cachesize is invalid, i.e., less than or equal to zero.
 #64979 is the reporting issue. Also added a test case "loop-tile-cache-size-invalid.mlir".
---
 mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp  |  5 +++++
 .../Affine/loop-tile-cache-size-invalid.mlir       | 14 ++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 mlir/test/Dialect/Affine/loop-tile-cache-size-invalid.mlir

diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp
index c8400dfe8cd5c7..167df9863781c9 100644
--- a/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/LoopTiling.cpp
@@ -173,6 +173,11 @@ void LoopTiling::getTileSizes(ArrayRef<AffineForOp> band,
 }
 
 void LoopTiling::runOnOperation() {
+  if (cacheSizeInKiB == 0) {
+    mlir::emitError(mlir::UnknownLoc::get(&Pass::getContext()),
+                    "illegal argument: 'cache-size' cannot be zero");
+    return signalPassFailure();
+  }
   // Bands of loops to tile.
   std::vector<SmallVector<AffineForOp, 6>> bands;
   getTileableBands(getOperation(), &bands);
diff --git a/mlir/test/Dialect/Affine/loop-tile-cache-size-invalid.mlir b/mlir/test/Dialect/Affine/loop-tile-cache-size-invalid.mlir
new file mode 100644
index 00000000000000..3a4af19f36f9c8
--- /dev/null
+++ b/mlir/test/Dialect/Affine/loop-tile-cache-size-invalid.mlir
@@ -0,0 +1,14 @@
+// RUN: mlir-opt -affine-loop-tile="cache-size=0" %s -split-input-file -verify-diagnostics
+// XFAIL: *
+// This is @legal_loop() test case. The expected error is "illegal argument: 'cache-size' cannot be zero"
+// at unknown location because of invalid command line argument.
+
+func.func @test_cache_size_zero() {
+  %0 = memref.alloc() : memref<64xf32>
+  affine.for %i = 0 to 64 {
+    %1 = affine.load %0[%i] : memref<64xf32>
+    %2 = arith.addf %1, %1 : f32
+    affine.store %2, %0[%i] : memref<64xf32>
+  }
+  return
+}



More information about the Mlir-commits mailing list