[mlir] GPU-to-LLVM Pass triggered Assertion failure "attempting to construct a TypeRange with null types"
MLIR built at commit https://github.com/llvm/llvm-project/commit/159cac50 Reproduced with:
mlir-opt temp.mlir --gpu-to-llvm
temp.mlir:
func.func private @async_execute_fn() -> (!async.token, !async.value<f32>) {
%0 = async.runtime.create : !async.token
%1 = async.runtime.create : !async.value<f32>
%2 = async.coro.id
%3 = async.coro.begin %2
%4 = async.coro.save %3
async.coro.suspend %4, ^bb3, ^bb1, ^bb2
^bb1:
cf.br ^bb2
^bb2:
cf.br ^bb3
^bb3:
return %0, %1 : !async.token, !async.value<f32>
}
trace:
Assertion failed: (llvm::all_of(types, [](Type t) { return t; }) && "attempting to construct a TypeRange with null types"), function TypeRange, file TypeRange.cpp, line 20.
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 temp.mlir --gpu-to-llvm
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 mlir-opt 0x00000001048e0818 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 mlir-opt 0x00000001048df880 llvm::sys::RunSignalHandlers() + 112
2 mlir-opt 0x00000001048e0eb0 SignalHandler(int) + 344
3 libsystem_platform.dylib 0x00000001aad414c4 _sigtramp + 56
4 libsystem_pthread.dylib 0x00000001aad29ee0 pthread_kill + 288
5 libsystem_c.dylib 0x00000001aac64340 abort + 168
6 libsystem_c.dylib 0x00000001aac63754 err + 0
7 mlir-opt 0x000000010664c39c mlir::TypeRange::TypeRange(llvm::ArrayRef<mlir::Type>) (.cold.2) + 0
8 mlir-opt 0x0000000106018698 mlir::TypeRange::TypeRange(mlir::OperandRange) + 0
9 mlir-opt 0x0000000105ffe9dc mlir::Operation::create(mlir::OperationState const&) + 60
10 mlir-opt 0x0000000105f89228 mlir::OpBuilder::create(mlir::OperationState const&) + 28
11 mlir-opt 0x0000000105a29d30 mlir::LLVM::UndefOp mlir::OpBuilder::create<mlir::LLVM::UndefOp, mlir::Type&>(mlir::Location, mlir::Type&) + 140
12 mlir-opt 0x0000000105a29984 (anonymous namespace)::ReturnOpLowering::matchAndRewrite(mlir::func::ReturnOp, mlir::func::ReturnOpAdaptor, mlir::ConversionPatternRewriter&) const + 572
13 mlir-opt 0x0000000105a29644 mlir::ConvertOpToLLVMPattern<mlir::func::ReturnOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const + 168
14 mlir-opt 0x0000000105f2df88 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const + 200
15 mlir-opt 0x0000000106191010 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) + 1420
16 mlir-opt 0x0000000105f38500 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) + 1948
17 mlir-opt 0x0000000105f31c78 (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, llvm::function_ref<void (mlir::Diagnostic&)>) + 936
18 mlir-opt 0x0000000105f33d68 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternSet const&, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>*) + 80
19 mlir-opt 0x0000000105a31678 (anonymous namespace)::GpuToLLVMConversionPass::runOnOperation() + 544
20 mlir-opt 0x0000000105ef66c4 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 428
21 mlir-opt 0x0000000105ef6bf4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 320
22 mlir-opt 0x0000000105ef8570 mlir::PassManager::run(mlir::Operation*) + 1148
23 mlir-opt 0x0000000105ef1934 performActions(llvm::raw_ostream&, bool, bool, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) + 504
24 mlir-opt 0x0000000105ef1504 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) + 704
25 mlir-opt 0x0000000105f5c9a0 mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) + 656
26 mlir-opt 0x0000000105eef92c mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) + 216
27 mlir-opt 0x0000000105eefe20 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) + 1208
28 mlir-opt 0x000000010478341c main + 108
29 dyld 0x0000000109801088 start + 516
@llvm/issue-subscribers-mlir-gpu
--convert-async-to-llvm will not crash. https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp#L300 is what aysnc-to-llvm uses to convert async.token and async.value.
gpu-to-llvm uses in https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp#L1131 and https://github.com/llvm/llvm-project/blob/main/mlir/lib/Conversion/AsyncToLLVM/AsyncToLLVM.cpp#L1132 to do the conversion. It does not convert the type to legal llvm type. So ReturnOpLowering::matchAndRewrite crash for a null packedType.
Works just fine with the latest compiler.