@@ -474,7 +474,7 @@ static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
474
474
" Invalid CollectSingleShuffleElements" );
475
475
unsigned NumElts = cast<FixedVectorType>(V->getType ())->getNumElements ();
476
476
477
- if (isa<UndefValue>(V )) {
477
+ if (match (V, m_Undef () )) {
478
478
Mask.assign (NumElts, -1 );
479
479
return true ;
480
480
}
@@ -630,7 +630,7 @@ static ShuffleOps collectShuffleElements(Value *V, SmallVectorImpl<int> &Mask,
630
630
assert (V->getType ()->isVectorTy () && " Invalid shuffle!" );
631
631
unsigned NumElts = cast<FixedVectorType>(V->getType ())->getNumElements ();
632
632
633
- if (isa<UndefValue>(V )) {
633
+ if (match (V, m_Undef () )) {
634
634
Mask.assign (NumElts, -1 );
635
635
return std::make_pair (
636
636
PermittedRHS ? UndefValue::get (PermittedRHS->getType ()) : V, nullptr );
@@ -1102,7 +1102,7 @@ static Instruction *foldInsSequenceIntoSplat(InsertElementInst &InsElt) {
1102
1102
// insert into every element.
1103
1103
// TODO: If the base vector is not undef, it might be better to create a splat
1104
1104
// and then a select-shuffle (blend) with the base vector.
1105
- if (!isa<UndefValue> (FirstIE->getOperand (0 )))
1105
+ if (!match (FirstIE->getOperand (0 ), m_Undef ( )))
1106
1106
if (!ElementPresent.all ())
1107
1107
return nullptr ;
1108
1108
@@ -1164,7 +1164,7 @@ static Instruction *foldInsEltIntoSplat(InsertElementInst &InsElt) {
1164
1164
static Instruction *foldInsEltIntoIdentityShuffle (InsertElementInst &InsElt) {
1165
1165
// Check if the vector operand of this insert is an identity shuffle.
1166
1166
auto *Shuf = dyn_cast<ShuffleVectorInst>(InsElt.getOperand (0 ));
1167
- if (!Shuf || !isa<UndefValue> (Shuf->getOperand (1 )) ||
1167
+ if (!Shuf || !match (Shuf->getOperand (1 ), m_Undef ( )) ||
1168
1168
!(Shuf->isIdentityWithExtract () || Shuf->isIdentityWithPadding ()))
1169
1169
return nullptr ;
1170
1170
@@ -1633,7 +1633,7 @@ static Value *evaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask) {
1633
1633
assert (V->getType ()->isVectorTy () && " can't reorder non-vector elements" );
1634
1634
Type *EltTy = V->getType ()->getScalarType ();
1635
1635
Type *I32Ty = IntegerType::getInt32Ty (V->getContext ());
1636
- if (isa<UndefValue>(V ))
1636
+ if (match (V, m_Undef () ))
1637
1637
return UndefValue::get (FixedVectorType::get (EltTy, Mask.size ()));
1638
1638
1639
1639
if (isa<ConstantAggregateZero>(V))
@@ -1886,7 +1886,7 @@ static Instruction *foldSelectShuffle(ShuffleVectorInst &Shuf,
1886
1886
// Canonicalize to choose from operand 0 first unless operand 1 is undefined.
1887
1887
// Commuting undef to operand 0 conflicts with another canonicalization.
1888
1888
unsigned NumElts = cast<FixedVectorType>(Shuf.getType ())->getNumElements ();
1889
- if (!isa<UndefValue> (Shuf.getOperand (1 )) &&
1889
+ if (!match (Shuf.getOperand (1 ), m_Undef ( )) &&
1890
1890
Shuf.getMaskValue (0 ) >= (int )NumElts) {
1891
1891
// TODO: Can we assert that both operands of a shuffle-select are not undef
1892
1892
// (otherwise, it would have been folded by instsimplify?
@@ -2083,7 +2083,7 @@ static Instruction *narrowVectorSelect(ShuffleVectorInst &Shuf,
2083
2083
// / Try to combine 2 shuffles into 1 shuffle by concatenating a shuffle mask.
2084
2084
static Instruction *foldIdentityExtractShuffle (ShuffleVectorInst &Shuf) {
2085
2085
Value *Op0 = Shuf.getOperand (0 ), *Op1 = Shuf.getOperand (1 );
2086
- if (!Shuf.isIdentityWithExtract () || !isa<UndefValue> (Op1))
2086
+ if (!Shuf.isIdentityWithExtract () || !match (Op1, m_Undef () ))
2087
2087
return nullptr ;
2088
2088
2089
2089
Value *X, *Y;
@@ -2231,10 +2231,10 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
2231
2231
!isPowerOf2_32 (
2232
2232
cast<FixedVectorType>(Shuffle0->getType ())->getNumElements ()) ||
2233
2233
!isPowerOf2_32 (cast<FixedVectorType>(X->getType ())->getNumElements ()) ||
2234
- isa<UndefValue>(X) || isa<UndefValue>(Y ))
2234
+ match (X, m_Undef ()) || match (Y, m_Undef () ))
2235
2235
return nullptr ;
2236
- assert (isa<UndefValue> (Shuffle0->getOperand (1 )) &&
2237
- isa<UndefValue> (Shuffle1->getOperand (1 )) &&
2236
+ assert (match (Shuffle0->getOperand (1 ), m_Undef ( )) &&
2237
+ match (Shuffle1->getOperand (1 ), m_Undef ( )) &&
2238
2238
" Unexpected operand for identity shuffle" );
2239
2239
2240
2240
// This is a shuffle of 2 widening shuffles. We can shuffle the narrow source
@@ -2342,7 +2342,8 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2342
2342
2343
2343
// shuffle x, x, mask --> shuffle x, undef, mask'
2344
2344
if (LHS == RHS) {
2345
- assert (!isa<UndefValue>(RHS) && " Shuffle with 2 undef ops not simplified?" );
2345
+ assert (!match (RHS, m_Undef ()) &&
2346
+ " Shuffle with 2 undef ops not simplified?" );
2346
2347
// Remap any references to RHS to use LHS.
2347
2348
SmallVector<int , 16 > Elts;
2348
2349
for (unsigned i = 0 ; i != VWidth; ++i) {
@@ -2356,7 +2357,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2356
2357
}
2357
2358
2358
2359
// shuffle undef, x, mask --> shuffle x, undef, mask'
2359
- if (isa<UndefValue> (LHS)) {
2360
+ if (match (LHS, m_Undef () )) {
2360
2361
SVI.commute ();
2361
2362
return &SVI;
2362
2363
}
@@ -2391,7 +2392,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2391
2392
if (Instruction *I = foldIdentityPaddedShuffles (SVI))
2392
2393
return I;
2393
2394
2394
- if (isa<UndefValue> (RHS) && canEvaluateShuffled (LHS, Mask)) {
2395
+ if (match (RHS, m_Undef () ) && canEvaluateShuffled (LHS, Mask)) {
2395
2396
Value *V = evaluateInDifferentElementOrder (LHS, Mask);
2396
2397
return replaceInstUsesWith (SVI, V);
2397
2398
}
@@ -2530,10 +2531,10 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2530
2531
ShuffleVectorInst* LHSShuffle = dyn_cast<ShuffleVectorInst>(LHS);
2531
2532
ShuffleVectorInst* RHSShuffle = dyn_cast<ShuffleVectorInst>(RHS);
2532
2533
if (LHSShuffle)
2533
- if (!isa<UndefValue> (LHSShuffle->getOperand (1 )) && !isa<UndefValue> (RHS))
2534
+ if (!match (LHSShuffle->getOperand (1 ), m_Undef ()) && !match (RHS, m_Undef () ))
2534
2535
LHSShuffle = nullptr ;
2535
2536
if (RHSShuffle)
2536
- if (!isa<UndefValue> (RHSShuffle->getOperand (1 )))
2537
+ if (!match (RHSShuffle->getOperand (1 ), m_Undef ( )))
2537
2538
RHSShuffle = nullptr ;
2538
2539
if (!LHSShuffle && !RHSShuffle)
2539
2540
return MadeChange ? &SVI : nullptr ;
@@ -2556,7 +2557,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2556
2557
Value* newRHS = RHS;
2557
2558
if (LHSShuffle) {
2558
2559
// case 1
2559
- if (isa<UndefValue> (RHS)) {
2560
+ if (match (RHS, m_Undef () )) {
2560
2561
newLHS = LHSOp0;
2561
2562
newRHS = LHSOp1;
2562
2563
}
@@ -2614,7 +2615,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2614
2615
//
2615
2616
// If the value selected is an undef value, explicitly specify it
2616
2617
// with a -1 mask value. (case 1)
2617
- if (isa<UndefValue> (RHS))
2618
+ if (match (RHS, m_Undef () ))
2618
2619
eltMask = -1 ;
2619
2620
// If RHS is going to be replaced (case 3 or 4), calculate the
2620
2621
// new mask value for the element.
@@ -2623,8 +2624,8 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
2623
2624
// If the value selected is an undef value, explicitly specify it
2624
2625
// with a -1 mask value.
2625
2626
if (eltMask >= (int )RHSOp0Width) {
2626
- assert (isa<UndefValue> (RHSShuffle->getOperand (1 ))
2627
- && " should have been check above" );
2627
+ assert (match (RHSShuffle->getOperand (1 ), m_Undef ()) &&
2628
+ " should have been check above" );
2628
2629
eltMask = -1 ;
2629
2630
}
2630
2631
} else
0 commit comments