@@ -1595,9 +1595,9 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1595
1595
return NItem;
1596
1596
};
1597
1597
1598
- SmallVector<InstLane> Start;
1599
- for (unsigned M = 0 ; M < Ty->getNumElements (); ++M)
1600
- Start. push_back ( LookThroughShuffles (&I, M) );
1598
+ SmallVector<InstLane> Start (Ty-> getNumElements ()) ;
1599
+ for (unsigned M = 0 , E = Ty->getNumElements (); M < E ; ++M)
1600
+ Start[M] = LookThroughShuffles (&I, M);
1601
1601
1602
1602
SmallVector<SmallVector<InstLane>> Worklist;
1603
1603
Worklist.push_back (Start);
@@ -1638,10 +1638,12 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1638
1638
return true ;
1639
1639
if (auto *I = dyn_cast<Instruction>(IL.first ); I && !I->hasOneUse ())
1640
1640
return false ;
1641
- return IL.first ->getValueID () == Item[0 ].first ->getValueID () &&
1642
- (!isa<IntrinsicInst>(IL.first ) ||
1643
- cast<IntrinsicInst>(IL.first )->getIntrinsicID () ==
1644
- cast<IntrinsicInst>(Item[0 ].first )->getIntrinsicID ());
1641
+ if (IL.first ->getValueID () != Item[0 ].first ->getValueID ())
1642
+ return false ;
1643
+ auto *II = dyn_cast<IntrinsicInst>(IL.first );
1644
+ return !II ||
1645
+ II->getIntrinsicID () ==
1646
+ cast<IntrinsicInst>(Item[0 ].first )->getIntrinsicID ();
1645
1647
}))
1646
1648
return false ;
1647
1649
@@ -1658,15 +1660,16 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1658
1660
1659
1661
// If we got this far, we know the shuffles are superfluous and can be
1660
1662
// removed. Scan through again and generate the new tree of instructions.
1661
- std::function<Value *(ArrayRef<InstLane>)> generate =
1663
+ std::function<Value *(ArrayRef<InstLane>)> Generate =
1662
1664
[&](ArrayRef<InstLane> Item) -> Value * {
1663
1665
if (IdentityLeafs.contains (Item[0 ].first ) &&
1664
1666
all_of (drop_begin (enumerate(Item)), [&](const auto &E) {
1665
1667
return !E.value ().first || (E.value ().first == Item[0 ].first &&
1666
1668
E.value ().second == (int )E.index ());
1667
1669
})) {
1668
1670
return Item[0 ].first ;
1669
- } else if (SplatLeafs.contains (Item[0 ].first )) {
1671
+ }
1672
+ if (SplatLeafs.contains (Item[0 ].first )) {
1670
1673
if (auto ILI = dyn_cast<Instruction>(Item[0 ].first ))
1671
1674
Builder.SetInsertPoint (*ILI->getInsertionPointAfterDef ());
1672
1675
else if (isa<Argument>(Item[0 ].first ))
@@ -1676,20 +1679,19 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1676
1679
}
1677
1680
1678
1681
auto *I = cast<Instruction>(Item[0 ].first );
1679
- SmallVector<Value *> Ops;
1680
- unsigned E = I->getNumOperands ();
1681
- for (unsigned Idx = 0 ; Idx < E; Idx++)
1682
- Ops.push_back (generate (GenerateInstLaneVectorFromOperand (Item, Idx)));
1682
+ SmallVector<Value *> Ops (I->getNumOperands ());
1683
+ for (unsigned Idx = 0 , E = I->getNumOperands (); Idx < E; Idx++)
1684
+ Ops[Idx] = Generate (GenerateInstLaneVectorFromOperand (Item, Idx));
1683
1685
Builder.SetInsertPoint (I);
1684
1686
if (auto BI = dyn_cast<BinaryOperator>(I))
1685
1687
return Builder.CreateBinOp ((Instruction::BinaryOps)BI->getOpcode (),
1686
1688
Ops[0 ], Ops[1 ]);
1687
- if ( auto UI = dyn_cast<UnaryOperator >(I))
1688
- return Builder. CreateUnOp ((Instruction::UnaryOps)UI-> getOpcode (), Ops[ 0 ] );
1689
- llvm_unreachable ( " Unhandled instruction in generate " );
1689
+ assert (isa<UnaryInstruction >(I) &&
1690
+ " Unexpected instruction type in Generate " );
1691
+ return Builder. CreateUnOp ((Instruction::UnaryOps)I-> getOpcode (), Ops[ 0 ] );
1690
1692
};
1691
1693
1692
- Value *V = generate (Start);
1694
+ Value *V = Generate (Start);
1693
1695
replaceValue (I, *V);
1694
1696
return true ;
1695
1697
}
0 commit comments