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

purnima shrivastava llvmlistbot at llvm.org
Thu Sep 10 06:05:45 PDT 2026


https://github.com/purnima-nlp created https://github.com/llvm/llvm-project/pull/222644

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.


>From 130af1947d37106695abacbec8c95576b7772c3e Mon Sep 17 00:00:00 2001
From: Purnima Shrivastava <purnimashrivastava05 at .com>
Date: Thu, 10 Sep 2026 18:26:05 +0530
Subject: [PATCH] [mlir][SCF] Avoid crash in parallel loop unrolling test pass

---
 mlir/test/Dialect/SCF/parallel-loop-unroll.mlir         | 6 ++++++
 mlir/test/lib/Dialect/SCF/TestParallelLoopUnrolling.cpp | 3 +++
 2 files changed, 9 insertions(+)

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)



More information about the Mlir-commits mailing list