[llvm] [X86][AVX] Fix handling of out-of-bounds shift amounts in AVX2 vector logical shift nodes #83840 (PR #86922)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 30 22:20:11 PDT 2024
================
@@ -45950,6 +45950,30 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG,
}
}
+ // Exploits AVX2 VSHLV/VSRLV instructions for efficient unsigned vector shifts
+ // with out-of-bounds clamping.
+
+ // Unlike general shift instructions (SHL/SRL), AVX2's VSHLV/VSRLV handle
+ // shift amounts exceeding the element bitwidth. VSHLV/VSRLV clamps the amount
+ // to bitwidth-1 for unsigned shifts, effectively performing a maximum left
+ // shift of bitwidth-1 positions. and returns zero for unsigned right shifts
+ // exceeding bitwidth-1.
+ if (N->getOpcode() == ISD::VSELECT &&
+ (LHS.getOpcode() == ISD::SRL || LHS.getOpcode() == ISD::SHL) &&
+ supportedVectorVarShift(VT, Subtarget, LHS.getOpcode())) {
+ APInt SV;
+ if (Cond.getOpcode() == ISD::SETCC &&
+ Cond.getOperand(0) == LHS.getOperand(1) &&
+ cast<CondCodeSDNode>(Cond.getOperand(2))->get() == ISD::SETULT &&
+ ISD::isConstantSplatVector(Cond.getOperand(1).getNode(), SV) &&
+ ISD::isConstantSplatVectorAllZeros(RHS.getNode()) &&
+ SV == VT.getScalarSizeInBits()) {
----------------
SahilPatidar wrote:
@RKSimon
https://github.com/llvm/llvm-project/pull/86922
More information about the llvm-commits
mailing list