[llvm] [X86][AVX] Fix handling of out-of-bounds shift amounts in AVX2 vector logical shift nodes #83840 (PR #86922)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 03:25: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 &&
----------------
RKSimon wrote:
Add a description comment:
```
// fold select(icmp_ult(amt,BW),shl(x,amt),0) -> avx2 psllv(x,amt)
// fold select(icmp_ult(amt,BW),srl(x,amt),0) -> avx2 psrlv(x,amt)
```
https://github.com/llvm/llvm-project/pull/86922
More information about the llvm-commits
mailing list