[llvm] [X86] getFauxShuffleMask - generalise logical shifts to work with non-uniform shift amounts (PR #137349)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 26 03:05:25 PDT 2025
================
@@ -6443,25 +6443,36 @@ static bool getFauxShuffleMask(SDValue N, const APInt &DemandedElts,
}
case ISD::SHL:
case ISD::SRL: {
- // We can only decode 'whole byte' bit shifts as shuffles.
- std::optional<uint64_t> Amt = DAG.getValidShiftAmount(N, DemandedElts);
- if (!Amt || (*Amt % 8) != 0)
+ APInt UndefElts;
+ SmallVector<APInt, 32> EltBits;
+ if (!getTargetConstantBitsFromNode(N.getOperand(1), NumBitsPerElt,
+ UndefElts, EltBits,
+ /*AllowWholeUndefs*/ true,
+ /*AllowPartialUndefs*/ false))
return false;
- uint64_t ByteShift = *Amt / 8;
- Ops.push_back(N.getOperand(0));
+ // We can only decode 'whole byte' bit shifts as shuffles.
+ for (unsigned I = 0; I != NumElts; ++I)
+ if (DemandedElts[I] && !UndefElts[I] &&
+ (EltBits[I].urem(8) != 0 || EltBits[I].uge(NumBitsPerElt)))
----------------
RKSimon wrote:
It can happen, and should generate poison, but tbh I just wanted to avoid the issue - I also wondered if I'll need to support the AVX2 X86ISD logical shift variants at some point which do handle out of bounds shift amounts.
https://github.com/llvm/llvm-project/pull/137349
More information about the llvm-commits
mailing list