Skip to content

[MLIR] Crash in -test-mesh-simplifications due to null scf.reduce body when simplifying arith.maxsi inside scf.parallel #148619

Open
@sweead

Description

@sweead

test commit: 87e39c3

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]mlir

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions