Skip to content
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

[NVPTX] DAG->DAG Pattern Instruction Selection crashes on mul i1 #57404

Closed
DataCorrupted opened this issue Aug 27, 2022 · 1 comment
Closed

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/6jdcM1vjG

define i1 @f(i1* %A1, <32 x i1> %L) {
  %E1 = extractelement <32 x i1> %L, i1 false
  %E = extractelement <32 x i1> %L, i8 16
  %B = mul i1 %E1, %E
  ret i1 %B
}
LLVM ERROR: Cannot select: t96: i1 = mul t108, t121
  t108: i1 = truncate t100
    t100: i16,i16,i16,i16,ch = NVPTXISD::LoadV4<(dereferenceable invariant load (s32) from `i1 addrspace(101)* null`, addrspace 101)> t0, TargetExternalSymbol:i32'f_param_1', undef:i32, Constant:i32<0>
      t2: i32 = TargetExternalSymbol'f_param_1'
      t1: i32 = undef
      t3: i32 = Constant<0>
  t121: i1 = truncate t113
    t113: i16,i16,i16,i16,ch = NVPTXISD::LoadV4<(dereferenceable invariant load (s32) from `i1 addrspace(101)* null`, addrspace 101)> t0, t50, undef:i32, Constant:i32<0>
      t50: i32 = add TargetExternalSymbol:i32'f_param_1', Constant:i32<16>
        t2: i32 = TargetExternalSymbol'f_param_1'
        t49: i32 = Constant<16>
      t1: i32 = undef
      t3: i32 = Constant<0>
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 mul.ll
1.      Running pass 'Function Pass Manager' on module 'mul.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 0x00007fa1db0d8980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007fa1d9fc8e87 raise /build/glibc-uZu3wS/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007fa1d9fca7f1 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 0x00007fa1d9fabc87 __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
Artem-B pushed a commit that referenced this issue Jan 31, 2024
Add TableGen patterns to convert more instructions to boolean
expressions:

- **mul -> and/or**: i1 multiply instructions currently cannot be
selected causing the compiler to crash. See
#57404
- **select -> and/or**: Converting selects to and/or can enable more
optimizations. `InstCombine` cannot do this as aggressively due to
poison semantics.
carlosgalvezp pushed a commit to carlosgalvezp/llvm-project that referenced this issue Feb 1, 2024
Add TableGen patterns to convert more instructions to boolean
expressions:

- **mul -> and/or**: i1 multiply instructions currently cannot be
selected causing the compiler to crash. See
llvm#57404
- **select -> and/or**: Converting selects to and/or can enable more
optimizations. `InstCombine` cannot do this as aggressively due to
poison semantics.
@DataCorrupted
Copy link
Member Author

Looks like this is fixed on upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants