[X86][SSE] Pull out target shuffle resolve code into helper. NFCI.

Pulled out code that removed unused inputs from a target shuffle mask into a helper function to allow it to be reused in a future commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293175 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Simon Pilgrim 2017-01-26 13:06:02 +00:00
parent c2598d4df6
commit b81877488f

View File

@ -5808,6 +5808,25 @@ static bool getFauxShuffleMask(SDValue N, SmallVectorImpl<int> &Mask,
return false;
}
/// Removes unused shuffle source ops and adjusts the shuffle mask accordingly.
static void resolveTargetShuffleInputsAndMask(SmallVectorImpl<SDValue> &Ops,
SmallVectorImpl<int> &Mask) {
int MaskWidth = Mask.size();
SmallVector<SDValue, 8> UsedOps;
for (int i = 0, e = Ops.size(); i < e; ++i) {
int lo = UsedOps.size() * MaskWidth;
int hi = lo + MaskWidth;
if (any_of(Mask, [lo, hi](int i) { return (lo <= i) && (i < hi); })) {
UsedOps.push_back(Ops[i]);
continue;
}
for (int &M : Mask)
if (lo <= M)
M -= MaskWidth;
}
Ops = UsedOps;
}
/// Calls setTargetShuffleZeroElements 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
@ -27490,20 +27509,8 @@ static bool combineX86ShufflesRecursively(ArrayRef<SDValue> SrcOps,
}
// Remove unused shuffle source ops.
SmallVector<SDValue, 8> UsedOps;
for (int i = 0, e = Ops.size(); i < e; ++i) {
int lo = UsedOps.size() * MaskWidth;
int hi = lo + MaskWidth;
if (any_of(Mask, [lo, hi](int i) { return (lo <= i) && (i < hi); })) {
UsedOps.push_back(Ops[i]);
continue;
}
for (int &M : Mask)
if (lo <= M)
M -= MaskWidth;
}
assert(!UsedOps.empty() && "Shuffle with no inputs detected");
Ops = UsedOps;
resolveTargetShuffleInputsAndMask(Ops, Mask);
assert(!Ops.empty() && "Shuffle with no inputs detected");
HasVariableMask |= isTargetShuffleVariableMask(Op.getOpcode());