Skip to content

[NVPTX] DAG->DAG Pattern Instruction Selection crashes on setcc #57405

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
DataCorrupted opened this issue Aug 27, 2022 · 0 comments · Fixed by #115035
Closed

[NVPTX] DAG->DAG Pattern Instruction Selection crashes on setcc #57405

DataCorrupted opened this issue Aug 27, 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

@DataCorrupted
Copy link
Member

DataCorrupted commented Aug 27, 2022

When compiling the following piece of code, NVPTX backend crashes.
The bug can be reproduced from LLVM14 or latest commit e723c69b94

You can find the reproduction here: https://llvm.godbolt.org/z/EWs3f5bsG

define void @f(<32 x i1>* %A) {
BB:
  br label %BB1

BB1:                                              ; preds = %BB1, %BB
  %L = load <32 x i1>, <32 x i1>* %A, align 4
  %E1 = extractelement <32 x i1> %L, i1 false
  %E = extractelement <32 x i1> %L, i8 16
  %C = icmp sge i1 %E1, %E
  br i1 %C, label %BB1, label %BB2

BB2:                                              ; preds = %BB1
  %I = insertelement <32 x i1> zeroinitializer, i1 %E, i64 0
  store <32 x i1> %I, <32 x i1>* %A, align 4
  ret void
}
LLVM ERROR: Cannot select: t14: i1 = setcc t304, t144, setge:ch
  t304: i1 = truncate t302
    t302: i16,ch = load<(load (s8) from %ir.A, align 4), anyext from i8> t0, t2, undef:i32
      t2: i32,ch = CopyFromReg t0, Register:i32 %1
        t1: i32 = Register %1
      t4: i32 = undef
  t144: i1 = truncate t142
    t142: i16,ch = load<(load (s8) from %ir.A + 2, align 2, basealign 4), anyext from i8> t0, t21, undef:i32
      t21: i32 = add nuw t2, Constant:i32<2>
        t2: i32,ch = CopyFromReg t0, Register:i32 %1
          t1: i32 = Register %1
        t20: i32 = Constant<2>
      t4: i32 = 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: /home/peter/aflplusplus-isel/llvm-project/build-debug/bin/llc -mtriple=nvptx setcc.ll
1.      Running pass 'Function Pass Manager' on module 'setcc.ll'.
2.      Running pass 'NVPTX DAG->DAG Pattern Instruction Selection' on function '@f'
 #0 0x0000000003a45a1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
 #1 0x0000000003a45bcb PrintStackTraceSignalHandler(void*) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x0000000003a44216 llvm::sys::RunSignalHandlers() /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Support/Signals.cpp:103:5
 #3 0x0000000003a462f5 SignalHandler(int) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007fd7f16e2980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007fd7f05d2e87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007fd7f05d47f1 abort /build/glibc-uZu3wS/glibc-2.27/stdlib/abort.c:81:0
 #7 0x000000000396ca74 llvm::report_fatal_error(llvm::Twine const&, bool) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
 #8 0x00000000037bec8b /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:3765:3
 #9 0x00000000037bc222 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:3667:9
#10 0x0000000001e0e299 llvm::NVPTXDAGToDAGISel::SelectCode(llvm::SDNode*) /home/peter/aflplusplus-isel/llvm-project/build-debug/lib/Target/NVPTX/NVPTXGenDAGISel.inc:86754:1
#11 0x0000000001e00944 llvm::NVPTXDAGToDAGISel::Select(llvm::SDNode*) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:505:1
#12 0x00000000037afdb9 llvm::SelectionDAGISel::DoInstructionSelection() /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1153:5
#13 0x00000000037aee0a llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:933:3
#14 0x00000000037ad7dd 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/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:685:1
#15 0x00000000037ad27b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1591:11
#16 0x00000000037aa81d llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:464:3
#17 0x0000000001e004e5 llvm::NVPTXDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:46:3
#18 0x000000000281fadd llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:85:8
#19 0x0000000002ef9146 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1430:23
#20 0x0000000002efdf72 llvm::FPPassManager::runOnModule(llvm::Module&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1476:16
#21 0x0000000002ef9a19 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:23
#22 0x0000000002ef958d llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:16
#23 0x0000000002efe251 llvm::legacy::PassManager::run(llvm::Module&) /home/peter/aflplusplus-isel/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1672:3
#24 0x0000000000d1ad70 compileModule(char**, llvm::LLVMContext&) /home/peter/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:737:41
#25 0x0000000000d190f2 main /home/peter/aflplusplus-isel/llvm-project/llvm/tools/llc/llc.cpp:418:13
#26 0x00007fd7f05b5c87 __libc_start_main /build/glibc-uZu3wS/glibc-2.27/csu/../csu/libc-start.c:344:0
#27 0x0000000000d188fa _start (/home/peter/aflplusplus-isel/llvm-project/build-debug/bin/llc+0xd188fa)
Aborted
@AlexMaclean AlexMaclean self-assigned this Nov 20, 2024
@AlexMaclean AlexMaclean linked a pull request Nov 20, 2024 that will close this issue
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 crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:SelectionDAG SelectionDAGISel as well 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.

3 participants