<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/148619>148619</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Crash in `-test-mesh-simplifications` due to null scf.reduce body when simplifying arith.maxsi inside scf.parallel
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sweead
</td>
</tr>
</table>
<pre>
test commit: [87e39c3](https://github.com/llvm/llvm-project/commit/87e39c399c96128307a826fd9168679f7c8c8d10)
step to reproduce:
```
mlir-opt -test-mesh-simplifications test.mlir
```
minimal test case:
```
module {
memref.global "private" constant @__constant_2x3x4xi64 : memref<2x3x4xi64> = dense<48> {alignment = 64 : i64}
func.func @main() {
%c4 = arith.constant 4 : index
%c3 = arith.constant 3 : index
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%c0 = arith.constant 0 : index
%c-41_i64 = arith.constant -41 : i64
%0 = memref.get_global @__constant_2x3x4xi64 : memref<2x3x4xi64>
%alloc = memref.alloc() {alignment = 64 : i64} : memref<2x3x4xi64>
scf.parallel (%arg0, %arg1, %arg2) = (%c0, %c0, %c0) to (%c2, %c3, %c4) step (%c1, %c1, %c1) {
%1 = memref.load %0[%arg0, %arg1, %arg2] : memref<2x3x4xi64>
%2 = arith.maxsi %1, %c-41_i64 : i64
memref.store %2, %alloc[%arg0, %arg1, %arg2] : memref<2x3x4xi64>
scf.reduce
}
return
}
}
```
Crash backtrace:
```
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 -test-mesh-simplifications test.mlir
#0 0x000055a9a0687fc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/workdir/llvm-project/build/bin/mlir-opt+0x1420fc8)
#1 0x000055a9a0685645 llvm::sys::RunSignalHandlers() (/home/workdir/llvm-project/build/bin/mlir-opt+0x141e645)
#2 0x000055a9a06890e1 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007fd518240520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000055a9a5995ac0 void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*, std::optional<mlir::Operation*>)::operator()(mlir::Operation*, std::optional<mlir::Operation*>) const (/home/workdir/llvm-project/build/bin/mlir-opt+0x672eac0)
#5 0x000055a9a599553b mlir::HomomorphismSimplification<void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda0'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*, llvm::SmallVector<mlir::OpOperand*, 6u>&), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda1'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda1'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*, std::optional<mlir::Operation*>), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda2'(mlir::Operation*), mlir::detail::CreateAlgebraicOpForEndomorphismSimplification>::matchOp(mlir::Operation*, llvm::SmallVector<mlir::OpOperand*, 6u>&) const (/home/workdir/llvm-project/build/bin/mlir-opt+0x672e53b)
#6 0x000055a9a5995477 mlir::HomomorphismSimplification<void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda0'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*, llvm::SmallVector<mlir::OpOperand*, 6u>&), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda1'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda1'(mlir::Operation*), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda'(mlir::Operation*, std::optional<mlir::Operation*>), void mlir::mesh::populateAllReduceEndomorphismSimplificationPatterns<mlir::arith::MaxSIOp>(mlir::RewritePatternSet&, mlir::mesh::ReductionKind)::'lambda2'(mlir::Operation*), mlir::detail::CreateAlgebraicOpForEndomorphismSimplification>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/home/workdir/llvm-project/build/bin/mlir-opt+0x672e477)
#7 0x000055a9a647bd02 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::$_0>(long) PatternApplicator.cpp:0:0
#8 0x000055a9a64789ff mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/home/workdir/llvm-project/build/bin/mlir-opt+0x72119ff)
#9 0x000055a9a3be4f7a (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#10 0x000055a9a3be17d3 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x497a7d3)
#11 0x000055a9a3d5580e (anonymous namespace)::TestMeshSimplificationsPass::runOnOperation() TestSimplifications.cpp:0:0
#12 0x000055a9a3b63593 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/workdir/llvm-project/build/bin/mlir-opt+0x48fc593)
#13 0x000055a9a3b63e32 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x48fce32)
#14 0x000055a9a3b6660e mlir::PassManager::run(mlir::Operation*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x48ff60e)
#15 0x000055a9a3b5e57b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#16 0x000055a9a3b5e1d4 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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#17 0x000055a9a3c0e125 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) (/home/workdir/llvm-project/build/bin/mlir-opt+0x49a7125)
#18 0x000055a9a3b573c2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x48f03c2)
#19 0x000055a9a3b57678 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x48f0678)
#20 0x000055a9a3b57892 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x48f0892)
#21 0x000055a9a0666a07 main (/home/workdir/llvm-project/build/bin/mlir-opt+0x13ffa07)
#22 0x00007fd518227d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#23 0x00007fd518227e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#24 0x000055a9a06664a5 _start (/home/workdir/llvm-project/build/bin/mlir-opt+0x13ff4a5)
Segmentation fault (core dumped)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWltz27gV_jXwC8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