[llvm] r344451 - [X86] Pull out target constant splat helper function. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 13 07:28:40 PDT 2018
Author: rksimon
Date: Sat Oct 13 07:28:40 2018
New Revision: 344451
URL: http://llvm.org/viewvc/llvm-project?rev=344451&view=rev
Log:
[X86] Pull out target constant splat helper function. NFCI.
The code in LowerScalarImmediateShift is just a more powerful version of ISD::isConstantSplatVector.
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=344451&r1=344450&r2=344451&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Sat Oct 13 07:28:40 2018
@@ -5830,6 +5830,30 @@ static bool getTargetConstantBitsFromNod
return false;
}
+static bool isConstantSplat(SDValue Op, APInt &SplatVal) {
+ APInt UndefElts;
+ SmallVector<APInt, 16> EltBits;
+ if (getTargetConstantBitsFromNode(Op, Op.getScalarValueSizeInBits(),
+ UndefElts, EltBits, true, false)) {
+ int SplatIndex = -1;
+ for (int i = 0, e = EltBits.size(); i != e; ++i) {
+ if (UndefElts[i])
+ continue;
+ if (0 <= SplatIndex && EltBits[i] != EltBits[SplatIndex]) {
+ SplatIndex = -1;
+ break;
+ }
+ SplatIndex = i;
+ }
+ if (0 <= SplatIndex) {
+ SplatVal = EltBits[SplatIndex];
+ return true;
+ }
+ }
+
+ return false;
+}
+
static bool getTargetShuffleMaskIndices(SDValue MaskNode,
unsigned MaskEltSizeInBits,
SmallVectorImpl<uint64_t> &RawMask) {
@@ -23600,7 +23624,6 @@ static SDValue LowerScalarImmediateShift
SDLoc dl(Op);
SDValue R = Op.getOperand(0);
SDValue Amt = Op.getOperand(1);
- unsigned EltSizeInBits = VT.getScalarSizeInBits();
unsigned X86Opc = getTargetVShiftUniformOpcode(Op.getOpcode(), false);
auto ArithmeticShiftRight64 = [&](uint64_t ShiftAmt) {
@@ -23644,24 +23667,11 @@ static SDValue LowerScalarImmediateShift
};
// Optimize shl/srl/sra with constant shift amount.
- APInt UndefElts;
- SmallVector<APInt, 8> EltBits;
- if (!getTargetConstantBitsFromNode(Amt, EltSizeInBits, UndefElts, EltBits,
- true, false))
- return SDValue();
-
- int SplatIndex = -1;
- for (int i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
- if (UndefElts[i])
- continue;
- if (0 <= SplatIndex && EltBits[i] != EltBits[SplatIndex])
- return SDValue();
- SplatIndex = i;
- }
- if (SplatIndex < 0)
+ APInt APIntShiftAmt;
+ if (!isConstantSplat(Amt, APIntShiftAmt))
return SDValue();
+ uint64_t ShiftAmt = APIntShiftAmt.getZExtValue();
- uint64_t ShiftAmt = EltBits[SplatIndex].getZExtValue();
if (SupportedVectorShiftWithImm(VT, Subtarget, Op.getOpcode()))
return getTargetVShiftByConstNode(X86Opc, dl, VT, R, ShiftAmt, DAG);
More information about the llvm-commits
mailing list