[X86][SSE] Move all undef/zero cases before target shuffle combining.

First small step towards fixing PR26667 - we need to ensure that combineX86ShuffleChain only gets called with a valid shuffle input node (a similar issue was found in D17041).

llvm-svn: 261433
This commit is contained in:
Simon Pilgrim 2016-02-20 12:57:32 +00:00
parent bc0122bca9
commit ccf2cce67c
1 changed files with 14 additions and 20 deletions

View File

@ -23525,21 +23525,9 @@ static bool combineX86ShuffleChain(SDValue Op, SDValue Root, ArrayRef<int> Mask,
SDValue Res;
if (Mask.size() == 1) {
int Index = Mask[0];
assert((Index >= 0 || Index == SM_SentinelUndef ||
Index == SM_SentinelZero) &&
"Invalid shuffle index found!");
// We may end up with an accumulated mask of size 1 as a result of
// widening of shuffle operands (see function canWidenShuffleElements).
// If the only shuffle index is equal to SM_SentinelZero then propagate
// a zero vector. Otherwise, the combine shuffle mask is a no-op shuffle
// mask, and therefore the entire chain of shuffles can be folded away.
if (Index == SM_SentinelZero)
DCI.CombineTo(Root.getNode(), getZeroVector(RootVT, Subtarget, DAG, DL));
else
DCI.CombineTo(Root.getNode(), DAG.getBitcast(RootVT, Input),
/*AddTo*/ true);
assert(Mask[0] == 0 && "Invalid shuffle index found!");
DCI.CombineTo(Root.getNode(), DAG.getBitcast(RootVT, Input),
/*AddTo*/ true);
return true;
}
@ -23802,20 +23790,26 @@ static bool combineX86ShufflesRecursively(SDValue Op, SDValue Root,
RootMaskedIdx % OpRatio);
}
// Handle the all undef case early.
// TODO - should we handle zero/undef case as well? Widening the mask
// will lose information on undef elements possibly reducing future
// combine possibilities.
// Handle the all undef/zero cases early.
if (std::all_of(Mask.begin(), Mask.end(),
[](int Idx) { return Idx == SM_SentinelUndef; })) {
DCI.CombineTo(Root.getNode(), DAG.getUNDEF(Root.getValueType()));
return true;
}
if (std::all_of(Mask.begin(), Mask.end(), [](int Idx) { return Idx < 0; })) {
// TODO - should we handle the mixed zero/undef case as well? Just returning
// a zero mask will lose information on undef elements possibly reducing
// future combine possibilities.
DCI.CombineTo(Root.getNode(), getZeroVector(Root.getSimpleValueType(),
Subtarget, DAG, SDLoc(Root)));
return true;
}
assert(Input0 && "Shuffle with no inputs detected");
HasPSHUFB |= (Op.getOpcode() == X86ISD::PSHUFB);
// See if we can recurse into Input0 (if it's a target shuffle).
if (Input0 && Op->isOnlyUserOf(Input0.getNode()) &&
if (Op->isOnlyUserOf(Input0.getNode()) &&
combineX86ShufflesRecursively(Input0, Root, Mask, Depth + 1, HasPSHUFB,
DAG, DCI, Subtarget))
return true;