From bb650daeaf5d7dd9786ce90431c4c68afb09fabc Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 6 Dec 2018 16:29:14 +0000 Subject: [PATCH] [X86] Refactored IsSplatVector to use switch. NFCI. Initial step towards making the function more generic (and probably move into SelectionDAG). This is necessary to avoid massive codegen bloat for PR38243 (Add modulo rotate support to LowerRotate). llvm-svn: 348498 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 45 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 5bdfdfa..d725fbd 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -24069,47 +24069,50 @@ static SDValue LowerScalarImmediateShift(SDValue Op, SelectionDAG &DAG, static SDValue IsSplatVector(SDValue V, int &SplatIdx) { V = peekThroughEXTRACT_SUBVECTORs(V); - // Check if this is a splat build_vector node. - if (BuildVectorSDNode *BV = dyn_cast(V)) { - BitVector BVUndefElts; - SDValue SplatAmt = BV->getSplatValue(&BVUndefElts); + unsigned Opcode = V.getOpcode(); + switch (Opcode) { + case ISD::BUILD_VECTOR: { + BitVector UndefElts; + SDValue SplatAmt = cast(V)->getSplatValue(&UndefElts); if (SplatAmt && !SplatAmt.isUndef()) { - for (int i = 0, e = BVUndefElts.size(); i != e; ++i) - if (!BVUndefElts[i]) { + for (int i = 0, e = UndefElts.size(); i != e; ++i) + if (!UndefElts[i]) { SplatIdx = i; return V; } } - return SDValue(); + break; } - - // Check for SUB(SPLAT_BV, SPLAT) cases from rotate patterns. - if (V.getOpcode() == ISD::SUB) { + case ISD::VECTOR_SHUFFLE: { + // Check if this is a shuffle node doing a splat. + auto *SVN = cast(V); + if (!SVN->isSplat()) + break; + int Idx = SVN->getSplatIndex(); + int NumElts = V.getValueType().getVectorNumElements(); + SplatIdx = Idx % NumElts; + return V.getOperand(Idx / NumElts); + } + case ISD::SUB: { SDValue LHS = peekThroughEXTRACT_SUBVECTORs(V.getOperand(0)); SDValue RHS = peekThroughEXTRACT_SUBVECTORs(V.getOperand(1)); // Ensure that the corresponding splat BV element is not UNDEF. BitVector UndefElts; - BuildVectorSDNode *BV0 = dyn_cast(LHS); - ShuffleVectorSDNode *SVN1 = dyn_cast(RHS); + auto *BV0 = dyn_cast(LHS); + auto *SVN1 = dyn_cast(RHS); if (BV0 && SVN1 && BV0->getSplatValue(&UndefElts) && SVN1->isSplat()) { int Idx = SVN1->getSplatIndex(); if (!UndefElts[Idx]) { SplatIdx = Idx; return V; } - return SDValue(); } + break; + } } - // Check if this is a shuffle node doing a splat. - ShuffleVectorSDNode *SVN = dyn_cast(V); - if (!SVN || !SVN->isSplat()) - return SDValue(); - int Idx = SVN->getSplatIndex(); - int NumElts = V.getValueType().getVectorNumElements(); - SplatIdx = Idx % NumElts; - return V.getOperand(Idx / NumElts); + return SDValue(); } static SDValue GetSplatValue(SDValue V, const SDLoc &dl, -- 2.7.4