Skip to content

[mlir] --inline crashed with assertion failure "UNREACHABLE" #73285

Closed
@ghost

Description

git version: ba89749

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: mlir-opt --inline a.mlir

a.mlir:

module {
  llvm.func @malloc(i64) -> !llvm.ptr
  llvm.func @func2() -> vector<4xf16> {
    %cst0_i32 = spirv.Constant 0 : i32
    %1 = builtin.unrealized_conversion_cast %cst0_i32 : i32 to index
    %3 = llvm.mlir.constant(64 : index) : i64
    %41 = llvm.mlir.constant(4 : index) : i64
    %44 = llvm.mlir.constant(0 : index) : i64
    %54 = llvm.mlir.constant(32 : index) : i64
    %56 = llvm.mlir.constant(1 : index) : i64
    %65 = builtin.unrealized_conversion_cast %44 : i64 to index
    %67 = builtin.unrealized_conversion_cast %41 : i64 to index
    %69 = builtin.unrealized_conversion_cast %56 : i64 to index
    %75 = builtin.unrealized_conversion_cast %54 : i64 to index
    %83 = llvm.mlir.zero : !llvm.ptr
    %89 = llvm.sub %3, %56  : i64
    %184 = llvm.getelementptr %83[1024] : (!llvm.ptr) -> !llvm.ptr, i32
    %185 = llvm.ptrtoint %184 : !llvm.ptr to i64
    %186 = llvm.add %185, %3  : i64
    %187 = llvm.call @malloc(%186) : (i64) -> !llvm.ptr
    %188 = llvm.ptrtoint %187 : !llvm.ptr to i64
    %189 = llvm.add %188, %89  : i64
    %190 = llvm.urem %189, %3  : i64
    %191 = llvm.sub %189, %190  : i64
    %192 = llvm.inttoptr %191 : i64 to !llvm.ptr
    cf.br ^bb1(%65 : index)
  ^bb1(%309: index):  // 2 preds: ^bb0, ^bb5
    %310 = arith.cmpi slt, %309, %67 : index
    cf.cond_br %310, ^bb2, ^bb6
  ^bb2:  // pred: ^bb1
    %328 = arith.addi %309, %69 : index
    cf.br ^bb1(%328 : index)
  ^bb6:  // pred: ^bb1
    %402 = llvm.alloca %56 x !llvm.array<2 x i64> : (i64) -> !llvm.ptr
    %403 = llvm.getelementptr %402[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.array<2 x i64>
    %404 = llvm.load %403 : !llvm.ptr -> i64
    %405 = builtin.unrealized_conversion_cast %404 : i64 to index
    cf.br ^bb19(%65 : index)
  ^bb19(%407: index):  // 2 preds: ^bb18, ^bb29
    %408 = arith.cmpi slt, %407, %405 : index
    cf.cond_br %408, ^bb20, ^bb30
  ^bb20:  // pred: ^bb19
    cf.br ^bb21(%65 : index)
  ^bb21(%409: index):  // 2 preds: ^bb20, ^bb28
    %444 = arith.addi %409, %69 : index
    cf.br ^bb21(%444 : index)
  ^bb30:  // pred: ^bb19
    cf.br ^bb31(%65 : index)
  ^bb31(%486: index):  // 2 preds: ^bb30, ^bb53
    %487 = arith.cmpi slt, %486, %69 : index
    cf.cond_br %487, ^bb32, ^bb54
  ^bb32:  // pred: ^bb31
    cf.br ^bb33(%65 : index)
  ^bb33(%488: index):  // 2 preds: ^bb32, ^bb52
    %643 = arith.addi %488, %69 : index
    cf.br ^bb33(%643 : index)
  ^bb54:  // pred: ^bb31
    cf.br ^bb67(%65 : index)
  ^bb67(%695: index):  // 2 preds: ^bb66, ^bb77
    %696 = arith.cmpi slt, %695, %69 : index
    cf.cond_br %696, ^bb68, ^bb78
  ^bb68:  // pred: ^bb67
    %732 = arith.addi %695, %69 : index
    cf.br ^bb67(%732 : index)
  ^bb78:  // pred: ^bb67
    %749 = builtin.unrealized_conversion_cast %56 : i64 to index
    cf.br ^bb79(%65 : index)
  ^bb79(%756: index):  // 2 preds: ^bb78, ^bb89
    %757 = arith.cmpi slt, %756, %749 : index
    cf.cond_br %757, ^bb80, ^bb90
  ^bb80:  // pred: ^bb79
    %794 = arith.addi %756, %69 : index
    cf.br ^bb79(%794 : index)
  ^bb90:  // pred: ^bb79
    cf.br ^bb121(%65 : index)
  ^bb121(%924: index):  // 2 preds: ^bb120, ^bb131
    %925 = arith.cmpi slt, %924, %69 : index
    cf.cond_br %925, ^bb122, ^bb132
  ^bb122:  // pred: ^bb121
    cf.br ^bb127(%1 : index)
  ^bb127(%942: index):  // 2 preds: ^bb126, ^bb128
    %958 = arith.addi %942, %69 : index
    cf.br ^bb127(%958 : index)
  ^bb132:  // pred: ^bb121
    cf.br ^bb133(%65 : index)
  ^bb133(%981: index):  // 2 preds: ^bb132, ^bb143
    %982 = arith.cmpi slt, %981, %75 : index
    cf.cond_br %982, ^bb134, ^bb144
  ^bb134:  // pred: ^bb133
    cf.br ^bb139(%1 : index)
  ^bb139(%999: index):  // 2 preds: ^bb138, ^bb140
    %1015 = arith.addi %999, %69 : index
    cf.br ^bb139(%1015 : index)
  ^bb144:  // pred: ^bb133
    cf.br ^bb169(%65 : index)
  ^bb169(%1157: index):  // 2 preds: ^bb168, ^bb179
    cf.br ^bb171(%65 : index)
  ^bb171(%1159: index):  // 2 preds: ^bb170, ^bb178
    cf.br ^bb173(%1 : index)
  ^bb173(%1173: index):  // 2 preds: ^bb172, ^bb177
    cf.br ^bb175(%1 : index)
  ^bb175(%1175: index):  // 2 preds: ^bb174, ^bb176
    %1177 = builtin.unrealized_conversion_cast %1173 : index to i32

    // Function call of __mlir_math_ipowi_i32
    %1189 = spirv.FunctionCall @__mlir_math_ipowi_i32(%1177, %1177) : (i32, i32) -> i32
    cf.br ^bb175(%65 : index)
  }
  spirv.func @__mlir_math_ipowi_i32(%arg0: i32, %arg1: i32) -> i32 "None" attributes {llvm.linkage = #llvm.linkage<linkonce_odr>, sym_visibility = "private"} {
    %cst0_i32 = spirv.Constant 0 : i32
    %cst1_i32 = spirv.Constant 1 : i32
    %cst-1_i32 = spirv.Constant -1 : i32
    %0 = spirv.IEqual %arg1, %cst0_i32 : i32
    cf.cond_br %0, ^bb1(%cst1_i32 : i32), ^bb2
  ^bb1(%1: i32):  // 6 preds: ^bb0, ^bb5, ^bb6, ^bb7, ^bb7, ^bb10
    spirv.ReturnValue %1 : i32
  ^bb2:  // pred: ^bb0
    %7 = spirv.BitwiseAnd %arg1, %cst1_i32 : i32
    %8 = spirv.INotEqual %7, %cst0_i32 : i32
    cf.cond_br %8, ^bb1(%cst-1_i32 : i32), ^bb1(%cst1_i32 : i32)
  }
}

trace:

unimplemented spirv.ReturnValue in inliner
UNREACHABLE executed at /data/bin/llvm-project/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp:98!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/bin/llvm-project/build/bin/mlir-opt --inline a.mlir
 #0 0x0000562d0a91701f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x160201f)
 #1 0x0000562d0a914074 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f5211db5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f52118a000b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f521187f859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x0000562d0a93ac4e (/data/bin/llvm-project/build/bin/mlir-opt+0x1625c4e)
 #6 0x0000562d0c2cfa89 (anonymous namespace)::SPIRVInlinerInterface::handleTerminator(mlir::Operation*, mlir::Block*) const SPIRVDialect.cpp:0:0
 #7 0x0000562d0d5ca033 inlineRegionImpl(mlir::InlinerInterface&, mlir::Region*, mlir::Block*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void, false>, false, false>, mlir::IRMapping&, mlir::ValueRange, mlir::TypeRange, std::optional<mlir::Location>, bool, mlir::CallOpInterface) InliningUtils.cpp:0:0
 #8 0x0000562d0d5cc85c mlir::inlineCall(mlir::InlinerInterface&, mlir::CallOpInterface, mlir::CallableOpInterface, mlir::Region*, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b785c)
 #9 0x0000562d0d53e8a6 inlineCallsInSCC((anonymous namespace)::Inliner&, (anonymous namespace)::CGUseList&, (anonymous namespace)::CallGraphSCC&) Inliner.cpp:0:0
#10 0x0000562d0d54069d mlir::LogicalResult llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>::callback_fn<(anonymous namespace)::InlinerPass::runOnOperation()::'lambda'((anonymous namespace)::CallGraphSCC&)>(long, (anonymous namespace)::CallGraphSCC&) Inliner.cpp:0:0
#11 0x0000562d0d5418a3 (anonymous namespace)::InlinerPass::runOnOperation() Inliner.cpp:0:0
#12 0x0000562d0d5088ee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x41f38ee)
#13 0x0000562d0d508dca mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x41f3dca)
#14 0x0000562d0d5095f4 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x41f45f4)
#15 0x0000562d0d4fa363 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#16 0x0000562d0d4fb834 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#17 0x0000562d0d4fb9e4 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>>, 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
#18 0x0000562d0d5facd4 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/bin/llvm-project/build/bin/mlir-opt+0x42e5cd4)
#19 0x0000562d0d4f4247 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x41df247)
#20 0x0000562d0d4fbb31 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x41e6b31)
#21 0x0000562d0d4fbf96 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x41e6f96)
#22 0x0000562d0a84e5eb main (/data/bin/llvm-project/build/bin/mlir-opt+0x15395eb)
#23 0x00007f5211881083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#24 0x0000562d0a8e737e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x15d237e)
Aborted (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions