<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64321>64321</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] `affine-loop-unroll` Pass crashed when assigning a 0 unroll factor
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Colloportus0
</td>
</tr>
</table>
<pre>
MLIR built at commit b4c54b20
Reproduced with:
` mlir-opt "--affine-loop-unroll=unroll-factor=0" temp.mlir`
temp.mlir:
``` milr
func.func @func2(%arg0: index, %arg1: vector<32xi32>) {
%c761048054_i32 = arith.constant 761048054 : i32
%c2 = arith.constant 2 : index
%c13 = arith.constant 13 : index
%1 = tensor.empty(%c13) : tensor<?xi32>
%4 = tensor.empty() : tensor<32x30xi32>
%57 = vector.broadcast %c761048054_i32 : i32 to vector<30xi32>
%91 = affine.for %arg2 = 0 to 49 iter_args(%arg3 = %1) -> (tensor<?xi32>) {
%126 = tensor.empty(%c2) : tensor<?xi32>
affine.yield %126 : tensor<?xi32>
}
return
}
```
trace:
```console
Assertion failed: (unrollFactor > 0 && "unroll factor should be positive"), function loopUnrollByFactor, file LoopUtils.cpp, line 1019.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: mlir-opt --affine-loop-unroll=unroll-factor=0 temp.mlir
#0 0x0000000101218548 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/build/bin/mlir-opt+0x1002f8548)
#1 0x00000001012167e4 llvm::sys::RunSignalHandlers() (/workspace/build/bin/mlir-opt+0x1002f67e4)
#2 0x0000000101218bf4 SignalHandler(int) (/workspace/build/bin/mlir-opt+0x1002f8bf4)
#3 0x00000001a46cd4c4 (/usr/lib/system/libsystem_platform.dylib+0x1803414c4)
#4 0x00000001a46b5ee0 (/usr/lib/system/libsystem_pthread.dylib+0x180329ee0)
#5 0x00000001a45f0340 (/usr/lib/system/libsystem_c.dylib+0x180264340)
#6 0x00000001a45ef754 (/usr/lib/system/libsystem_c.dylib+0x180263754)
#7 0x000000010505d264 mlir::affine::loopUnrollByFactor(mlir::affine::AffineForOp, unsigned long long, llvm::function_ref<void (unsigned int, mlir::Operation*, mlir::OpBuilder)>, bool) (.cold.2) (/workspace/build/bin/mlir-opt+0x10413d264)
#8 0x0000000101306b74 mlir::affine::loopUnrollByFactor(mlir::affine::AffineForOp, unsigned long long, llvm::function_ref<void (unsigned int, mlir::Operation*, mlir::OpBuilder)>, bool) (/workspace/build/bin/mlir-opt+0x1003e6b74)
#9 0x00000001012e713c (anonymous namespace)::LoopUnroll::runOnOperation() (/workspace/build/bin/mlir-opt+0x1003c713c)
#10 0x00000001038a1e34 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x102981e34)
#11 0x00000001038a2524 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/workspace/build/bin/mlir-opt+0x102982524)
#12 0x00000001038a35d8 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/workspace/build/bin/mlir-opt+0x1029835d8)
#13 0x00000001038a1f90 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspace/build/bin/mlir-opt+0x102981f90)
#14 0x00000001038a2524 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/workspace/build/bin/mlir-opt+0x102982524)
#15 0x00000001038a43bc mlir::PassManager::run(mlir::Operation*) (/workspace/build/bin/mlir-opt+0x1029843bc)
#16 0x000000010389c808 performActions(llvm::raw_ostream&, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x10297c808)
#17 0x000000010389bd30 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_1>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) (/workspace/build/bin/mlir-opt+0x10297bd30)
#18 0x000000010391abe0 mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/workspace/build/bin/mlir-opt+0x1029fabe0)
#19 0x00000001038966e4 mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/workspace/build/bin/mlir-opt+0x1029766e4)
#20 0x0000000103896b54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/workspace/build/bin/mlir-opt+0x102976b54)
#21 0x0000000100f2358c main (/workspace/build/bin/mlir-opt+0x10000358c)
#22 0x000000010c565088
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWV1voz7W_zTujdXI2EDgIhdp0uip1KpV-3-uI2NM4h1js7aZab79ypi8OE1nptHu6q_RjkaBYp9zf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