llvm-project
llvm-project copied to clipboard
[CodeGenPrepare] GC relocate is incorrectly tied to the statepoint
Godbolt link: https://godbolt.org/z/39frWe6ja
Run opt -codegenprepare on the test
bug.ll.txt
Failure looks like:
gc relocate is incorrectly tied to the statepoint
%tmp5 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token undef, i32 1, i32 1) ; (opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::GCStatepointInst; From = const llvm::Value]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -codegenprepare <source>
1. Running pass 'Function Pass Manager' on module '<source>'.
2. Running pass 'Module Verifier' on function '@widget'
#0 0x000055b0e8778c2f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x000055b0e877665c SignalHandler(int) Signals.cpp:0:0
#2 0x00007f7ef27743c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
#3 0x00007f7ef224103b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
#4 0x00007f7ef2220859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007f7ef2220729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007f7ef2232006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
#7 0x000055b0e7e89fab llvm::GCProjectionInst::getStatepoint() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2c89fab)
#8 0x000055b0e7e8a376 llvm::GCRelocateInst::getBasePtr() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2c8a376)
#9 0x000055b0e7d56a5c (anonymous namespace)::AssemblyWriter::printInfoComment(llvm::Value const&) AsmWriter.cpp:0:0
#10 0x000055b0e7d59f92 (anonymous namespace)::AssemblyWriter::printInstruction(llvm::Instruction const&) AsmWriter.cpp:0:0
#11 0x000055b0e7d62199 llvm::Value::print(llvm::raw_ostream&, llvm::ModuleSlotTracker&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2b62199)
#12 0x000055b0e7f24beb llvm::VerifierSupport::Write(llvm::Value const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2d24beb)
#13 0x000055b0e7f2bb28 void llvm::VerifierSupport::CheckFailed<llvm::CallBase, llvm::Value*>(llvm::Twine const&, llvm::CallBase const&, llvm::Value* const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2d2bb28)
#14 0x000055b0e7f40313 (anonymous namespace)::Verifier::visitCallBase(llvm::CallBase&) Verifier.cpp:0:0
#15 0x000055b0e7f43561 (anonymous namespace)::Verifier::visitCallInst(llvm::CallInst&) Verifier.cpp:0:0
#16 0x000055b0e7f48734 llvm::InstVisitor<(anonymous namespace)::Verifier, void>::visit(llvm::Function&) Verifier.cpp:0:0
#17 0x000055b0e7f48a98 (anonymous namespace)::Verifier::verify(llvm::Function const&) Verifier.cpp:0:0
#18 0x000055b0e7f49185 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) Verifier.cpp:0:0
#19 0x000055b0e7ead366 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2cad366)
#20 0x000055b0e7ead6b9 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2cad6b9)
#21 0x000055b0e7eae019 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2cae019)
#22 0x000055b0e5dee67f main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xbee67f)
#23 0x00007f7ef22220b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#24 0x000055b0e5ea542a _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xca542a)
Compiler returned: 139
If we replace true in bb10 with undef, then the bug disappears. As part of the codegenprepare optimization, an attempt is made to merge bb6 and bb10, as a result of which token becomes undef due to the unreachability of the block with token. Codegenprepare can't handle token undef. I think that the solution to this problem is to teach cast undef to process this same undef.
commit d693fd29f1885e72b90428999aee92573abb9c2d (HEAD -> main, origin/main, origin/HEAD)
Author: Max Kazantsev <[email protected]>
Date: Mon Jul 18 16:13:58 2022 +0700
[Verifier] Make Verifier recognize undef tokens as correct IR
Undef tokens may appear in unreached code as result of RAUW of some optimization,
and it should not be considered as bad IR.
Patch by Dmitry Bakunevich!
Differential Revision: https://reviews.llvm.org/D128904
Reviewed By: mkazantsev