@@ -1595,9 +1595,9 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
15951595 return NItem;
15961596 };
15971597
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);
16011601
16021602 SmallVector<SmallVector<InstLane>> Worklist;
16031603 Worklist.push_back (Start);
@@ -1638,10 +1638,12 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
16381638 return true ;
16391639 if (auto *I = dyn_cast<Instruction>(IL.first ); I && !I->hasOneUse ())
16401640 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 ();
16451647 }))
16461648 return false ;
16471649
@@ -1658,15 +1660,16 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
16581660
16591661 // If we got this far, we know the shuffles are superfluous and can be
16601662 // 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 =
16621664 [&](ArrayRef<InstLane> Item) -> Value * {
16631665 if (IdentityLeafs.contains (Item[0 ].first ) &&
16641666 all_of (drop_begin (enumerate(Item)), [&](const auto &E) {
16651667 return !E.value ().first || (E.value ().first == Item[0 ].first &&
16661668 E.value ().second == (int )E.index ());
16671669 })) {
16681670 return Item[0 ].first ;
1669- } else if (SplatLeafs.contains (Item[0 ].first )) {
1671+ }
1672+ if (SplatLeafs.contains (Item[0 ].first )) {
16701673 if (auto ILI = dyn_cast<Instruction>(Item[0 ].first ))
16711674 Builder.SetInsertPoint (*ILI->getInsertionPointAfterDef ());
16721675 else if (isa<Argument>(Item[0 ].first ))
@@ -1676,20 +1679,19 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
16761679 }
16771680
16781681 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));
16831685 Builder.SetInsertPoint (I);
16841686 if (auto BI = dyn_cast<BinaryOperator>(I))
16851687 return Builder.CreateBinOp ((Instruction::BinaryOps)BI->getOpcode (),
16861688 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 ] );
16901692 };
16911693
1692- Value *V = generate (Start);
1694+ Value *V = Generate (Start);
16931695 replaceValue (I, *V);
16941696 return true ;
16951697}
0 commit comments