<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58428>58428</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[NVPTX] `icmp i1` used as branching condition crashes backend
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
HazyFish
</td>
</tr>
</table>
<pre>
## Description
When `icmp` instruction with i1 operands is used as a branching condition, `nvptx` backend crashes with error `Cannot select: t20: i1 = setcc t29, t24, setule:ch`.
`icmp eq` and `icmp ne` do not have the problem.
The problem doesn't exist when `icmp` is used on `i8`, `i16`, etc.
## Minimal Reproduction
https://godbolt.org/z/Taj5G5aGW
### Code
```ll
define i8 @f(i1 %0, i1 %1) {
BB:
%C = icmp ugt i1 %1, %0
br i1 %C, label %BB1, label %BB2
BB1:
ret i8 1
BB2:
ret i8 127
}
```
### Stack Trace
```
LLVM ERROR: Cannot select: t20: i1 = setcc t29, t24, setule:ch
t29: i1 = truncate t31
t31: i16,ch = load<(dereferenceable invariant load (s8) from `ptr addrspace(101) null`, addrspace 101), anyext from i8> t0, TargetExternalSymbol:i64'f_param_1', undef:i64
t7: i64 = TargetExternalSymbol'f_param_1'
t3: i64 = undef
t24: i1 = truncate t26
t26: i16,ch = load<(dereferenceable invariant load (s8) from `ptr addrspace(101) null`, addrspace 101), anyext from i8> t0, TargetExternalSymbol:i64'f_param_0', undef:i64
t1: i64 = TargetExternalSymbol'f_param_0'
t3: i64 = undef
In function: f
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: ./llvm-project/build-debug/bin/llc -mtriple=nvptx64 ./crash-reports/dagisel-nvptx/2.ll
1. Running pass 'Function Pass Manager' on module './crash-reports/dagisel-nvptx/2.ll'.
2. Running pass 'NVPTX DAG->DAG Pattern Instruction Selection' on function '@f'
#0 0x0000000003b0f2aa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
#1 0x0000000003b0f45b PrintStackTraceSignalHandler(void*) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
#2 0x0000000003b0daa6 llvm::sys::RunSignalHandlers() /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Signals.cpp:104:5
#3 0x0000000003b0fb85 SignalHandler(int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
#4 0x00007f3ee5b58980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#5 0x00007f3ee4a48e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#6 0x00007f3ee4a4a7f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
#7 0x0000000003a352f4 llvm::report_fatal_error(llvm::Twine const&, bool) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
#8 0x00000000038829cb /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:3779:3
#9 0x000000000387ff62 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:3681:9
#10 0x0000000001e968e9 llvm::NVPTXDAGToDAGISel::SelectCode(llvm::SDNode*) /home/henry/aflplusplus-isel/llvm-project/build-debug/lib/Target/NVPTX/NVPTXGenDAGISel.inc:86782:1
#11 0x0000000001e88f94 llvm::NVPTXDAGToDAGISel::Select(llvm::SDNode*) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:505:1
#12 0x0000000003873a69 llvm::SelectionDAGISel::DoInstructionSelection() /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1165:5
#13 0x0000000003872aba llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:936:3
#14 0x000000000387148d llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:688:1
#15 0x0000000003870f2b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1603:11
#16 0x000000000386e4d6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:467:3
#17 0x0000000001e88b35 llvm::NVPTXDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:46:3
#18 0x00000000028bfd55 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:8
#19 0x0000000002fa7ca6 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1430:23
#20 0x0000000002facad2 llvm::FPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1476:16
#21 0x0000000002fa8579 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#22 0x0000000002fa80ed llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:16
#23 0x0000000002facdb1 llvm::legacy::PassManager::run(llvm::Module&) /home/henry/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#24 0x0000000000d3dd1c compileModule(char**, llvm::LLVMContext&) /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:737:41
#25 0x0000000000d3c0c2 main /home/henry/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:418:13
#26 0x00007f3ee4a2bc87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#27 0x0000000000d3b8ca _start (./llvm-project/build-debug/bin/llc+0xd3b8ca)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVWdty4zYS_Rr5BSUVCd6gBz34OvHWOHHZ3snWvqhAEpSQkKCWAG05X59ukBQvo5Q1iTPOTnlE4sLGOd2N7iYYl-nrakY9-CNXQieV3BlZqplzNXPOm9-ft0KRWejIpNjBhUilTVUnOI28SLMl0iXlTlRcpZpITWotUsI14SSGvmQr1YYkpUqlFUwvUZZ63pk9Cot58qtQKUkqrrdCNwJFVZUVTrvkSpWGaJGLxMy8c2KogxdYceZdQb9JEuhbolRDfbxAX50LmJRsQcBiSKTlQMT_cGWA27EiSmBPWhJcbcufBTFbQXZVGeeiaGU89T0wU2igEhki9lIb8jJVUauFsull8NMSl27YNgD7GF1jhDupZMFz8iBgsbRR83Da1pidBnozegN_mzKNy9wsymoDrd_g_xP_JfgU8E8_fy0bxV-WqZjopPnL86YjFZlUgkhGZr6TzShDXdPAQm5u3Rldkll00cy_uEAw9pbg6KW1jNVqvTH9I5eNlHZiXLUjlziS81jk2Lq4cCdtOgSLw_1ilTAI0x3PoEdm0KidE11NWB9X0q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