<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58658>58658</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR]Crash when using -affine-loop-fusion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BealZephyr
</td>
</tr>
</table>
<pre>
Hello, I tried to run `mlir-opt temp.mlir -affine-loop-fusion`, but the execution crashed with the following crash backtrace:
```
mlir-opt: /data/llvm/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:2001: void mlir::AffineForOp::setLowerBound(mlir::ValueRange, mlir::AffineMap): Assertion `map.getNumResults() >= 1 && "bound map has at least one result"' failed.
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-fusion temp.mlir
#0 0x000000000047f08a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/llvm/llvm/lib/Support/Unix/Signals.inc:569:11
#1 0x000000000047f23b PrintStackTraceSignalHandler(void*) /data/llvm/llvm/lib/Support/Unix/Signals.inc:636:1
#2 0x000000000047d8b6 llvm::sys::RunSignalHandlers() /data/llvm/llvm/lib/Support/Signals.cpp:103:5
#3 0x000000000047f965 SignalHandler(int) /data/llvm/llvm/lib/Support/Unix/Signals.inc:407:1
#4 0x00007fdd89da3980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#5 0x00007fdd88c93e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#6 0x00007fdd88c957f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
#7 0x00007fdd88c853fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
#8 0x00007fdd88c85472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
#9 0x0000000000585cc7 mlir::AffineForOp::setLowerBound(mlir::ValueRange, mlir::AffineMap) /data/llvm/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:2003:37
#10 0x00000000006a95ec mlir::fuseLoops(mlir::AffineForOp, mlir::AffineForOp, mlir::ComputationSliceState const&, bool) /data/llvm/mlir/lib/Dialect/Affine/Utils/LoopFusionUtils.cpp:452:5
#11 0x000000000065767c (anonymous namespace)::GreedyFusion::fuseProducerConsumerNodes(unsigned int) /data/llvm/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp:1621:26
#12 0x0000000000651b2e (anonymous namespace)::GreedyFusion::runGreedyFusion() /data/llvm/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp:1412:5
#13 0x00000000006507fa (anonymous namespace)::LoopFusion::runOnOperation() /data/llvm/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp:0:12
#14 0x00000000029bbf7a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /data/llvm/mlir/lib/Pass/Pass.cpp:471:21
#15 0x00000000029bc574 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /data/llvm/mlir/lib/Pass/Pass.cpp:534:16
#16 0x00000000029c1988 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const /data/llvm/mlir/lib/Pass/Pass.cpp:754:36
#17 0x00000000029c15f9 mlir::LogicalResult mlir::failableParallelForEach<__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12&>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12&) /data/llvm/mlir/include/mlir/IR/Threading.h:46:18
#18 0x00000000029bd853 mlir::LogicalResult mlir::failableParallelForEach<std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>&, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12&>(mlir::MLIRContext*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>&, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12&) /data/llvm/mlir/include/mlir/IR/Threading.h:92:10
#19 0x00000000029bd10d mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) /data/llvm/mlir/lib/Pass/Pass.cpp:764:14
#20 0x00000000029bc227 mlir::detail::OpToOpPassAdaptor::runOnOperation(bool) /data/llvm/mlir/lib/Pass/Pass.cpp:655:5
#21 0x00000000029bbf6b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /data/llvm/mlir/lib/Pass/Pass.cpp:468:5
#22 0x00000000029bc574 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /data/llvm/mlir/lib/Pass/Pass.cpp:534:16
#23 0x00000000029bde3c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /data/llvm/mlir/lib/Pass/Pass.cpp:837:10
#24 0x00000000029bdd5c mlir::PassManager::run(mlir::Operation*) /data/llvm/mlir/lib/Pass/Pass.cpp:817:60
#25 0x00000000029b539c performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>) /data/llvm/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:84:17
#26 0x00000000029b50c3 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) /data/llvm/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:124:12
#27 0x00000000029b4ecf mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir:
[temp.mlir.txt](https://github.com/llvm/llvm-project/files/9884511/temp.mlir.txt)
:LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /data/llvm/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:164:12
#28 0x00000000029b4ded mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /data/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#29 0x0000000002ae1789 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /data/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#30 0x0000000002ae0d65 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) /data/llvm/mlir/lib/Support/ToolUtilities.cpp:28:12
#31 0x00000000029b4159 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool) /data/llvm/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:169:10
#32 0x00000000029b429a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool) /data/llvm/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:187:10
#33 0x00000000029b4c06 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /data/llvm/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:269:14
#34 0x0000000000411c2e main /data/llvm/mlir/tools/mlir-opt/mlir-opt.cpp:237:7
#35 0x00007fdd88c76c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#36 0x0000000000411aca _start (/data/llvm/mlir/build/bin/mlir-opt+0x411aca)
Aborted (core dumped)
```
Here is a minimize input [temp.mlir](https://github.com/llvm/llvm-project/files/9884507/temp.mlir.txt):
```
#map0 = affine_map<(d0) -> (d0)>
#map1 = affine_map<(d0) -> (d0 + 1)>
module {
func.func @test_reduce_sum(%arg0: tensor<14x3xi8>) {
%0 = bufferization.to_memref %arg0 : memref<14x3xi8>
%1 = memref.alloc() {alignment = 128 : i64} : memref<3xi8>
%2 = memref.alloc() {alignment = 128 : i64} : memref<3xi8>
memref.copy %1, %2 : memref<3xi8> to memref<3xi8>
affine.for %arg1 = 0 to 14 {
affine.for %arg2 = 0 to 3 {
affine.for %arg3 = #map0(%arg1) to #map1(%arg1) {
affine.for %arg4 = #map0(%arg2) to #map1(%arg2) {
%6 = affine.load %2[%arg3] : memref<3xi8>
affine.store %6, %2[%arg3] : memref<3xi8>
}
}
}
}
affine.for %arg1 = 0 to 3 {
affine.for %arg2 = #map0(%arg1) to #map1(%arg1) {
%5 = affine.load %2[%arg2] : memref<3xi8>
}
}
return
}
}
```
The original test case is attached [here](https://github.com/llvm/llvm-project/files/9884585/origin.mlir.txt). You can reproduce it using `mlir-opt origin.mlir -affine-loop-fusion`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztW1tT4zgW_jXhRYXLlu8PPARottmCgQJmqnZeXLItJ9q1La8lN2F-_R7JTnxJ0oQGpuneplJYtqRzvnPVxXLM06eTzzTP-Q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