forked from OSchip/llvm-project
[X86] Pull out target constant splat helper function. NFCI.
The code in LowerScalarImmediateShift is just a more powerful version of ISD::isConstantSplatVector. llvm-svn: 344451
This commit is contained in:
parent
10434cbae1
commit
a03379527a
|
@ -5830,6 +5830,30 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
|
||||||
return false;
|
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,
|
static bool getTargetShuffleMaskIndices(SDValue MaskNode,
|
||||||
unsigned MaskEltSizeInBits,
|
unsigned MaskEltSizeInBits,
|
||||||
SmallVectorImpl<uint64_t> &RawMask) {
|
SmallVectorImpl<uint64_t> &RawMask) {
|
||||||
|
@ -23600,7 +23624,6 @@ static SDValue LowerScalarImmediateShift(SDValue Op, SelectionDAG &DAG,
|
||||||
SDLoc dl(Op);
|
SDLoc dl(Op);
|
||||||
SDValue R = Op.getOperand(0);
|
SDValue R = Op.getOperand(0);
|
||||||
SDValue Amt = Op.getOperand(1);
|
SDValue Amt = Op.getOperand(1);
|
||||||
unsigned EltSizeInBits = VT.getScalarSizeInBits();
|
|
||||||
unsigned X86Opc = getTargetVShiftUniformOpcode(Op.getOpcode(), false);
|
unsigned X86Opc = getTargetVShiftUniformOpcode(Op.getOpcode(), false);
|
||||||
|
|
||||||
auto ArithmeticShiftRight64 = [&](uint64_t ShiftAmt) {
|
auto ArithmeticShiftRight64 = [&](uint64_t ShiftAmt) {
|
||||||
|
@ -23644,24 +23667,11 @@ static SDValue LowerScalarImmediateShift(SDValue Op, SelectionDAG &DAG,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Optimize shl/srl/sra with constant shift amount.
|
// Optimize shl/srl/sra with constant shift amount.
|
||||||
APInt UndefElts;
|
APInt APIntShiftAmt;
|
||||||
SmallVector<APInt, 8> EltBits;
|
if (!isConstantSplat(Amt, APIntShiftAmt))
|
||||||
if (!getTargetConstantBitsFromNode(Amt, EltSizeInBits, UndefElts, EltBits,
|
|
||||||
true, false))
|
|
||||||
return SDValue();
|
return SDValue();
|
||||||
|
uint64_t ShiftAmt = APIntShiftAmt.getZExtValue();
|
||||||
|
|
||||||
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)
|
|
||||||
return SDValue();
|
|
||||||
|
|
||||||
uint64_t ShiftAmt = EltBits[SplatIndex].getZExtValue();
|
|
||||||
if (SupportedVectorShiftWithImm(VT, Subtarget, Op.getOpcode()))
|
if (SupportedVectorShiftWithImm(VT, Subtarget, Op.getOpcode()))
|
||||||
return getTargetVShiftByConstNode(X86Opc, dl, VT, R, ShiftAmt, DAG);
|
return getTargetVShiftByConstNode(X86Opc, dl, VT, R, ShiftAmt, DAG);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue