@@ -1710,9 +1710,9 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17101710 return NItem;
17111711 };
17121712
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);
17161716
17171717 SmallVector<SmallVector<InstLane>> Worklist;
17181718 Worklist.push_back (Start);
@@ -1753,10 +1753,12 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17531753 return true ;
17541754 if (auto *I = dyn_cast<Instruction>(IL.first ); I && !I->hasOneUse ())
17551755 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 ();
17601762 }))
17611763 return false ;
17621764
@@ -1773,15 +1775,16 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17731775
17741776 // If we got this far, we know the shuffles are superfluous and can be
17751777 // 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 =
17771779 [&](ArrayRef<InstLane> Item) -> Value * {
17781780 if (IdentityLeafs.contains (Item[0 ].first ) &&
17791781 all_of (drop_begin (enumerate(Item)), [&](const auto &E) {
17801782 return !E.value ().first || (E.value ().first == Item[0 ].first &&
17811783 E.value ().second == (int )E.index ());
17821784 })) {
17831785 return Item[0 ].first ;
1784- } else if (SplatLeafs.contains (Item[0 ].first )) {
1786+ }
1787+ if (SplatLeafs.contains (Item[0 ].first )) {
17851788 if (auto ILI = dyn_cast<Instruction>(Item[0 ].first ))
17861789 Builder.SetInsertPoint (*ILI->getInsertionPointAfterDef ());
17871790 else if (isa<Argument>(Item[0 ].first ))
@@ -1791,20 +1794,19 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17911794 }
17921795
17931796 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));
17981800 Builder.SetInsertPoint (I);
17991801 if (auto BI = dyn_cast<BinaryOperator>(I))
18001802 return Builder.CreateBinOp ((Instruction::BinaryOps)BI->getOpcode (),
18011803 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 ] );
18051807 };
18061808
1807- Value *V = generate (Start);
1809+ Value *V = Generate (Start);
18081810 replaceValue (I, *V);
18091811 return true ;
18101812}
0 commit comments