Skip to content

[NVPTX] icmp i1 used as branching condition crashes backend #58428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HazyFish opened this issue Oct 17, 2022 · 0 comments · Fixed by #115035
Closed

[NVPTX] icmp i1 used as branching condition crashes backend #58428

HazyFish opened this issue Oct 17, 2022 · 0 comments · Fixed by #115035
Assignees
Labels
backend:NVPTX crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:SelectionDAG SelectionDAGISel as well

Comments

@HazyFish
Copy link
Contributor

HazyFish commented Oct 17, 2022

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

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)
@EugeneZelenko EugeneZelenko added llvm:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Oct 17, 2022
AlexMaclean added a commit that referenced this issue Dec 5, 2024
Add DAG legalization support for expanding i1 SETCC nodes using
appropriate logical operations to simulate integer comparisons. Use
these expansions to handle i1 SETCC in NVPTX.

fixes #58428 and #57405
@EugeneZelenko EugeneZelenko added llvm:SelectionDAG SelectionDAGISel as well and removed llvm:codegen labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:NVPTX crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants