Skip to content

[MLIR]crashes on omp.parallel due to missing terminator in AllocaScopeHoister #137333

@sweead

Description

@sweead

test commit: 8c7a2ce

step to reproduce:

mlir-opt test.mlir -test-lower-to-llvm

minimal test case:

module {
  llvm.func @powf(f32, f32) -> f32 attributes {memory_effects = #llvm.memory_effects<other = none, argMem = none, inaccessibleMem = none>, sym_visibility = "private"}
  func.func @main() -> memref<2x2xf32> {
    %c1 = arith.constant 1 : index
    %c2 = arith.constant 2 : index
    %c0 = arith.constant 0 : index
    %0 = llvm.mlir.constant(-4.770000e+00 : f32) : f32
    %1 = llvm.mlir.constant(8.751000e+01 : f32) : f32
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<2x2xf32>
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.mlir.constant(4 : i32) : i32
    omp.parallel num_threads(%3 : i32) {
      omp.wsloop {
        omp.loop_nest (%arg0, %arg1) : index = (%c0, %c0) to (%c2, %c2) step (%c1, %c1) {
          memref.alloca_scope  {
            %4 = llvm.call @powf(%1, %0) : (f32, f32) -> f32
            memref.store %4, %alloc[%arg0, %arg1] : memref<2x2xf32>
          }
          omp.yield
        }
      }
      omp.terminator
    }
    return %alloc : memref<2x2xf32>
  }
}

Crash backtrace:

mlir-opt: /home/workdir/llvm-project/mlir/lib/IR/Block.cpp:247: Operation *mlir::Block::getTerminator(): Assertion `mightHaveTerminator()' 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 -test-lower-to-llvm test.mlir
 #0 0x0000564b4a48ff78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/workdir/llvm-project/build/bin/mlir-opt+0x1342f78)
 #1 0x0000564b4a48da9e llvm::sys::RunSignalHandlers() (/home/workdir/llvm-project/build/bin/mlir-opt+0x1340a9e)
 #2 0x0000564b4a490981 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f431d00e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f431d0629fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f431d00e476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f431cff47f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f431cff471b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f431d005e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000564b4d7c826f mlir::Block::getTerminator() (/home/workdir/llvm-project/build/bin/mlir-opt+0x467b26f)
#10 0x0000564b4bf685d6 AllocaScopeHoister::matchAndRewrite(mlir::memref::AllocaScopeOp, mlir::PatternRewriter&) const (/home/workdir/llvm-project/build/bin/mlir-opt+0x2e1b5d6)
#11 0x0000564b4feea442 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
#12 0x0000564b4fee713f 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+0x6d9a13f)
#13 0x0000564b4d76485a (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#14 0x0000564b4d7610b3 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x46140b3)
#15 0x0000564b4d704c45 (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#16 0x0000564b4d6e6373 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/workdir/llvm-project/build/bin/mlir-opt+0x4599373)
#17 0x0000564b4d6e6c12 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+0x4599c12)
#18 0x0000564b4d6e93ee mlir::PassManager::run(mlir::Operation*) (/home/workdir/llvm-project/build/bin/mlir-opt+0x459c3ee)
#19 0x0000564b4d6e196b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000564b4d6e15c4 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
#21 0x0000564b4d78d9e5 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+0x46409e5)
#22 0x0000564b4d6da7b2 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+0x458d7b2)
#23 0x0000564b4d6daa68 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x458da68)
#24 0x0000564b4d6dac82 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/workdir/llvm-project/build/bin/mlir-opt+0x458dc82)
#25 0x0000564b4a46f4ef main (/home/workdir/llvm-project/build/bin/mlir-opt+0x13224ef)
#26 0x00007f431cff5d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007f431cff5e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x0000564b4a46f045 _start (/home/workdir/llvm-project/build/bin/mlir-opt+0x1322045)
Aborted (core dumped)

Metadata

Metadata

Assignees

Labels

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

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions