@@ -5919,39 +5919,41 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
5919
5919
// to detect it as a final shuffled/identity match.
5920
5920
if (auto *VU = dyn_cast_or_null<InsertElementInst>(EU.User )) {
5921
5921
if (auto *FTy = dyn_cast<FixedVectorType>(VU->getType ())) {
5922
- unsigned InsertIdx = *getInsertIndex (VU);
5923
- auto *It = find_if (FirstUsers, [VU](Value *V) {
5924
- return areTwoInsertFromSameBuildVector (VU,
5925
- cast<InsertElementInst>(V));
5926
- });
5927
- int VecId = -1 ;
5928
- if (It == FirstUsers.end ()) {
5929
- VF.push_back (FTy->getNumElements ());
5930
- ShuffleMask.emplace_back (VF.back (), UndefMaskElem);
5931
- // Find the insertvector, vectorized in tree, if any.
5932
- Value *Base = VU;
5933
- while (isa<InsertElementInst>(Base)) {
5934
- // Build the mask for the vectorized insertelement instructions.
5935
- if (const TreeEntry *E = getTreeEntry (Base)) {
5936
- VU = cast<InsertElementInst>(Base);
5937
- do {
5938
- int Idx = E->findLaneForValue (Base);
5939
- ShuffleMask.back ()[Idx] = Idx;
5940
- Base = cast<InsertElementInst>(Base)->getOperand (0 );
5941
- } while (E == getTreeEntry (Base));
5942
- break ;
5922
+ Optional<unsigned > InsertIdx = getInsertIndex (VU);
5923
+ if (InsertIdx) {
5924
+ auto *It = find_if (FirstUsers, [VU](Value *V) {
5925
+ return areTwoInsertFromSameBuildVector (VU,
5926
+ cast<InsertElementInst>(V));
5927
+ });
5928
+ int VecId = -1 ;
5929
+ if (It == FirstUsers.end ()) {
5930
+ VF.push_back (FTy->getNumElements ());
5931
+ ShuffleMask.emplace_back (VF.back (), UndefMaskElem);
5932
+ // Find the insertvector, vectorized in tree, if any.
5933
+ Value *Base = VU;
5934
+ while (isa<InsertElementInst>(Base)) {
5935
+ // Build the mask for the vectorized insertelement instructions.
5936
+ if (const TreeEntry *E = getTreeEntry (Base)) {
5937
+ VU = cast<InsertElementInst>(Base);
5938
+ do {
5939
+ int Idx = E->findLaneForValue (Base);
5940
+ ShuffleMask.back ()[Idx] = Idx;
5941
+ Base = cast<InsertElementInst>(Base)->getOperand (0 );
5942
+ } while (E == getTreeEntry (Base));
5943
+ break ;
5944
+ }
5945
+ Base = cast<InsertElementInst>(Base)->getOperand (0 );
5943
5946
}
5944
- Base = cast<InsertElementInst>(Base)->getOperand (0 );
5947
+ FirstUsers.push_back (VU);
5948
+ DemandedElts.push_back (APInt::getZero (VF.back ()));
5949
+ VecId = FirstUsers.size () - 1 ;
5950
+ } else {
5951
+ VecId = std::distance (FirstUsers.begin (), It);
5945
5952
}
5946
- FirstUsers.push_back (VU);
5947
- DemandedElts.push_back (APInt::getZero (VF.back ()));
5948
- VecId = FirstUsers.size () - 1 ;
5949
- } else {
5950
- VecId = std::distance (FirstUsers.begin (), It);
5953
+ ShuffleMask[VecId][*InsertIdx] = EU.Lane ;
5954
+ DemandedElts[VecId].setBit (*InsertIdx);
5955
+ continue ;
5951
5956
}
5952
- ShuffleMask[VecId][InsertIdx] = EU.Lane ;
5953
- DemandedElts[VecId].setBit (InsertIdx);
5954
- continue ;
5955
5957
}
5956
5958
}
5957
5959
0 commit comments