@@ -1710,9 +1710,9 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1710
1710
return NItem;
1711
1711
};
1712
1712
1713
- SmallVector<InstLane> Start;
1714
- for (unsigned M = 0 ; M < Ty->getNumElements (); ++M)
1715
- Start. push_back ( LookThroughShuffles (&I, M) );
1713
+ SmallVector<InstLane> Start (Ty-> getNumElements ()) ;
1714
+ for (unsigned M = 0 , E = Ty->getNumElements (); M < E ; ++M)
1715
+ Start[M] = LookThroughShuffles (&I, M);
1716
1716
1717
1717
SmallVector<SmallVector<InstLane>> Worklist;
1718
1718
Worklist.push_back (Start);
@@ -1753,10 +1753,12 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1753
1753
return true ;
1754
1754
if (auto *I = dyn_cast<Instruction>(IL.first ); I && !I->hasOneUse ())
1755
1755
return false ;
1756
- return IL.first ->getValueID () == Item[0 ].first ->getValueID () &&
1757
- (!isa<IntrinsicInst>(IL.first ) ||
1758
- cast<IntrinsicInst>(IL.first )->getIntrinsicID () ==
1759
- cast<IntrinsicInst>(Item[0 ].first )->getIntrinsicID ());
1756
+ if (IL.first ->getValueID () != Item[0 ].first ->getValueID ())
1757
+ return false ;
1758
+ auto *II = dyn_cast<IntrinsicInst>(IL.first );
1759
+ return !II ||
1760
+ II->getIntrinsicID () ==
1761
+ cast<IntrinsicInst>(Item[0 ].first )->getIntrinsicID ();
1760
1762
}))
1761
1763
return false ;
1762
1764
@@ -1773,15 +1775,16 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1773
1775
1774
1776
// If we got this far, we know the shuffles are superfluous and can be
1775
1777
// removed. Scan through again and generate the new tree of instructions.
1776
- std::function<Value *(ArrayRef<InstLane>)> generate =
1778
+ std::function<Value *(ArrayRef<InstLane>)> Generate =
1777
1779
[&](ArrayRef<InstLane> Item) -> Value * {
1778
1780
if (IdentityLeafs.contains (Item[0 ].first ) &&
1779
1781
all_of (drop_begin (enumerate(Item)), [&](const auto &E) {
1780
1782
return !E.value ().first || (E.value ().first == Item[0 ].first &&
1781
1783
E.value ().second == (int )E.index ());
1782
1784
})) {
1783
1785
return Item[0 ].first ;
1784
- } else if (SplatLeafs.contains (Item[0 ].first )) {
1786
+ }
1787
+ if (SplatLeafs.contains (Item[0 ].first )) {
1785
1788
if (auto ILI = dyn_cast<Instruction>(Item[0 ].first ))
1786
1789
Builder.SetInsertPoint (*ILI->getInsertionPointAfterDef ());
1787
1790
else if (isa<Argument>(Item[0 ].first ))
@@ -1791,20 +1794,19 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
1791
1794
}
1792
1795
1793
1796
auto *I = cast<Instruction>(Item[0 ].first );
1794
- SmallVector<Value *> Ops;
1795
- unsigned E = I->getNumOperands ();
1796
- for (unsigned Idx = 0 ; Idx < E; Idx++)
1797
- Ops.push_back (generate (GenerateInstLaneVectorFromOperand (Item, Idx)));
1797
+ SmallVector<Value *> Ops (I->getNumOperands ());
1798
+ for (unsigned Idx = 0 , E = I->getNumOperands (); Idx < E; Idx++)
1799
+ Ops[Idx] = Generate (GenerateInstLaneVectorFromOperand (Item, Idx));
1798
1800
Builder.SetInsertPoint (I);
1799
1801
if (auto BI = dyn_cast<BinaryOperator>(I))
1800
1802
return Builder.CreateBinOp ((Instruction::BinaryOps)BI->getOpcode (),
1801
1803
Ops[0 ], Ops[1 ]);
1802
- if ( auto UI = dyn_cast<UnaryOperator >(I))
1803
- return Builder. CreateUnOp ((Instruction::UnaryOps)UI-> getOpcode (), Ops[ 0 ] );
1804
- llvm_unreachable ( " Unhandled instruction in generate " );
1804
+ assert (isa<UnaryInstruction >(I) &&
1805
+ " Unexpected instruction type in Generate " );
1806
+ return Builder. CreateUnOp ((Instruction::UnaryOps)I-> getOpcode (), Ops[ 0 ] );
1805
1807
};
1806
1808
1807
- Value *V = generate (Start);
1809
+ Value *V = Generate (Start);
1808
1810
replaceValue (I, *V);
1809
1811
return true ;
1810
1812
}
0 commit comments