@@ -9713,6 +9713,22 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
9713
9713
}
9714
9714
VecCost = std::min(VecCost, IntrinsicCost);
9715
9715
}
9716
+ if (auto *SI = dyn_cast<SelectInst>(VL0)) {
9717
+ auto *CondType =
9718
+ getWidenedType(SI->getCondition()->getType(), VL.size());
9719
+ unsigned CondNumElements = CondType->getNumElements();
9720
+ unsigned VecTyNumElements = getNumElements(VecTy);
9721
+ assert(VecTyNumElements % CondNumElements == 0 &&
9722
+ "Cannot vectorize Instruction::Select");
9723
+ if (CondNumElements != VecTyNumElements) {
9724
+ // When the return type is i1 but the source is fixed vector type, we
9725
+ // need to duplicate the condition value.
9726
+ VecCost += TTI->getShuffleCost(
9727
+ TTI::SK_PermuteSingleSrc, CondType,
9728
+ createReplicatedMask(VecTyNumElements / CondNumElements,
9729
+ CondNumElements));
9730
+ }
9731
+ }
9716
9732
return VecCost + CommonCost;
9717
9733
};
9718
9734
return GetCostDiff(GetScalarCost, GetVectorCost);
@@ -13196,6 +13212,21 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
13196
13212
False = Builder.CreateIntCast(False, VecTy, GetOperandSignedness(2));
13197
13213
}
13198
13214
13215
+ unsigned CondNumElements = getNumElements(Cond->getType());
13216
+ unsigned TrueNumElements = getNumElements(True->getType());
13217
+ assert(TrueNumElements % CondNumElements == 0 &&
13218
+ "Cannot vectorize Instruction::Select");
13219
+ assert(TrueNumElements == getNumElements(False->getType()) &&
13220
+ "Cannot vectorize Instruction::Select");
13221
+ if (CondNumElements != TrueNumElements) {
13222
+ // When the return type is i1 but the source is fixed vector type, we
13223
+ // need to duplicate the condition value.
13224
+ Cond = Builder.CreateShuffleVector(
13225
+ Cond, createReplicatedMask(TrueNumElements / CondNumElements,
13226
+ CondNumElements));
13227
+ }
13228
+ assert(getNumElements(Cond->getType()) == TrueNumElements &&
13229
+ "Cannot vectorize Instruction::Select");
13199
13230
Value *V = Builder.CreateSelect(Cond, True, False);
13200
13231
V = FinalShuffle(V, E, VecTy);
13201
13232
0 commit comments