[X86] isFNEG - use switch() instead of if-else tree. NFCI.

In a future patch this will avoid some checks which don't need to be done for some opcodes.
This commit is contained in:
Simon Pilgrim 2019-11-01 17:08:39 +00:00
parent 961d48df28
commit ea27d82814
1 changed files with 36 additions and 33 deletions

View File

@ -41459,23 +41459,25 @@ static SDValue isFNEG(SelectionDAG &DAG, SDNode *N, unsigned Depth = 0) {
SDValue Op = peekThroughBitcasts(SDValue(N, 0)); SDValue Op = peekThroughBitcasts(SDValue(N, 0));
EVT VT = Op->getValueType(0); EVT VT = Op->getValueType(0);
// Make sure the element size does't change.
// Make sure the element size doesn't change.
if (VT.getScalarSizeInBits() != ScalarSize) if (VT.getScalarSizeInBits() != ScalarSize)
return SDValue(); return SDValue();
if (auto SVOp = dyn_cast<ShuffleVectorSDNode>(Op.getNode())) { unsigned Opc = Op.getOpcode();
switch (Opc) {
case ISD::VECTOR_SHUFFLE: {
// For a VECTOR_SHUFFLE(VEC1, VEC2), if the VEC2 is undef, then the negate // For a VECTOR_SHUFFLE(VEC1, VEC2), if the VEC2 is undef, then the negate
// of this is VECTOR_SHUFFLE(-VEC1, UNDEF). The mask can be anything here. // of this is VECTOR_SHUFFLE(-VEC1, UNDEF). The mask can be anything here.
if (!SVOp->getOperand(1).isUndef()) if (!Op.getOperand(1).isUndef())
return SDValue(); return SDValue();
if (SDValue NegOp0 = isFNEG(DAG, SVOp->getOperand(0).getNode(), Depth + 1)) if (SDValue NegOp0 = isFNEG(DAG, Op.getOperand(0).getNode(), Depth + 1))
if (NegOp0.getValueType() == VT) // FIXME: Can we do better? if (NegOp0.getValueType() == VT) // FIXME: Can we do better?
return DAG.getVectorShuffle(VT, SDLoc(SVOp), NegOp0, DAG.getUNDEF(VT), return DAG.getVectorShuffle(VT, SDLoc(Op), NegOp0, DAG.getUNDEF(VT),
SVOp->getMask()); cast<ShuffleVectorSDNode>(Op)->getMask());
return SDValue(); break;
} }
unsigned Opc = Op.getOpcode(); case ISD::INSERT_VECTOR_ELT: {
if (Opc == ISD::INSERT_VECTOR_ELT) {
// Negate of INSERT_VECTOR_ELT(UNDEF, V, INDEX) is INSERT_VECTOR_ELT(UNDEF, // Negate of INSERT_VECTOR_ELT(UNDEF, V, INDEX) is INSERT_VECTOR_ELT(UNDEF,
// -V, INDEX). // -V, INDEX).
SDValue InsVector = Op.getOperand(0); SDValue InsVector = Op.getOperand(0);
@ -41486,27 +41488,26 @@ static SDValue isFNEG(SelectionDAG &DAG, SDNode *N, unsigned Depth = 0) {
if (NegInsVal.getValueType() == VT.getVectorElementType()) // FIXME if (NegInsVal.getValueType() == VT.getVectorElementType()) // FIXME
return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), VT, InsVector, return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), VT, InsVector,
NegInsVal, Op.getOperand(2)); NegInsVal, Op.getOperand(2));
return SDValue(); break;
} }
case ISD::FSUB:
if (Opc != X86ISD::FXOR && Opc != ISD::XOR && Opc != ISD::FSUB) case ISD::XOR:
return SDValue(); case X86ISD::FXOR: {
SDValue Op1 = Op.getOperand(1); SDValue Op1 = Op.getOperand(1);
SDValue Op0 = Op.getOperand(0); SDValue Op0 = Op.getOperand(0);
// For XOR and FXOR, we want to check if constant bits of Op1 are sign bit // For XOR and FXOR, we want to check if constant
// masks. For FSUB, we have to check if constant bits of Op0 are sign bit // bits of Op1 are sign bit masks. For FSUB, we
// masks and hence we swap the operands. // have to check if constant bits of Op0 are sign
// bit masks and hence we swap the operands.
if (Opc == ISD::FSUB) if (Opc == ISD::FSUB)
std::swap(Op0, Op1); std::swap(Op0, Op1);
APInt UndefElts; APInt UndefElts;
SmallVector<APInt, 16> EltBits; SmallVector<APInt, 16> EltBits;
// Extract constant bits and see if they are all sign bit masks. Ignore the // Extract constant bits and see if they are all
// undef elements. // sign bit masks. Ignore the undef elements.
if (getTargetConstantBitsFromNode(Op1, ScalarSize, if (getTargetConstantBitsFromNode(Op1, ScalarSize, UndefElts, EltBits,
UndefElts, EltBits,
/* AllowWholeUndefs */ true, /* AllowWholeUndefs */ true,
/* AllowPartialUndefs */ false)) { /* AllowPartialUndefs */ false)) {
for (unsigned I = 0, E = EltBits.size(); I < E; I++) for (unsigned I = 0, E = EltBits.size(); I < E; I++)
@ -41515,6 +41516,8 @@ static SDValue isFNEG(SelectionDAG &DAG, SDNode *N, unsigned Depth = 0) {
return peekThroughBitcasts(Op0); return peekThroughBitcasts(Op0);
} }
}
}
return SDValue(); return SDValue();
} }