<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/142937>142937</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SelectionDAG][X86] Compiler crash when using `-opt-bisect-limit=0` because of `llvm.type.test.intrinsic`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
abhishek-kaushik22
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
abhishek-kaushik22
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org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