[llvm] [X86][AVX] Fix handling of out-of-bounds shift amounts in AVX2 vector shift nodes (PR #84426)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 9 01:49:09 PST 2024


================
@@ -47291,6 +47291,16 @@ static SDValue combineShiftRightArithmetic(SDNode *N, SelectionDAG &DAG,
   if (SDValue V = combineShiftToPMULH(N, DAG, Subtarget))
     return V;
 
+  APInt ShiftAmt;
+  SDNode *UMinNode = N1.getNode();
+  if (UMinNode->getOpcode() == ISD::UMIN &&
+      ISD::isConstantSplatVector(UMinNode->getOperand(1).getNode(), ShiftAmt) &&
+      ShiftAmt == VT.getScalarSizeInBits() - 1) {
+    SDValue ShrAmtVal = UMinNode->getOperand(0);
+    SDLoc DL(N);
+    return DAG.getNode(N->getOpcode(), DL, N->getVTList(), N0, ShrAmtVal);
----------------
SahilPatidar wrote:

I tried the following code:
```cpp
unsigned int Opcode = N->getOpcode();
if (supportedVectorShiftWithImm(VT, Subtarget, X86ISD::VSRAV)) {
     Opcode = X86ISD::VSRAV;
}
```
But with this code, it crashes the above test.:
```
LLVM ERROR: Cannot select: t13: v4i32 = X86ISD::VSRAV t2, t4
  t2: v4i32,ch = CopyFromReg t0, Register:v4i32 %0
    t1: v4i32 = Register %0
  t4: v4i32,ch = CopyFromReg t0, Register:v4i32 %1
    t3: v4i32 = Register %1
In function: combine_vec_ashr_out_of_bound
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: build/bin/llc -mtriple=x86_64-unknown-unknown -mattr=+sse4.1
1.	Running pass 'Function Pass Manager' on module '<stdin>'.
2.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@combine_vec_ashr_out_of_bound'
 #0 0x0000000107ec3c14 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105c37c14)
 #1 0x0000000107ec417c PrintStackTraceSignalHandler(void*) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105c3817c)
 #2 0x0000000107ec1d58 llvm::sys::RunSignalHandlers() (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105c35d58)
 #3 0x0000000107ec5db4 SignalHandler(int) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105c39db4)
 #4 0x000000018d945a24 (/usr/lib/system/libsystem_platform.dylib+0x18046da24)
 #5 0x000000018d915cc0 (/usr/lib/system/libsystem_pthread.dylib+0x18043dcc0)
 #6 0x000000018d821a40 (/usr/lib/system/libsystem_c.dylib+0x180349a40)
 #7 0x0000000107d53964 llvm::report_fatal_error(llvm::Twine const&, bool) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105ac7964)
 #8 0x0000000107bb2154 llvm::SmallVectorTemplateCommon<(anonymous namespace)::MatchScope, void>::back() (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105926154)
 #9 0x0000000107bae860 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105922860)
#10 0x00000001048779a4 (anonymous namespace)::X86DAGToDAGISel::SelectCode(llvm::SDNode*) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1025eb9a4)
#11 0x000000010486c1e4 (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1025e01e4)
#12 0x0000000107b9ff2c llvm::SelectionDAGISel::DoInstructionSelection() (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105913f2c)
#13 0x0000000107b9eb5c llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105912b5c)
#14 0x0000000107b9d708 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, true>, bool&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x105911708)
#15 0x0000000107b9be54 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x10590fe54)
#16 0x0000000107b993a0 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x10590d3a0)
#17 0x000000010485cad4 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1025d0ad4)
#18 0x0000000106031ce0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x103da5ce0)
#19 0x0000000106b6bfb0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1048dffb0)
#20 0x0000000106b731e8 llvm::FPPassManager::runOnModule(llvm::Module&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1048e71e8)
#21 0x0000000106b6c844 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1048e0844)
#22 0x0000000106b6c3d0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1048e03d0)
#23 0x0000000106b735e8 llvm::legacy::PassManager::run(llvm::Module&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1048e75e8)
#24 0x00000001022925a4 compileModule(char**, llvm::LLVMContext&) (/Users/sahilpatidar/Desktop/llvm/llvm-project/build/bin/llc+0x1000065a4)
```

https://github.com/llvm/llvm-project/pull/84426


More information about the llvm-commits mailing list