mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[X86] LowerRotate - use X86::isConstantSplat to detect constant splat rotation amounts.
Avoid code duplication and matches what we do for the similar LowerFunnelShift and LowerScalarImmediateShift methods.
This commit is contained in:
parent
59335a3b3a
commit
8b6b4c77d6
@ -27359,30 +27359,19 @@ static SDValue LowerRotate(SDValue Op, const X86Subtarget &Subtarget,
|
||||
int NumElts = VT.getVectorNumElements();
|
||||
|
||||
// Check for constant splat rotation amount.
|
||||
APInt UndefElts;
|
||||
SmallVector<APInt, 32> EltBits;
|
||||
int CstSplatIndex = -1;
|
||||
if (getTargetConstantBitsFromNode(Amt, EltSizeInBits, UndefElts, EltBits))
|
||||
for (int i = 0; i != NumElts; ++i)
|
||||
if (!UndefElts[i]) {
|
||||
if (CstSplatIndex < 0 || EltBits[i] == EltBits[CstSplatIndex]) {
|
||||
CstSplatIndex = i;
|
||||
continue;
|
||||
}
|
||||
CstSplatIndex = -1;
|
||||
break;
|
||||
}
|
||||
APInt CstSplatValue;
|
||||
bool IsCstSplat = X86::isConstantSplat(Amt, CstSplatValue);
|
||||
|
||||
// Check for splat rotate by zero.
|
||||
if (0 <= CstSplatIndex && EltBits[CstSplatIndex].urem(EltSizeInBits) == 0)
|
||||
if (IsCstSplat && CstSplatValue.urem(EltSizeInBits) == 0)
|
||||
return R;
|
||||
|
||||
// AVX512 implicitly uses modulo rotation amounts.
|
||||
if (Subtarget.hasAVX512() && 32 <= EltSizeInBits) {
|
||||
// Attempt to rotate by immediate.
|
||||
if (0 <= CstSplatIndex) {
|
||||
if (IsCstSplat) {
|
||||
unsigned RotOpc = (Opcode == ISD::ROTL ? X86ISD::VROTLI : X86ISD::VROTRI);
|
||||
uint64_t RotAmt = EltBits[CstSplatIndex].urem(EltSizeInBits);
|
||||
uint64_t RotAmt = CstSplatValue.urem(EltSizeInBits);
|
||||
return DAG.getNode(RotOpc, DL, VT, R,
|
||||
DAG.getTargetConstant(RotAmt, DL, MVT::i8));
|
||||
}
|
||||
@ -27402,10 +27391,10 @@ static SDValue LowerRotate(SDValue Op, const X86Subtarget &Subtarget,
|
||||
assert(VT.is128BitVector() && "Only rotate 128-bit vectors!");
|
||||
|
||||
// Attempt to rotate by immediate.
|
||||
if (0 <= CstSplatIndex) {
|
||||
uint64_t RotateAmt = EltBits[CstSplatIndex].urem(EltSizeInBits);
|
||||
if (IsCstSplat) {
|
||||
uint64_t RotAmt = CstSplatValue.urem(EltSizeInBits);
|
||||
return DAG.getNode(X86ISD::VROTLI, DL, VT, R,
|
||||
DAG.getTargetConstant(RotateAmt, DL, MVT::i8));
|
||||
DAG.getTargetConstant(RotAmt, DL, MVT::i8));
|
||||
}
|
||||
|
||||
// Use general rotate by variable (per-element).
|
||||
@ -27422,7 +27411,7 @@ static SDValue LowerRotate(SDValue Op, const X86Subtarget &Subtarget,
|
||||
"Only vXi32/vXi16/vXi8 vector rotates supported");
|
||||
|
||||
// Rotate by an uniform constant - expand back to shifts.
|
||||
if (0 <= CstSplatIndex)
|
||||
if (IsCstSplat)
|
||||
return SDValue();
|
||||
|
||||
bool IsSplatAmt = DAG.isSplatValue(Amt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user