[Mlir-commits] [mlir] e38c8bd - [MLIR][scf.parallel] Don't allow a tile size of 0 (#68762)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 23 14:28:48 PDT 2023


Author: Justin Fargnoli
Date: 2023-10-23T14:28:44-07:00
New Revision: e38c8bdca8ca1c05d8e6e2e665524c0841fb13d3

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

LOG: [MLIR][scf.parallel] Don't allow a tile size of 0 (#68762)

Fix a crash reported in #64331. The crash is described in the following
comment:

> It looks like the bug is being caused by the command line argument
--scf-parallel-loop-tiling=parallel-loop-tile-sizes=0. More
specifically, --scf-parallel-loop-tiling=parallel-loop-tile-sizes sets
the tileSize variable to 0 on [this
line](https://github.com/llvm/llvm-project/blob/7cc1bfaf371c4a816cf4e62fe31d8515bf8f6fbd/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp#L67).
tileSize is then used on [this
line](https://github.com/llvm/llvm-project/blob/7cc1bfaf371c4a816cf4e62fe31d8515bf8f6fbd/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp#L117)
causing a divide by zero exception.

This PR will:

1. Call `signalPassFail()` when 0 is passed as a tile size.
2. Avoid the divide by zero that causes the crash. 

Note: This is my first PR for MLIR, so please liberally critique it.

Added: 
    mlir/test/Dialect/SCF/parallel-loop-invalid.mlir

Modified: 
    mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp b/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp
index 1e04261e2eb3649..fdc28060917fb26 100644
--- a/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp
@@ -195,6 +195,12 @@ struct ParallelLoopTiling
   }
 
   void runOnOperation() override {
+    for (auto tileSize : tileSizes)
+      if (tileSize == 0) {
+        mlir::emitError(mlir::UnknownLoc::get(&Pass::getContext()),
+                        "tile size cannot be 0");
+        return signalPassFailure();
+      }
     auto *parentOp = getOperation();
     SmallVector<ParallelOp, 2> innermostPloops;
     getInnermostParallelLoops(parentOp, innermostPloops);

diff  --git a/mlir/test/Dialect/SCF/parallel-loop-invalid.mlir b/mlir/test/Dialect/SCF/parallel-loop-invalid.mlir
new file mode 100644
index 000000000000000..f031bc956f0d5ac
--- /dev/null
+++ b/mlir/test/Dialect/SCF/parallel-loop-invalid.mlir
@@ -0,0 +1,11 @@
+// RUN: mlir-opt %s -pass-pipeline='builtin.module(func.func(scf-parallel-loop-tiling{parallel-loop-tile-sizes=0,0}))' -split-input-file -verify-diagnostics
+
+// The expected error is, "tile size cannot be 0" at an unknown location. (It's 
+// location is unknown because the it's caused by an invalid command line 
+// argument.)
+// XFAIL: *
+
+func.func @parallel_loop(%arg0 : index, %arg1 : index, %arg2 : index) {
+  scf.parallel (%i) = (%arg0) to (%arg1) step (%arg2) {}
+  return
+}


        


More information about the Mlir-commits mailing list