Open atulkatti opened 4 weeks ago
@llvm/issue-subscribers-backend-x86
Author: atul (atulkatti)
Can you check if this was fixed in e027e04f0139126b0a4af3aba0dbb31fdf22ea62?
Legalizing node: t14: i1,ch = llvm.coro.alloc t12:1, TargetConstant:i64<27>, t12, ../../nwc/main.cc:19
Analyzing result type: i1
Promote integer result: t14: i1,ch = llvm.coro.alloc t12:1, TargetConstant:i64<27>, t12, ../../nwc/main.cc:19
PromoteIntegerResult #0: t14: i1,ch = llvm.coro.alloc t12:1, TargetConstant:i64<27>, t12, ../../nwc/main.cc:19
LLVM ERROR: Do not know how to promote this operator!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: ninja\\bin\\llc coroutines_main.bc -o bar.s -debug
1. Running pass 'Function Pass Manager' on module 'coroutines_main.bc'.
2. Running pass 'X86 DAG->DAG Instruction Selection' on function '@"?Deploy@@YA?AUTacticalNuke@@XZ"'
I presume g7088a5ed
is from commit 7088a5ed, which is before 234cb4c6e3a382a5c0b3396647a1839699944ec0. So it's probably not related
I don't think llvm.coro.alloc is supposed to reach the backend. The CoroCleanup pass should remove it in the middle end.
There's a commit that mention CoroCleanup from the end of July
commit 3a9ef4e69a3fec3203bd3e1caa53edf4b76843cf
Author: Wei Wang <apollo.mobility@gmail.com>
Date: Mon Jul 29 17:42:01 2024
[Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (#100205)
This is re-land of #90310 after making asan skip pre-split coroutines in
#99415.
Skip CoroSplit and CoroCleanup in LTO pre-link pipeline so that
CoroElide can happen after callee coroutine is imported into caller's
module in ThinLTO.
@atulkatti are you using ThinLTO?
@topperc Yes, we are using ThinLTO. But on the reduced repro I was able to reproduce the issue even when LTO was disabled.
@topperc Yes, we are using ThinLTO. But on the reduced repro I was able to reproduce the issue even when LTO was disabled.
@topperc Correction, my earlier attempt to disable ThinLTO didn't work as expected due to flags being added elsewhere in the build system. Once I disabled ThinLTO correctly the crash went away. However, we can't disable ThinLTO completely in our product build. Would it be possible to make a fix for this issue when ThinLTO is being used?
@apolloww Can you take a look at this?
The change moves both CoroSplit
and CoroCleanup
into ThinLTO post link optimization pipeline, but CoroCleanup
should still run before going into codegen passes. If the pre-link compilation has -flto=thin
flag, the output bitcode retains all coroutine intrinsics, including llvm.coro.alloc
. The bitcode file is meant to be fed into ThinLTO compilation. Otherwise, all coroutine intrinsics should be lowered.
Could you share how Just checked the bitcode file, it has module summary, so likely compiled with coroutines_main.bc
is generated?-flto=thin
. Then llc
invokes codegen passes without calling opt passes. If ThinLTO is not going to be applied to the bitcode module, you can just remove the -flto=thin
flag.
@apolloww The repro file I shared is from a reduced repro of the real issue we are facing in Edge official build where ThinLTO is enabled. The crashing code exists in a first party library that we consume and we can't disable ThinLTO due to performance implications in important scenarios. Can a fix be made so that the intrinsics get lowered before codegen when ThinLTO is enabled?
@apolloww The repro file I shared is from a reduced repro of the real issue we are facing in Edge official build where ThinLTO is enabled. The crashing code exists in a first party library that we consume and we can't disable ThinLTO due to performance implications in important scenarios. Can a fix be made so that the intrinsics get lowered before codegen when ThinLTO is enabled?
Could you share the flags that are passed into pre-link compilation and linking? If every step is invoked via clang driver, the intrinsics should be lowered before entering the CodeGen pipeline. So if you have something like
# compile
clang -flto=thin -O3 -c foo.cpp -o foo.o
clang -flto=thin -O3 -c bar.cpp -o bar.o
#link
clang -flto=thin -fuse-ld=lld foo.o. bar.o -o bin
It should work.
@apolloww Thanks for looking into this and providing guidance. After looking into our build logs I was able to confirm that we are indeed disabling ThinLTO during linking. So there is a mismatch in the ThinLTO enablement between the compilation and linking steps. We will try to workaround this issue by enabling ThinLTO for the failing component.
I can reproduce this crash as well, and revert https://github.com/llvm/llvm-project/pull/100205 helps.
I can reproduce this crash as well, and revert #100205 helps.
Is this still causing asan pipeline failure?
No asan failures, it's not on bot.
This is a different issue, internal build with CFI and ThinLTO.
LLVM ERROR: Cannot select: intrinsic %llvm.coro.subfn.addr
Stack dump:
....
llvm::report_fatal_error(llvm::Twine const&, bool) llvm-project/llvm/lib/Support/ErrorHandling.cpp:0:5
llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:4360:47
(third_party/crosstool/v18/llvm_unstable/toolchain/bin/ld+0x3e1d76a)
(anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) llvm-project/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:0:0
llvm::operator!=(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::SDNode, false, false, void, false, void>, false, false> const&, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::SDNode, false, false, void, false, void>, false, false> const&) llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:178:16
llvm::SelectionDAGISel::DoInstructionSelection() llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1237:25
llvm::SelectionDAGISel::CodeGenAndEmitDAG() llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1076:3
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1599:8
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:615:22
llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:374:20
llvm::MachineFunctionPass::runOnFunction(llvm::Function&) llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:94:13
llvm::FPPassManager::runOnFunction(llvm::Function&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1408:27
llvm::FPPassManager::runOnModule(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1454:13
(anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1523:27
llvm::legacy::PassManagerImpl::run(llvm::Module&) llvm-project/llvm/lib/IR/LegacyPassManager.cpp:541:44
std::__u::unique_ptr<llvm::ToolOutputFile, std::__u::default_delete<llvm::ToolOutputFile>>::operator bool() const third_party/crosstool/v18/stable/src/libcxx/include/__memory/unique_ptr.h:297:19
codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) llvm-project/llvm/lib/LTO/LTOBackend.cpp:432:7
std::__u::__function::__policy_func<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>::~__policy_func() third_party/crosstool/v18/stable/src/libcxx/include/__functional/function.h:692:9
std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>::~function() third_party/crosstool/v18/stable/src/libcxx/include/__functional/function.h:980:43
llvm::lto::backend(llvm::lto::Config const&, std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) llvm-project/llvm/lib/LTO/LTOBackend.cpp:534:5
std::__u::__function::__policy_func<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>::~__policy_func() third_party/crosstool/v18/stable/src/libcxx/include/__functional/function.h:692:9
std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>::~function() third_party/crosstool/v18/stable/src/libcxx/include/__functional/function.h:980:43
llvm::lto::LTO::runRegularLTO(std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) llvm-project/llvm/lib/LTO/LTO.cpp:1353:13
std::__u::__function::__policy_func<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>::~__policy_func() third_party/crosstool/v18/stable/src/libcxx/include/__functional/function.h:692:9
std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>::~function() third_party/crosstool/v18/stable/src/libcxx/include/__functional/function.h:980:43
llvm::lto::LTO::run(std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, std::__u::function<llvm::Expected<std::__u::function<llvm::Expected<std::__u::unique_ptr<llvm::CachedFileStream, std::__u::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>> (unsigned int, llvm::StringRef, llvm::Twine const&)>) llvm-project/llvm/lib/LTO/LTO.cpp:1186:18
lld::elf::BitcodeCompiler::compile() llvm-project/lld/ELF/LTO.cpp:327:5
std::__u::vector<lld::elf::InputFile*, std::__u::allocator<lld::elf::InputFile*>>::begin() third_party/crosstool/v18/stable/src/libcxx/include/vector:1411:28
void lld::elf::LinkerDriver::compileBitcodeFiles<llvm::object::ELFType<(llvm::endianness)1, true>>(bool) llvm-project/lld/ELF/Driver.cpp:2521:24
void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) llvm-project/lld/ELF/Driver.cpp:2994:3
lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) llvm-project/lld/ELF/Driver.cpp:0:5
lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) llvm-project/lld/ELF/Driver.cpp:172:10
lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) llvm-project/lld/Common/DriverDispatcher.cpp:164:11
lld_main(int, char**, llvm::ToolContext const&) llvm-project/lld/tools/lld/lld.cpp:115:1
main llvm-project/lld/lld-driver.cpp:17:10
No asan failures, it's not on bot.
This is a different issue, internal build with CFI and ThinLTO.
OK. I'll put the change behind a flag.
No asan failures, it's not on bot. This is a different issue, internal build with CFI and ThinLTO.
OK. I'll put the change behind a flag.
Flags is LGTM.
However, I didn't look into details, but are there difficulties to support invocation like in the stack trace?
No asan failures, it's not on bot. This is a different issue, internal build with CFI and ThinLTO.
OK. I'll put the change behind a flag.
Flags is LGTM.
However, I didn't look into details, but are there difficulties to support invocation like in the stack trace?
From the stack trace, it seems the invocation was through regular LTO compilation. I think Coro passes are not enabled in regular LTO post-link pipeline.
Even if we fix this case, there are still cases that user can take the pre-link compilation output and feed directly into codegen pipeline.
We are seeing this crash in official builds of Edge. This repro has been provided using internal LLVM build that should be compatible with the following Chromium upstream LLVM build: CLANG_REVISION = 'llvmorg-20-init-1009-g7088a5ed' CLANG_SUB_REVISION = 9
This actively blocks our consumption of the latest LLVM bits, so it will help if this gets looked at soon. We had the exact same break during Chromium clang roll in May-2024 and it got fixed with the next Clang roll in June-2024. It is broken again with the latest August-2024 Clang roll referenced above. We are wondering if this is related to churn in the coroutines codebase. Attaching the reduced repro source file if this can be included in your test suite so it can prevent future breaks in this area.
The crash reproduces with the LLC command line. Bugpoint crashed during reduction. llc.exe coroutines_main.bc
Please find both the reduced repro source file and the .bc file (attached as .bc.txt). coroutines_main.bc.txt Reduce repro source file main.cc.txt