Skip to content
Permalink
Browse files

[X86][SSE] Remove resolveTargetShuffleInputs and use getTargetShuffle…

…Inputs directly.

Move the resolveTargetShuffleInputsAndMask call to after the shuffle mask combine before the undef/zero constant fold instead.

llvm-svn: 373868
  • Loading branch information
RKSimon committed Oct 6, 2019
1 parent 42010dc commit 739c9f0b79335edf8810b15e67d43a5b41ab1cd5
Showing with 22 additions and 42 deletions.
  1. +22 −42 llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -6816,11 +6816,10 @@ static bool getTargetShuffleAndZeroables(SDValue N, SmallVectorImpl<int> &Mask,

// Forward declaration (for getFauxShuffleMask recursive check).
// TODO: Use DemandedElts variant.
static bool resolveTargetShuffleInputs(SDValue Op,
SmallVectorImpl<SDValue> &Inputs,
SmallVectorImpl<int> &Mask,
SelectionDAG &DAG, unsigned Depth,
bool ResolveZero);
static bool getTargetShuffleInputs(SDValue Op, SmallVectorImpl<SDValue> &Inputs,
SmallVectorImpl<int> &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<int, 64> SrcMask0, SrcMask1;
SmallVector<SDValue, 2> 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<int, 64> Mask0, Mask1;
@@ -6975,8 +6974,8 @@ static bool getFauxShuffleMask(SDValue N, const APInt &DemandedElts,
// Handle INSERT_SUBVECTOR(SRC0, SHUFFLE(SRC1)).
SmallVector<int, 64> SubMask;
SmallVector<SDValue, 2> 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<SDValue> &Inputs,
SmallVectorImpl<int> &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<SDValue> &Inputs,
SmallVectorImpl<int> &Mask,
SelectionDAG &DAG, unsigned Depth,
bool ResolveZero = true) {
static bool getTargetShuffleInputs(SDValue Op, SmallVectorImpl<SDValue> &Inputs,
SmallVectorImpl<int> &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
// Extract target shuffle mask and resolve sentinels and inputs.
SmallVector<int, 64> OpMask;
SmallVector<SDValue, 2> 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.
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());
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.
SmallVector<int, 16> ShuffleMask;
SmallVector<SDValue, 2> 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();
// Resolve the target shuffle inputs and mask.
SmallVector<int, 16> Mask;
SmallVector<SDValue, 2> 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.

0 comments on commit 739c9f0

Please sign in to comment.
You can’t perform that action at this time.