<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118225>118225</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Crash when using --affine-loop-coalescing
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wangyongj1a
</td>
</tr>
</table>
<pre>
I have the following MLIR program:
test.mlir:
```
module {
func.func @func1() {
%c0 = arith.constant 0 : index
%c17 = arith.constant 17 : index
%alloc_33 = memref.alloc(%c17) : memref<?xi64>
affine.for %arg0 = 0 to 79 {
%492 = affine.for %arg1 = 0 to 64 iter_args(%arg2 = %alloc_33) -> (memref<?xi64>) {
%dim_89 = memref.dim %arg2, %c0 : memref<?xi64>
affine.yield %arg2 : memref<?xi64>
}
}
return
}
}
```
The above MLIR program will cause a crash when using the following command:
```
mlir-opt --affine-loop-coalescing test.mlir
```
And the crash backtrace is:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /data/tmp/v1201/llvm-project/build/bin/mlir-opt --affine-loop-coalescing test.mlir
#0 0x00005596d2fb2e6f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x150ae6f)
#1 0x00005596d2fb0624 SignalHandler(int) Signals.cpp:0:0
#2 0x00007fdad986e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00005596d43b3bdc mlir::memref::__mlir_ods_local_type_constraint_MemRefOps9(mlir::Operation*, mlir::Type, llvm::StringRef, unsigned int) (.constprop.0) MemRefOps.cpp:0:0
#4 0x00005596d43b3e39 mlir::memref::DimOp::verifyInvariantsImpl() (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x290be39)
#5 0x00005596d4347685 mlir::Op<mlir::memref::DimOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::IndexType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::NOperands<2u>::Impl, mlir::OpTrait::OpInvariants, mlir::OpAsmOpInterface::Trait, mlir::OpTrait::MemRefsNormalizable, mlir::ConditionallySpeculatable::Trait, mlir::MemoryEffectOpInterface::Trait, mlir::ShapedDimOpInterface::Trait, mlir::InferTypeOpInterface::Trait>::verifyInvariants(mlir::Operation*) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x289f685)
#6 0x00005596d435d79b mlir::RegisteredOperationName::Model<mlir::memref::DimOp>::verifyInvariants(mlir::Operation*) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x28b579b)
#7 0x00005596d604be92 (anonymous namespace)::OperationVerifier::verifyOnEntrance(mlir::Operation&) (.isra.0) Verifier.cpp:0:0
#8 0x00005596d604c975 (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) Verifier.cpp:0:0
#9 0x00005596d604e46a mlir::verify(mlir::Operation*, bool) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x45a646a)
#10 0x00005596d5e2d203 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4385203)
#11 0x00005596d5e2d451 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4385451)
#12 0x00005596d5e2bf16 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4383f16)
#13 0x00005596d5e2c959 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4384959)
#14 0x00005596d5e2d451 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4385451)
#15 0x00005596d5e2e4f6 mlir::PassManager::run(mlir::Operation*) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x43864f6)
#16 0x00005596d5e1e973 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#17 0x00005596d5e1f6af processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#18 0x00005596d5e1f7f4 llvm::LogicalResult llvm::function_ref<llvm::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>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#19 0x00005596d5f21ae5 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4479ae5)
#20 0x00005596d5e17de9 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x436fde9)
#21 0x00005596d5e1f961 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4377961)
#22 0x00005596d5e1fe26 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x4377e26)
#23 0x00005596d2eeba7b main (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x1443a7b)
#24 0x00007fdad931c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#25 0x00005596d2f8735e _start (/data/tmp/v1201/llvm-project/build/bin/mlir-opt+0x14df35e)
Segmentation fault (core dumped)
```
My git version is 22417ec6cca0ed8ccecb0c2b77011e591378fd2a.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWUtv4zgS_jXMhYghUe9DDu48sAE6kyBp7GEvAkWWZM5QpJak0vH--oUejmTFdvfseLtnBwt0xzZVLH7fV0WyKFJrRaUArlD0CUU3F7R1G22uvlJVbbWqfvXpRaH59uoeb-grYLcBXGop9VehKvzw-f4ZN0ZXhtYoWCNv7cC6VS2FGX6i2Bv_eeta81YCRskn5K0xLlvFVt0fjEKv-_QRSRHJ3g0wRiRiHkbBDaZGuM2KaWUdVQ53jWssFIe3mamfHLLtWyfjyZ5KqVkeBH2nGmoD5apv63F07no0wXp8iIJrFNy9iThEwe3oiZalULAqtek9mmqA62GncTKn0o8YZmRAuOzlT73iEAsHJqemsgMQaqqh2wxzh-wSBbcYkfQQOrI_dj86F3We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