[Mlir-commits] [mlir] [mlir][transform] Guard parametric loop tiling pass from no option (PR #118254)

Kai Sasaki llvmlistbot at llvm.org
Sun Dec 1 21:47:16 PST 2024


https://github.com/Lewuathe created https://github.com/llvm/llvm-project/pull/118254

`test-extract-fixed-outer-loops` pass always crash without any `test-outer-loop-sizes` option. We need to keep the pass from crash by checking the option existence. 

Fix https://github.com/llvm/llvm-project/issues/116360

>From e1f17d587d0802a9f870b6d33dcb65a462606508 Mon Sep 17 00:00:00 2001
From: Kai Sasaki <lewuathe at gmail.com>
Date: Mon, 2 Dec 2024 14:38:57 +0900
Subject: [PATCH] [mlir][transform] Guard parametric loop tiling pass from no
 option

---
 .../Transforms/invalid-outer-loop-size.mlir   | 19 +++++++++++++++++++
 .../Dialect/SCF/TestLoopParametricTiling.cpp  |  3 +++
 2 files changed, 22 insertions(+)
 create mode 100644 mlir/test/Transforms/invalid-outer-loop-size.mlir

diff --git a/mlir/test/Transforms/invalid-outer-loop-size.mlir b/mlir/test/Transforms/invalid-outer-loop-size.mlir
new file mode 100644
index 00000000000000..42e5848b9704ed
--- /dev/null
+++ b/mlir/test/Transforms/invalid-outer-loop-size.mlir
@@ -0,0 +1,19 @@
+// RUN: mlir-opt -test-extract-fixed-outer-loops %s | FileCheck %s 
+
+// COMMON-LABEL: @no_crash
+func.func @no_crash(%arg0: memref<?x?xf32>) {
+  // CHECK: %[[c2:.*]] = arith.constant 2 : index
+  %c2 = arith.constant 2 : index
+  // CHECK: %[[c44:.*]] = arith.constant 44 : index
+  %c44 = arith.constant 44 : index
+  // CHECK: %[[c1:.*]] = arith.constant 1 : index  
+  %c1 = arith.constant 1 : index
+  // CHECK: scf.for %[[i:.*]] = %[[c2]] to %[[c44]] step %[[c1]]
+  scf.for %i = %c2 to %c44 step %c1 {
+    // CHECK: scf.for %[[j:.*]] = %[[c1]] to %[[c44]] step %[[c2]]
+    scf.for %j = %c1 to %c44 step %c2 {
+      memref.load %arg0[%i, %j]: memref<?x?xf32>
+    }
+  }
+  return
+}
diff --git a/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp b/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
index 1f33a04b0668a9..f90371a27e7393 100644
--- a/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
+++ b/mlir/test/lib/Dialect/SCF/TestLoopParametricTiling.cpp
@@ -40,6 +40,9 @@ class SimpleParametricLoopTilingPass
   }
 
   void runOnOperation() override {
+    // If no outer loop iteration is given, ignore the pass.
+    if (sizes.empty())
+      return;
     getOperation()->walk([this](scf::ForOp op) {
       // Ignore nested loops.
       if (op->getParentRegion()->getParentOfType<scf::ForOp>())



More information about the Mlir-commits mailing list