[X86] Remove some duplicate ConstantSDNode casts. NFC.

Avoid repeated isa<> and cast<> by just performing a dyn_cast<ConstantSDNode>
This commit is contained in:
Simon Pilgrim 2020-05-15 18:23:19 +01:00
parent 91ef7cb508
commit 330b7491d5
1 changed files with 20 additions and 20 deletions

View File

@ -8261,8 +8261,8 @@ static bool findEltLoadSrc(SDValue Elt, LoadSDNode *&Ld, int64_t &ByteOffset) {
case ISD::SCALAR_TO_VECTOR: case ISD::SCALAR_TO_VECTOR:
return findEltLoadSrc(Elt.getOperand(0), Ld, ByteOffset); return findEltLoadSrc(Elt.getOperand(0), Ld, ByteOffset);
case ISD::SRL: case ISD::SRL:
if (isa<ConstantSDNode>(Elt.getOperand(1))) { if (auto *IdxC = dyn_cast<ConstantSDNode>(Elt.getOperand(1))) {
uint64_t Idx = Elt.getConstantOperandVal(1); uint64_t Idx = IdxC->getZExtValue();
if ((Idx % 8) == 0 && findEltLoadSrc(Elt.getOperand(0), Ld, ByteOffset)) { if ((Idx % 8) == 0 && findEltLoadSrc(Elt.getOperand(0), Ld, ByteOffset)) {
ByteOffset += Idx / 8; ByteOffset += Idx / 8;
return true; return true;
@ -8270,13 +8270,13 @@ static bool findEltLoadSrc(SDValue Elt, LoadSDNode *&Ld, int64_t &ByteOffset) {
} }
break; break;
case ISD::EXTRACT_VECTOR_ELT: case ISD::EXTRACT_VECTOR_ELT:
if (isa<ConstantSDNode>(Elt.getOperand(1))) { if (auto *IdxC = dyn_cast<ConstantSDNode>(Elt.getOperand(1))) {
SDValue Src = Elt.getOperand(0); SDValue Src = Elt.getOperand(0);
unsigned SrcSizeInBits = Src.getScalarValueSizeInBits(); unsigned SrcSizeInBits = Src.getScalarValueSizeInBits();
unsigned DstSizeInBits = Elt.getScalarValueSizeInBits(); unsigned DstSizeInBits = Elt.getScalarValueSizeInBits();
if (DstSizeInBits == SrcSizeInBits && (SrcSizeInBits % 8) == 0 && if (DstSizeInBits == SrcSizeInBits && (SrcSizeInBits % 8) == 0 &&
findEltLoadSrc(Src, Ld, ByteOffset)) { findEltLoadSrc(Src, Ld, ByteOffset)) {
uint64_t Idx = Elt.getConstantOperandVal(1); uint64_t Idx = IdxC->getZExtValue();
ByteOffset += Idx * (SrcSizeInBits / 8); ByteOffset += Idx * (SrcSizeInBits / 8);
return true; return true;
} }
@ -9007,11 +9007,11 @@ static SDValue LowerBUILD_VECTORvXi1(SDValue Op, SelectionDAG &DAG,
SDValue In = Op.getOperand(idx); SDValue In = Op.getOperand(idx);
if (In.isUndef()) if (In.isUndef())
continue; continue;
if (!isa<ConstantSDNode>(In)) if (auto *InC = dyn_cast<ConstantSDNode>(In)) {
NonConstIdx.push_back(idx); Immediate |= (InC->getZExtValue() & 0x1) << idx;
else {
Immediate |= (cast<ConstantSDNode>(In)->getZExtValue() & 0x1) << idx;
HasConstElts = true; HasConstElts = true;
} else {
NonConstIdx.push_back(idx);
} }
if (SplatIdx < 0) if (SplatIdx < 0)
SplatIdx = idx; SplatIdx = idx;
@ -18092,6 +18092,7 @@ static SDValue ExtractBitFromMaskVector(SDValue Op, SelectionDAG &DAG,
SDLoc dl(Vec); SDLoc dl(Vec);
MVT VecVT = Vec.getSimpleValueType(); MVT VecVT = Vec.getSimpleValueType();
SDValue Idx = Op.getOperand(1); SDValue Idx = Op.getOperand(1);
auto* IdxC = dyn_cast<ConstantSDNode>(Idx);
MVT EltVT = Op.getSimpleValueType(); MVT EltVT = Op.getSimpleValueType();
assert((VecVT.getVectorNumElements() <= 16 || Subtarget.hasBWI()) && assert((VecVT.getVectorNumElements() <= 16 || Subtarget.hasBWI()) &&
@ -18099,7 +18100,7 @@ static SDValue ExtractBitFromMaskVector(SDValue Op, SelectionDAG &DAG,
// variable index can't be handled in mask registers, // variable index can't be handled in mask registers,
// extend vector to VR512/128 // extend vector to VR512/128
if (!isa<ConstantSDNode>(Idx)) { if (!IdxC) {
unsigned NumElts = VecVT.getVectorNumElements(); unsigned NumElts = VecVT.getVectorNumElements();
// Extending v8i1/v16i1 to 512-bit get better performance on KNL // Extending v8i1/v16i1 to 512-bit get better performance on KNL
// than extending to 128/256bit. // than extending to 128/256bit.
@ -18110,7 +18111,7 @@ static SDValue ExtractBitFromMaskVector(SDValue Op, SelectionDAG &DAG,
return DAG.getNode(ISD::TRUNCATE, dl, EltVT, Elt); return DAG.getNode(ISD::TRUNCATE, dl, EltVT, Elt);
} }
unsigned IdxVal = cast<ConstantSDNode>(Idx)->getZExtValue(); unsigned IdxVal = IdxC->getZExtValue();
if (IdxVal == 0) // the operation is legal if (IdxVal == 0) // the operation is legal
return Op; return Op;
@ -18139,11 +18140,12 @@ X86TargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
SDValue Vec = Op.getOperand(0); SDValue Vec = Op.getOperand(0);
MVT VecVT = Vec.getSimpleValueType(); MVT VecVT = Vec.getSimpleValueType();
SDValue Idx = Op.getOperand(1); SDValue Idx = Op.getOperand(1);
auto* IdxC = dyn_cast<ConstantSDNode>(Idx);
if (VecVT.getVectorElementType() == MVT::i1) if (VecVT.getVectorElementType() == MVT::i1)
return ExtractBitFromMaskVector(Op, DAG, Subtarget); return ExtractBitFromMaskVector(Op, DAG, Subtarget);
if (!isa<ConstantSDNode>(Idx)) { if (!IdxC) {
// Its more profitable to go through memory (1 cycles throughput) // Its more profitable to go through memory (1 cycles throughput)
// than using VMOVD + VPERMV/PSHUFB sequence ( 2/3 cycles throughput) // than using VMOVD + VPERMV/PSHUFB sequence ( 2/3 cycles throughput)
// IACA tool was used to get performance estimation // IACA tool was used to get performance estimation
@ -18177,7 +18179,7 @@ X86TargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
return SDValue(); return SDValue();
} }
unsigned IdxVal = cast<ConstantSDNode>(Idx)->getZExtValue(); unsigned IdxVal = IdxC->getZExtValue();
// If this is a 256-bit vector result, first extract the 128-bit vector and // If this is a 256-bit vector result, first extract the 128-bit vector and
// then extract the element from the 128-bit vector. // then extract the element from the 128-bit vector.
@ -18299,9 +18301,7 @@ static SDValue InsertBitToMaskVector(SDValue Op, SelectionDAG &DAG,
// Copy into a k-register, extract to v1i1 and insert_subvector. // Copy into a k-register, extract to v1i1 and insert_subvector.
SDValue EltInVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v1i1, Elt); SDValue EltInVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v1i1, Elt);
return DAG.getNode(ISD::INSERT_SUBVECTOR, dl, VecVT, Vec, EltInVec, Idx);
return DAG.getNode(ISD::INSERT_SUBVECTOR, dl, VecVT, Vec, EltInVec,
Op.getOperand(2));
} }
SDValue X86TargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op, SDValue X86TargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op,
@ -21299,8 +21299,8 @@ static bool matchScalarReduction(SDValue Op, ISD::NodeType BinOp,
return false; return false;
// Quit if without a constant index. // Quit if without a constant index.
SDValue Idx = I->getOperand(1); auto *Idx = dyn_cast<ConstantSDNode>(I->getOperand(1));
if (!isa<ConstantSDNode>(Idx)) if (!Idx)
return false; return false;
SDValue Src = I->getOperand(0); SDValue Src = I->getOperand(0);
@ -21316,8 +21316,9 @@ static bool matchScalarReduction(SDValue Op, ISD::NodeType BinOp,
M = SrcOpMap.insert(std::make_pair(Src, EltCount)).first; M = SrcOpMap.insert(std::make_pair(Src, EltCount)).first;
SrcOps.push_back(Src); SrcOps.push_back(Src);
} }
// Quit if element already used. // Quit if element already used.
unsigned CIdx = cast<ConstantSDNode>(Idx)->getZExtValue(); unsigned CIdx = Idx->getZExtValue();
if (M->second[CIdx]) if (M->second[CIdx])
return false; return false;
M->second.setBit(CIdx); M->second.setBit(CIdx);
@ -35909,8 +35910,7 @@ static SDValue combineTargetShuffle(SDValue N, SelectionDAG &DAG,
assert(VT == MVT::v4f32 && "INSERTPS ValueType must be MVT::v4f32"); assert(VT == MVT::v4f32 && "INSERTPS ValueType must be MVT::v4f32");
SDValue Op0 = N.getOperand(0); SDValue Op0 = N.getOperand(0);
SDValue Op1 = N.getOperand(1); SDValue Op1 = N.getOperand(1);
SDValue Op2 = N.getOperand(2); unsigned InsertPSMask = N.getConstantOperandVal(2);
unsigned InsertPSMask = cast<ConstantSDNode>(Op2)->getZExtValue();
unsigned SrcIdx = (InsertPSMask >> 6) & 0x3; unsigned SrcIdx = (InsertPSMask >> 6) & 0x3;
unsigned DstIdx = (InsertPSMask >> 4) & 0x3; unsigned DstIdx = (InsertPSMask >> 4) & 0x3;
unsigned ZeroMask = InsertPSMask & 0xF; unsigned ZeroMask = InsertPSMask & 0xF;