Skip to content

Commit 714d0ea

Browse files
committed
Split out general cost model changes
1 parent 586676b commit 714d0ea

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
@@ -1564,8 +1564,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
15641564
Type *RetTy = ICA.getReturnType();
15651565

15661566
ElementCount RetVF =
1567-
isWideTy(RetTy) ? getWideTypeVF(RetTy) : ElementCount::getFixed(1);
1568-
1567+
(RetTy->isVectorTy() ? cast<VectorType>(RetTy)->getElementCount()
1568+
: ElementCount::getFixed(1));
15691569
const IntrinsicInst *I = ICA.getInst();
15701570
const SmallVectorImpl<const Value *> &Args = ICA.getArgs();
15711571
FastMathFlags FMF = ICA.getFlags();
@@ -1886,13 +1886,10 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18861886
InstructionCost ScalarizationCost = InstructionCost::getInvalid();
18871887
if (RetVF.isVector() && !RetVF.isScalable()) {
18881888
ScalarizationCost = 0;
1889-
if (!RetTy->isVoidTy()) {
1890-
for (Type *VectorTy : getContainedTypes(RetTy)) {
1891-
ScalarizationCost += getScalarizationOverhead(
1892-
cast<VectorType>(VectorTy),
1893-
/*Insert*/ true, /*Extract*/ false, CostKind);
1894-
}
1895-
}
1889+
if (!RetTy->isVoidTy())
1890+
ScalarizationCost += getScalarizationOverhead(
1891+
cast<VectorType>(RetTy),
1892+
/*Insert*/ true, /*Extract*/ false, CostKind);
18961893
ScalarizationCost +=
18971894
getOperandsScalarizationOverhead(Args, ICA.getArgTypes(), CostKind);
18981895
}
@@ -2483,32 +2480,27 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
24832480
// Else, assume that we need to scalarize this intrinsic. For math builtins
24842481
// this will emit a costly libcall, adding call overhead and spills. Make it
24852482
// very expensive.
2486-
if (isWideTy(RetTy)) {
2487-
const SmallVector<Type *, 2> RetVTys = getContainedTypes(RetTy);
2488-
2483+
if (auto *RetVTy = dyn_cast<VectorType>(RetTy)) {
24892484
// Scalable vectors cannot be scalarized, so return Invalid.
2490-
if (any_of(concat<Type *const>(RetVTys, Tys),
2491-
[](Type *Ty) { return isa<ScalableVectorType>(Ty); }))
2485+
if (isa<ScalableVectorType>(RetTy) || any_of(Tys, [](const Type *Ty) {
2486+
return isa<ScalableVectorType>(Ty);
2487+
}))
24922488
return InstructionCost::getInvalid();
24932489

2494-
InstructionCost ScalarizationCost = ScalarizationCostPassed;
2495-
if (!SkipScalarizationCost) {
2496-
ScalarizationCost = 0;
2497-
for (Type *RetVTy : RetVTys) {
2498-
ScalarizationCost += getScalarizationOverhead(
2499-
cast<VectorType>(RetVTy), /*Insert*/ true,
2500-
/*Extract*/ false, CostKind);
2501-
}
2502-
}
2490+
InstructionCost ScalarizationCost =
2491+
SkipScalarizationCost
2492+
? ScalarizationCostPassed
2493+
: getScalarizationOverhead(RetVTy, /*Insert*/ true,
2494+
/*Extract*/ false, CostKind);
25032495

2504-
unsigned ScalarCalls = getWideTypeVF(RetTy).getFixedValue();
2496+
unsigned ScalarCalls = cast<FixedVectorType>(RetVTy)->getNumElements();
25052497
SmallVector<Type *, 4> ScalarTys;
25062498
for (Type *Ty : Tys) {
25072499
if (Ty->isVectorTy())
25082500
Ty = Ty->getScalarType();
25092501
ScalarTys.push_back(Ty);
25102502
}
2511-
IntrinsicCostAttributes Attrs(IID, ToNarrowTy(RetTy), ScalarTys, FMF);
2503+
IntrinsicCostAttributes Attrs(IID, RetTy->getScalarType(), ScalarTys, FMF);
25122504
InstructionCost ScalarCost =
25132505
thisT()->getIntrinsicInstrCost(Attrs, CostKind);
25142506
for (Type *Ty : Tys) {

0 commit comments

Comments
 (0)