@@ -9713,6 +9713,23 @@ 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 &&
9722
+ VecTyNumElements % CondNumElements == 0 &&
9723
+ "Cannot vectorize Instruction::Select");
9724
+ if (CondNumElements != VecTyNumElements) {
9725
+ // When the return type is i1 but the source is fixed vector type, we
9726
+ // need to duplicate the condition value.
9727
+ VecCost += TTI->getShuffleCost(
9728
+ TTI::SK_PermuteSingleSrc, CondType,
9729
+ createReplicatedMask(VecTyNumElements / CondNumElements,
9730
+ CondNumElements));
9731
+ }
9732
+ }
9716
9733
return VecCost + CommonCost;
9717
9734
};
9718
9735
return GetCostDiff(GetScalarCost, GetVectorCost);
@@ -13196,6 +13213,22 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
13196
13213
False = Builder.CreateIntCast(False, VecTy, GetOperandSignedness(2));
13197
13214
}
13198
13215
13216
+ unsigned CondNumElements = getNumElements(Cond->getType());
13217
+ unsigned TrueNumElements = getNumElements(True->getType());
13218
+ assert(TrueNumElements >= CondNumElements &&
13219
+ TrueNumElements % CondNumElements == 0 &&
13220
+ "Cannot vectorize Instruction::Select");
13221
+ assert(TrueNumElements == getNumElements(False->getType()) &&
13222
+ "Cannot vectorize Instruction::Select");
13223
+ if (CondNumElements != TrueNumElements) {
13224
+ // When the return type is i1 but the source is fixed vector type, we
13225
+ // need to duplicate the condition value.
13226
+ Cond = Builder.CreateShuffleVector(
13227
+ Cond, createReplicatedMask(TrueNumElements / CondNumElements,
13228
+ CondNumElements));
13229
+ }
13230
+ assert(getNumElements(Cond->getType()) == TrueNumElements &&
13231
+ "Cannot vectorize Instruction::Select");
13199
13232
Value *V = Builder.CreateSelect(Cond, True, False);
13200
13233
V = FinalShuffle(V, E, VecTy);
13201
13234
0 commit comments