Skip to content

Commit cb14533

Browse files
committed
Split out general cost model changes
1 parent c96bbd3 commit cb14533

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
15691569
Type *RetTy = ICA.getReturnType();
15701570

15711571
ElementCount RetVF =
1572-
isWideTy(RetTy) ? getWideTypeVF(RetTy) : ElementCount::getFixed(1);
1573-
1572+
(RetTy->isVectorTy() ? cast<VectorType>(RetTy)->getElementCount()
1573+
: ElementCount::getFixed(1));
15741574
const IntrinsicInst *I = ICA.getInst();
15751575
const SmallVectorImpl<const Value *> &Args = ICA.getArgs();
15761576
FastMathFlags FMF = ICA.getFlags();
@@ -1891,13 +1891,10 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18911891
InstructionCost ScalarizationCost = InstructionCost::getInvalid();
18921892
if (RetVF.isVector() && !RetVF.isScalable()) {
18931893
ScalarizationCost = 0;
1894-
if (!RetTy->isVoidTy()) {
1895-
for (Type *VectorTy : getContainedTypes(RetTy)) {
1896-
ScalarizationCost += getScalarizationOverhead(
1897-
cast<VectorType>(VectorTy),
1898-
/*Insert*/ true, /*Extract*/ false, CostKind);
1899-
}
1900-
}
1894+
if (!RetTy->isVoidTy())
1895+
ScalarizationCost += getScalarizationOverhead(
1896+
cast<VectorType>(RetTy),
1897+
/*Insert*/ true, /*Extract*/ false, CostKind);
19011898
ScalarizationCost +=
19021899
getOperandsScalarizationOverhead(Args, ICA.getArgTypes(), CostKind);
19031900
}
@@ -2488,32 +2485,27 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24882485
// Else, assume that we need to scalarize this intrinsic. For math builtins
24892486
// this will emit a costly libcall, adding call overhead and spills. Make it
24902487
// very expensive.
2491-
if (isWideTy(RetTy)) {
2492-
const SmallVector<Type *, 2> RetVTys = getContainedTypes(RetTy);
2493-
2488+
if (auto *RetVTy = dyn_cast<VectorType>(RetTy)) {
24942489
// Scalable vectors cannot be scalarized, so return Invalid.
2495-
if (any_of(concat<Type *const>(RetVTys, Tys),
2496-
[](Type *Ty) { return isa<ScalableVectorType>(Ty); }))
2490+
if (isa<ScalableVectorType>(RetTy) || any_of(Tys, [](const Type *Ty) {
2491+
return isa<ScalableVectorType>(Ty);
2492+
}))
24972493
return InstructionCost::getInvalid();
24982494

2499-
InstructionCost ScalarizationCost = ScalarizationCostPassed;
2500-
if (!SkipScalarizationCost) {
2501-
ScalarizationCost = 0;
2502-
for (Type *RetVTy : RetVTys) {
2503-
ScalarizationCost += getScalarizationOverhead(
2504-
cast<VectorType>(RetVTy), /*Insert*/ true,
2505-
/*Extract*/ false, CostKind);
2506-
}
2507-
}
2495+
InstructionCost ScalarizationCost =
2496+
SkipScalarizationCost
2497+
? ScalarizationCostPassed
2498+
: getScalarizationOverhead(RetVTy, /*Insert*/ true,
2499+
/*Extract*/ false, CostKind);
25082500

2509-
unsigned ScalarCalls = getWideTypeVF(RetTy).getFixedValue();
2501+
unsigned ScalarCalls = cast<FixedVectorType>(RetVTy)->getNumElements();
25102502
SmallVector<Type *, 4> ScalarTys;
25112503
for (Type *Ty : Tys) {
25122504
if (Ty->isVectorTy())
25132505
Ty = Ty->getScalarType();
25142506
ScalarTys.push_back(Ty);
25152507
}
2516-
IntrinsicCostAttributes Attrs(IID, ToNarrowTy(RetTy), ScalarTys, FMF);
2508+
IntrinsicCostAttributes Attrs(IID, RetTy->getScalarType(), ScalarTys, FMF);
25172509
InstructionCost ScalarCost =
25182510
thisT()->getIntrinsicInstrCost(Attrs, CostKind);
25192511
for (Type *Ty : Tys) {

0 commit comments

Comments
 (0)