[Mlir-commits] [mlir] [mlir][SCF] Avoid crash in parallel loop unrolling test pass (PR #222644)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 10 06:06:24 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: purnima shrivastava (purnima-nlp)

<details>
<summary>Changes</summary>

This fixes a crash in `--test-parallel-loop-unrolling` when the pass is invoked without `unroll-factors`.

In that case, the `unrollFactors` list is empty, but the test pass still forwards it to `parallelLoopUnrollByFactors`, which requires a non-empty factor list and asserts.

The fix makes the test pass return early when no unroll factors are provided. A regression test was added to verify that the pass leaves the parallel loop unchanged instead of crashing.

Fixes #<!-- -->222535.


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


2 Files Affected:

- (modified) mlir/test/Dialect/SCF/parallel-loop-unroll.mlir (+6) 
- (modified) mlir/test/lib/Dialect/SCF/TestParallelLoopUnrolling.cpp (+3) 


``````````diff
diff --git a/mlir/test/Dialect/SCF/parallel-loop-unroll.mlir b/mlir/test/Dialect/SCF/parallel-loop-unroll.mlir
index 6e02074d18475..3aa1d341f6e5f 100644
--- a/mlir/test/Dialect/SCF/parallel-loop-unroll.mlir
+++ b/mlir/test/Dialect/SCF/parallel-loop-unroll.mlir
@@ -1,7 +1,13 @@
+// RUN: mlir-opt %s -test-parallel-loop-unrolling -split-input-file | FileCheck %s --check-prefix=CHECK-NO-UNROLL
 // RUN: mlir-opt %s -test-parallel-loop-unrolling='unroll-factors=1,2' -split-input-file | FileCheck %s
 // RUN: mlir-opt %s -test-parallel-loop-unrolling='unroll-factors=1,2 loop-depth=1' -split-input-file | FileCheck %s --check-prefix CHECK-UNROLL-INNER
 // RUN: mlir-opt %s -test-parallel-loop-unrolling='unroll-factors=3,1' -split-input-file | FileCheck %s --check-prefix CHECK-UNROLL-BY-3
 
+// CHECK-NO-UNROLL-LABEL: func @unroll_simple_parallel_loop
+// CHECK-NO-UNROLL: [[C1:%.*]] = arith.constant 1 : index
+// CHECK-NO-UNROLL: scf.parallel {{.*}} step ([[C1]], [[C1]], [[C1]])
+// CHECK-NO-UNROLL-NOT: affine.apply
+// CHECK-NO-UNROLL: return
 func.func @unroll_simple_parallel_loop(%src: memref<1x16x12xf32>, %dst: memref<1x16x12xf32>) {
   %c12 = arith.constant 12 : index
   %c16 = arith.constant 16 : index
diff --git a/mlir/test/lib/Dialect/SCF/TestParallelLoopUnrolling.cpp b/mlir/test/lib/Dialect/SCF/TestParallelLoopUnrolling.cpp
index 12a6a6af59fa6..c6da5b8842f77 100644
--- a/mlir/test/lib/Dialect/SCF/TestParallelLoopUnrolling.cpp
+++ b/mlir/test/lib/Dialect/SCF/TestParallelLoopUnrolling.cpp
@@ -46,6 +46,9 @@ struct TestParallelLoopUnrollingPass
   }
 
   void runOnOperation() override {
+    if (unrollFactors.empty())
+      return;
+
     SmallVector<scf::ParallelOp, 4> loops;
     getOperation()->walk([&](scf::ParallelOp parLoop) {
       if (getNestingDepth(parLoop) == loopDepth)

``````````

</details>


https://github.com/llvm/llvm-project/pull/222644


More information about the Mlir-commits mailing list