@@ -5682,39 +5682,41 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
5682
5682
// to detect it as a final shuffled/identity match.
5683
5683
if (auto *VU = dyn_cast_or_null<InsertElementInst>(EU.User )) {
5684
5684
if (auto *FTy = dyn_cast<FixedVectorType>(VU->getType ())) {
5685
- unsigned InsertIdx = *getInsertIndex (VU);
5686
- auto *It = find_if (FirstUsers, [VU](Value *V) {
5687
- return areTwoInsertFromSameBuildVector (VU,
5688
- cast<InsertElementInst>(V));
5689
- });
5690
- int VecId = -1 ;
5691
- if (It == FirstUsers.end ()) {
5692
- VF.push_back (FTy->getNumElements ());
5693
- ShuffleMask.emplace_back (VF.back (), UndefMaskElem);
5694
- // Find the insertvector, vectorized in tree, if any.
5695
- Value *Base = VU;
5696
- while (isa<InsertElementInst>(Base)) {
5697
- // Build the mask for the vectorized insertelement instructions.
5698
- if (const TreeEntry *E = getTreeEntry (Base)) {
5699
- VU = cast<InsertElementInst>(Base);
5700
- do {
5701
- int Idx = E->findLaneForValue (Base);
5702
- ShuffleMask.back ()[Idx] = Idx;
5703
- Base = cast<InsertElementInst>(Base)->getOperand (0 );
5704
- } while (E == getTreeEntry (Base));
5705
- break ;
5685
+ Optional<unsigned > InsertIdx = getInsertIndex (VU);
5686
+ if (InsertIdx) {
5687
+ auto *It = find_if (FirstUsers, [VU](Value *V) {
5688
+ return areTwoInsertFromSameBuildVector (VU,
5689
+ cast<InsertElementInst>(V));
5690
+ });
5691
+ int VecId = -1 ;
5692
+ if (It == FirstUsers.end ()) {
5693
+ VF.push_back (FTy->getNumElements ());
5694
+ ShuffleMask.emplace_back (VF.back (), UndefMaskElem);
5695
+ // Find the insertvector, vectorized in tree, if any.
5696
+ Value *Base = VU;
5697
+ while (isa<InsertElementInst>(Base)) {
5698
+ // Build the mask for the vectorized insertelement instructions.
5699
+ if (const TreeEntry *E = getTreeEntry (Base)) {
5700
+ VU = cast<InsertElementInst>(Base);
5701
+ do {
5702
+ int Idx = E->findLaneForValue (Base);
5703
+ ShuffleMask.back ()[Idx] = Idx;
5704
+ Base = cast<InsertElementInst>(Base)->getOperand (0 );
5705
+ } while (E == getTreeEntry (Base));
5706
+ break ;
5707
+ }
5708
+ Base = cast<InsertElementInst>(Base)->getOperand (0 );
5706
5709
}
5707
- Base = cast<InsertElementInst>(Base)->getOperand (0 );
5710
+ FirstUsers.push_back (VU);
5711
+ DemandedElts.push_back (APInt::getZero (VF.back ()));
5712
+ VecId = FirstUsers.size () - 1 ;
5713
+ } else {
5714
+ VecId = std::distance (FirstUsers.begin (), It);
5708
5715
}
5709
- FirstUsers.push_back (VU);
5710
- DemandedElts.push_back (APInt::getZero (VF.back ()));
5711
- VecId = FirstUsers.size () - 1 ;
5712
- } else {
5713
- VecId = std::distance (FirstUsers.begin (), It);
5716
+ ShuffleMask[VecId][*InsertIdx] = EU.Lane ;
5717
+ DemandedElts[VecId].setBit (*InsertIdx);
5718
+ continue ;
5714
5719
}
5715
- ShuffleMask[VecId][InsertIdx] = EU.Lane ;
5716
- DemandedElts[VecId].setBit (InsertIdx);
5717
- continue ;
5718
5720
}
5719
5721
}
5720
5722
0 commit comments