Skip to content

[SelectionDAG][X86] Compiler crash when using -opt-bisect-limit=0 because of llvm.type.test intrinsic #142937

@abhishek-kaushik22

Description

@abhishek-kaushik22

Godbolt: https://godbolt.org/z/r1feYojPc

When trying to bisect a file compiled with -flto I encountered a compiler crash

BISECT: NOT running pass (1) Merge contiguous icmps into a memcmp on function (wombat)
BISECT: NOT running pass (2) Expand memcmp() to load/stores on function (wombat)
BISECT: NOT running pass (3) Constant Hoisting on function (wombat)
BISECT: NOT running pass (4) Partially inline calls to library functions on function (wombat)
BISECT: NOT running pass (5) X86 Partial Reduction on function (wombat)
BISECT: NOT running pass (6) CodeGen Prepare on function (wombat)
BISECT: NOT running pass (7) X86 DAG->DAG Instruction Selection on function (wombat)
llc: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::MDNode; From = llvm::Metadata]: 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/llc -o /app/output.s -opt-bisect-limit=0 -mtriple=x86_64-- <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@wombat'
 #0 0x0000000003f17898 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3f17898)
 #1 0x0000000003f15224 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007c77e3a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007c77e3a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007c77e3a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007c77e3a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007c77e3a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007c77e3a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000003beb607 llvm::SelectionDAGBuilder::getValueImpl(llvm::Value const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3beb607)
 #9 0x0000000003bf1c83 llvm::SelectionDAGBuilder::getValue(llvm::Value const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3bf1c83)
#10 0x0000000003c03f53 llvm::SelectionDAGBuilder::visitTargetIntrinsic(llvm::CallInst const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3c03f53)
#11 0x0000000003c0c061 llvm::SelectionDAGBuilder::visitIntrinsicCall(llvm::CallInst const&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3c0c061)
#12 0x0000000003c18ac3 llvm::SelectionDAGBuilder::visitCall(llvm::CallInst const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3c18ac3)
#13 0x0000000003c2baef llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3c2baef)
#14 0x0000000003cbad3d llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, true>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3cbad3d)
#15 0x0000000003cbba8e llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3cbba8e)
#16 0x0000000003cbcf15 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3cbcf15)
#17 0x0000000003cad7df llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3cad7df)
#18 0x0000000002e5e86a llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#19 0x000000000348a4bf llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x348a4bf)
#20 0x000000000348a871 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x348a871)
#21 0x000000000348b111 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x348b111)
#22 0x00000000008c85a8 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#23 0x00000000007a640e main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7a640e)
#24 0x00007c77e3a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x00007c77e3a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00000000008bec85 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x8bec85)
Program terminated with signal: SIGSEGV
Compiler returned: 139

I managed to reduce to the llvm ir to

define void @wombat() {
bb:
  %call = call i1 @llvm.public.type.test(ptr null, metadata !"typeinfo")
  br label %bb1

bb1:
  call void @llvm.assume(i1 %call)
  ret void
}

The llvm*.type.test is supposed to be removed at the IR level but because of the bisect limit we encounter it in SelectionDAG and that causes a crash.

Metadata

Metadata

Labels

backend:X86crashPrefer [crash-on-valid] or [crash-on-invalid]llvm:SelectionDAGSelectionDAGISel as well

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions