static Instruction *shrinkSplatShuffle(TruncInst &Trunc,
InstCombiner::BuilderTy &Builder) {
auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand(0));
- if (Shuf && Shuf->hasOneUse() && isa<UndefValue>(Shuf->getOperand(1)) &&
+ if (Shuf && Shuf->hasOneUse() && match(Shuf->getOperand(1), m_Undef()) &&
is_splat(Shuf->getShuffleMask()) &&
Shuf->getType() == Shuf->getOperand(0)->getType()) {
// trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Undef, SplatMask
Value *ScalarOp = InsElt->getOperand(1);
Value *Index = InsElt->getOperand(2);
- if (isa<UndefValue>(VecOp)) {
+ if (match(VecOp, m_Undef())) {
// trunc (inselt undef, X, Index) --> inselt undef, (trunc X), Index
// fptrunc (inselt undef, X, Index) --> inselt undef, (fptrunc X), Index
UndefValue *NarrowUndef = UndefValue::get(DestTy);
ShufElts.getKnownMinValue() % 2 == 0 && Shuf->hasOneUse() &&
Shuf->isReverse()) {
assert(ShufOp0->getType() == SrcTy && "Unexpected shuffle mask");
- assert(isa<UndefValue>(ShufOp1) && "Unexpected shuffle op");
+ assert(match(ShufOp1, m_Undef()) && "Unexpected shuffle op");
Function *Bswap =
Intrinsic::getDeclaration(CI.getModule(), Intrinsic::bswap, DestTy);
Value *ScalarX = Builder.CreateBitCast(ShufOp0, DestTy);
"Invalid CollectSingleShuffleElements");
unsigned NumElts = cast<FixedVectorType>(V->getType())->getNumElements();
- if (isa<UndefValue>(V)) {
+ if (match(V, m_Undef())) {
Mask.assign(NumElts, -1);
return true;
}
assert(V->getType()->isVectorTy() && "Invalid shuffle!");
unsigned NumElts = cast<FixedVectorType>(V->getType())->getNumElements();
- if (isa<UndefValue>(V)) {
+ if (match(V, m_Undef())) {
Mask.assign(NumElts, -1);
return std::make_pair(
PermittedRHS ? UndefValue::get(PermittedRHS->getType()) : V, nullptr);
// insert into every element.
// TODO: If the base vector is not undef, it might be better to create a splat
// and then a select-shuffle (blend) with the base vector.
- if (!isa<UndefValue>(FirstIE->getOperand(0)))
+ if (!match(FirstIE->getOperand(0), m_Undef()))
if (!ElementPresent.all())
return nullptr;
static Instruction *foldInsEltIntoIdentityShuffle(InsertElementInst &InsElt) {
// Check if the vector operand of this insert is an identity shuffle.
auto *Shuf = dyn_cast<ShuffleVectorInst>(InsElt.getOperand(0));
- if (!Shuf || !isa<UndefValue>(Shuf->getOperand(1)) ||
+ if (!Shuf || !match(Shuf->getOperand(1), m_Undef()) ||
!(Shuf->isIdentityWithExtract() || Shuf->isIdentityWithPadding()))
return nullptr;
assert(V->getType()->isVectorTy() && "can't reorder non-vector elements");
Type *EltTy = V->getType()->getScalarType();
Type *I32Ty = IntegerType::getInt32Ty(V->getContext());
- if (isa<UndefValue>(V))
+ if (match(V, m_Undef()))
return UndefValue::get(FixedVectorType::get(EltTy, Mask.size()));
if (isa<ConstantAggregateZero>(V))
// Canonicalize to choose from operand 0 first unless operand 1 is undefined.
// Commuting undef to operand 0 conflicts with another canonicalization.
unsigned NumElts = cast<FixedVectorType>(Shuf.getType())->getNumElements();
- if (!isa<UndefValue>(Shuf.getOperand(1)) &&
+ if (!match(Shuf.getOperand(1), m_Undef()) &&
Shuf.getMaskValue(0) >= (int)NumElts) {
// TODO: Can we assert that both operands of a shuffle-select are not undef
// (otherwise, it would have been folded by instsimplify?
/// Try to combine 2 shuffles into 1 shuffle by concatenating a shuffle mask.
static Instruction *foldIdentityExtractShuffle(ShuffleVectorInst &Shuf) {
Value *Op0 = Shuf.getOperand(0), *Op1 = Shuf.getOperand(1);
- if (!Shuf.isIdentityWithExtract() || !isa<UndefValue>(Op1))
+ if (!Shuf.isIdentityWithExtract() || !match(Op1, m_Undef()))
return nullptr;
Value *X, *Y;
!isPowerOf2_32(
cast<FixedVectorType>(Shuffle0->getType())->getNumElements()) ||
!isPowerOf2_32(cast<FixedVectorType>(X->getType())->getNumElements()) ||
- isa<UndefValue>(X) || isa<UndefValue>(Y))
+ match(X, m_Undef()) || match(Y, m_Undef()))
return nullptr;
- assert(isa<UndefValue>(Shuffle0->getOperand(1)) &&
- isa<UndefValue>(Shuffle1->getOperand(1)) &&
+ assert(match(Shuffle0->getOperand(1), m_Undef()) &&
+ match(Shuffle1->getOperand(1), m_Undef()) &&
"Unexpected operand for identity shuffle");
// This is a shuffle of 2 widening shuffles. We can shuffle the narrow source
// shuffle x, x, mask --> shuffle x, undef, mask'
if (LHS == RHS) {
- assert(!isa<UndefValue>(RHS) && "Shuffle with 2 undef ops not simplified?");
+ assert(!match(RHS, m_Undef()) &&
+ "Shuffle with 2 undef ops not simplified?");
// Remap any references to RHS to use LHS.
SmallVector<int, 16> Elts;
for (unsigned i = 0; i != VWidth; ++i) {
}
// shuffle undef, x, mask --> shuffle x, undef, mask'
- if (isa<UndefValue>(LHS)) {
+ if (match(LHS, m_Undef())) {
SVI.commute();
return &SVI;
}
if (Instruction *I = foldIdentityPaddedShuffles(SVI))
return I;
- if (isa<UndefValue>(RHS) && canEvaluateShuffled(LHS, Mask)) {
+ if (match(RHS, m_Undef()) && canEvaluateShuffled(LHS, Mask)) {
Value *V = evaluateInDifferentElementOrder(LHS, Mask);
return replaceInstUsesWith(SVI, V);
}
ShuffleVectorInst* LHSShuffle = dyn_cast<ShuffleVectorInst>(LHS);
ShuffleVectorInst* RHSShuffle = dyn_cast<ShuffleVectorInst>(RHS);
if (LHSShuffle)
- if (!isa<UndefValue>(LHSShuffle->getOperand(1)) && !isa<UndefValue>(RHS))
+ if (!match(LHSShuffle->getOperand(1), m_Undef()) && !match(RHS, m_Undef()))
LHSShuffle = nullptr;
if (RHSShuffle)
- if (!isa<UndefValue>(RHSShuffle->getOperand(1)))
+ if (!match(RHSShuffle->getOperand(1), m_Undef()))
RHSShuffle = nullptr;
if (!LHSShuffle && !RHSShuffle)
return MadeChange ? &SVI : nullptr;
Value* newRHS = RHS;
if (LHSShuffle) {
// case 1
- if (isa<UndefValue>(RHS)) {
+ if (match(RHS, m_Undef())) {
newLHS = LHSOp0;
newRHS = LHSOp1;
}
//
// If the value selected is an undef value, explicitly specify it
// with a -1 mask value. (case 1)
- if (isa<UndefValue>(RHS))
+ if (match(RHS, m_Undef()))
eltMask = -1;
// If RHS is going to be replaced (case 3 or 4), calculate the
// new mask value for the element.
// If the value selected is an undef value, explicitly specify it
// with a -1 mask value.
if (eltMask >= (int)RHSOp0Width) {
- assert(isa<UndefValue>(RHSShuffle->getOperand(1))
- && "should have been check above");
+ assert(match(RHSShuffle->getOperand(1), m_Undef()) &&
+ "should have been check above");
eltMask = -1;
}
} else