From 739c9f0b79335edf8810b15e67d43a5b41ab1cd5 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sun, 6 Oct 2019 19:07:00 +0000 Subject: [PATCH] [X86][SSE] Remove resolveTargetShuffleInputs and use getTargetShuffleInputs directly. Move the resolveTargetShuffleInputsAndMask call to after the shuffle mask combine before the undef/zero constant fold instead. llvm-svn: 373868 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 64 +++++++++---------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 52b3a723107f..7ffe3971b6f8 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -6816,11 +6816,10 @@ static bool getTargetShuffleAndZeroables(SDValue N, SmallVectorImpl &Mask, // Forward declaration (for getFauxShuffleMask recursive check). // TODO: Use DemandedElts variant. -static bool resolveTargetShuffleInputs(SDValue Op, - SmallVectorImpl &Inputs, - SmallVectorImpl &Mask, - SelectionDAG &DAG, unsigned Depth, - bool ResolveZero); +static bool getTargetShuffleInputs(SDValue Op, SmallVectorImpl &Inputs, + SmallVectorImpl &Mask, + SelectionDAG &DAG, unsigned Depth, + bool ResolveZero); // Attempt to decode ops that could be represented as a shuffle mask. // The decoded shuffle mask may contain a different number of elements to the @@ -6923,10 +6922,10 @@ static bool getFauxShuffleMask(SDValue N, const APInt &DemandedElts, return false; SmallVector SrcMask0, SrcMask1; SmallVector SrcInputs0, SrcInputs1; - if (!resolveTargetShuffleInputs(N0, SrcInputs0, SrcMask0, DAG, Depth + 1, - ResolveZero) || - !resolveTargetShuffleInputs(N1, SrcInputs1, SrcMask1, DAG, Depth + 1, - ResolveZero)) + if (!getTargetShuffleInputs(N0, SrcInputs0, SrcMask0, DAG, Depth + 1, + ResolveZero) || + !getTargetShuffleInputs(N1, SrcInputs1, SrcMask1, DAG, Depth + 1, + ResolveZero)) return false; int MaskSize = std::max(SrcMask0.size(), SrcMask1.size()); SmallVector Mask0, Mask1; @@ -6975,8 +6974,8 @@ static bool getFauxShuffleMask(SDValue N, const APInt &DemandedElts, // Handle INSERT_SUBVECTOR(SRC0, SHUFFLE(SRC1)). SmallVector SubMask; SmallVector SubInputs; - if (!resolveTargetShuffleInputs(peekThroughOneUseBitcasts(Sub), SubInputs, - SubMask, DAG, Depth + 1, ResolveZero)) + if (!getTargetShuffleInputs(peekThroughOneUseBitcasts(Sub), SubInputs, + SubMask, DAG, Depth + 1, ResolveZero)) return false; if (SubMask.size() != NumSubElts) { assert(((SubMask.size() % NumSubElts) == 0 || @@ -7277,33 +7276,14 @@ static bool getTargetShuffleInputs(SDValue Op, const APInt &DemandedElts, ResolveZero); } -/// Calls getTargetShuffleInputs to resolve a target shuffle mask's inputs -/// and set the SM_SentinelUndef and SM_SentinelZero values. Then check the -/// remaining input indices in case we now have a unary shuffle and adjust the -/// inputs accordingly. -/// Returns true if the target shuffle mask was decoded. -static bool resolveTargetShuffleInputs(SDValue Op, const APInt &DemandedElts, - SmallVectorImpl &Inputs, - SmallVectorImpl &Mask, - SelectionDAG &DAG, unsigned Depth, - bool ResolveZero) { - if (!getTargetShuffleInputs(Op, DemandedElts, Inputs, Mask, DAG, Depth, - ResolveZero)) - return false; - - resolveTargetShuffleInputsAndMask(Inputs, Mask); - return true; -} - -static bool resolveTargetShuffleInputs(SDValue Op, - SmallVectorImpl &Inputs, - SmallVectorImpl &Mask, - SelectionDAG &DAG, unsigned Depth, - bool ResolveZero = true) { +static bool getTargetShuffleInputs(SDValue Op, SmallVectorImpl &Inputs, + SmallVectorImpl &Mask, + SelectionDAG &DAG, unsigned Depth = 0, + bool ResolveZero = true) { unsigned NumElts = Op.getValueType().getVectorNumElements(); APInt DemandedElts = APInt::getAllOnesValue(NumElts); - return resolveTargetShuffleInputs(Op, DemandedElts, Inputs, Mask, DAG, Depth, - ResolveZero); + return getTargetShuffleInputs(Op, DemandedElts, Inputs, Mask, DAG, Depth, + ResolveZero); } /// Returns the scalar element that will make up the ith @@ -33006,7 +32986,7 @@ static SDValue combineX86ShufflesRecursively( // Extract target shuffle mask and resolve sentinels and inputs. SmallVector OpMask; SmallVector OpInputs; - if (!resolveTargetShuffleInputs(Op, OpInputs, OpMask, DAG, Depth)) + if (!getTargetShuffleInputs(Op, OpInputs, OpMask, DAG, Depth)) return SDValue(); // Add the inputs to the Ops list, avoiding duplicates. @@ -33109,6 +33089,9 @@ static SDValue combineX86ShufflesRecursively( Mask[i] = OpMaskedIdx; } + // Remove unused/repeated shuffle source ops. + resolveTargetShuffleInputsAndMask(Ops, Mask); + // Handle the all undef/zero cases early. if (all_of(Mask, [](int Idx) { return Idx == SM_SentinelUndef; })) return DAG.getUNDEF(Root.getValueType()); @@ -33120,10 +33103,7 @@ static SDValue combineX86ShufflesRecursively( return getZeroVector(Root.getSimpleValueType(), Subtarget, DAG, SDLoc(Root)); - // Remove unused/repeated shuffle source ops. - resolveTargetShuffleInputsAndMask(Ops, Mask); assert(!Ops.empty() && "Shuffle with no inputs detected"); - HasVariableMask |= isTargetShuffleVariableMask(Op.getOpcode()); // Update the list of shuffle nodes that have been combined so far. @@ -34962,7 +34942,7 @@ SDValue X86TargetLowering::SimplifyMultipleUseDemandedBitsForTargetNode( SmallVector ShuffleMask; SmallVector ShuffleOps; if (VT.isSimple() && VT.isVector() && - resolveTargetShuffleInputs(Op, ShuffleOps, ShuffleMask, DAG, Depth)) { + getTargetShuffleInputs(Op, ShuffleOps, ShuffleMask, DAG, Depth)) { // If all the demanded elts are from one operand and are inline, // then we can use the operand directly. int NumOps = ShuffleOps.size(); @@ -36041,7 +36021,7 @@ static SDValue combineExtractWithShuffle(SDNode *N, SelectionDAG &DAG, // Resolve the target shuffle inputs and mask. SmallVector Mask; SmallVector Ops; - if (!resolveTargetShuffleInputs(SrcBC, Ops, Mask, DAG, 0)) + if (!getTargetShuffleInputs(SrcBC, Ops, Mask, DAG)) return SDValue(); // Attempt to narrow/widen the shuffle mask to the correct size.