diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index cd3fa5c5372b..e25dc0242878 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -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 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);