@@ -9063,25 +9063,35 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
9063
9063
cast<CmpInst>(E->getAltOp())->getPredicate(), CostKind,
9064
9064
E->getAltOp());
9065
9065
} else {
9066
- Type *Src0SclTy = E->getMainOp()->getOperand(0)->getType();
9067
- Type *Src1SclTy = E->getAltOp()->getOperand(0)->getType();
9068
- auto *Src0Ty = FixedVectorType::get(Src0SclTy, VL.size());
9069
- auto *Src1Ty = FixedVectorType::get(Src1SclTy, VL.size());
9070
- if (It != MinBWs.end()) {
9071
- if (!MinBWs.contains(getOperandEntry(E, 0)))
9072
- VecCost =
9073
- TTIRef.getCastInstrCost(Instruction::Trunc, VecTy, Src0Ty,
9074
- TTI::CastContextHint::None, CostKind);
9075
- LLVM_DEBUG({
9076
- dbgs() << "SLP: alternate extension, which should be truncated.\n";
9077
- E->dump();
9078
- });
9079
- return VecCost;
9066
+ Type *SrcSclTy = E->getMainOp()->getOperand(0)->getType();
9067
+ auto *SrcTy = FixedVectorType::get(SrcSclTy, VL.size());
9068
+ if (SrcSclTy->isIntegerTy() && ScalarTy->isIntegerTy()) {
9069
+ auto SrcIt = MinBWs.find(getOperandEntry(E, 0));
9070
+ unsigned BWSz = DL->getTypeSizeInBits(ScalarTy);
9071
+ unsigned SrcBWSz =
9072
+ DL->getTypeSizeInBits(E->getMainOp()->getOperand(0)->getType());
9073
+ if (SrcIt != MinBWs.end()) {
9074
+ SrcBWSz = SrcIt->second.first;
9075
+ SrcSclTy = IntegerType::get(SrcSclTy->getContext(), SrcBWSz);
9076
+ SrcTy = FixedVectorType::get(SrcSclTy, VL.size());
9077
+ }
9078
+ if (BWSz <= SrcBWSz) {
9079
+ if (BWSz < SrcBWSz)
9080
+ VecCost =
9081
+ TTIRef.getCastInstrCost(Instruction::Trunc, VecTy, SrcTy,
9082
+ TTI::CastContextHint::None, CostKind);
9083
+ LLVM_DEBUG({
9084
+ dbgs()
9085
+ << "SLP: alternate extension, which should be truncated.\n";
9086
+ E->dump();
9087
+ });
9088
+ return VecCost;
9089
+ }
9080
9090
}
9081
- VecCost = TTIRef.getCastInstrCost(E->getOpcode(), VecTy, Src0Ty ,
9091
+ VecCost = TTIRef.getCastInstrCost(E->getOpcode(), VecTy, SrcTy ,
9082
9092
TTI::CastContextHint::None, CostKind);
9083
9093
VecCost +=
9084
- TTIRef.getCastInstrCost(E->getAltOpcode(), VecTy, Src1Ty ,
9094
+ TTIRef.getCastInstrCost(E->getAltOpcode(), VecTy, SrcTy ,
9085
9095
TTI::CastContextHint::None, CostKind);
9086
9096
}
9087
9097
SmallVector<int> Mask;
@@ -12591,15 +12601,20 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
12591
12601
CmpInst::Predicate AltPred = AltCI->getPredicate();
12592
12602
V1 = Builder.CreateCmp(AltPred, LHS, RHS);
12593
12603
} else {
12594
- if (It != MinBWs.end()) {
12595
- if (!MinBWs.contains(getOperandEntry(E, 0)))
12596
- LHS = Builder.CreateIntCast(LHS, VecTy, It->second.first);
12597
- assert(LHS->getType() == VecTy && "Expected same type as operand.");
12598
- if (auto *I = dyn_cast<Instruction>(LHS))
12599
- LHS = propagateMetadata(I, E->Scalars);
12600
- E->VectorizedValue = LHS;
12601
- ++NumVectorInstructions;
12602
- return LHS;
12604
+ if (LHS->getType()->isIntOrIntVectorTy() && ScalarTy->isIntegerTy()) {
12605
+ unsigned SrcBWSz = DL->getTypeSizeInBits(
12606
+ cast<VectorType>(LHS->getType())->getElementType());
12607
+ unsigned BWSz = DL->getTypeSizeInBits(ScalarTy);
12608
+ if (BWSz <= SrcBWSz) {
12609
+ if (BWSz < SrcBWSz)
12610
+ LHS = Builder.CreateIntCast(LHS, VecTy, It->second.first);
12611
+ assert(LHS->getType() == VecTy && "Expected same type as operand.");
12612
+ if (auto *I = dyn_cast<Instruction>(LHS))
12613
+ LHS = propagateMetadata(I, E->Scalars);
12614
+ E->VectorizedValue = LHS;
12615
+ ++NumVectorInstructions;
12616
+ return LHS;
12617
+ }
12603
12618
}
12604
12619
V0 = Builder.CreateCast(
12605
12620
static_cast<Instruction::CastOps>(E->getOpcode()), LHS, VecTy);
0 commit comments