Skip to content

Commit b245a49

Browse files
committed
[SLP] Allow targets to add cost for nonstandard conditions
Change-Id: I0de224f42d77bb25fcbae5ccd6ad863560d0bb1d
1 parent 69ecffc commit b245a49

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,11 @@ class TargetTransformInfo {
891891
bool Insert, bool Extract,
892892
TTI::TargetCostKind CostKind) const;
893893

894+
/// Whether or not there is any target-specific condition that imposes an
895+
/// overhead for scalarization
896+
bool hasScalarizationOverhead(ArrayRef<Value *> VL,
897+
std::pair<bool, bool> &ScalarizationKind) const;
898+
894899
/// Estimate the overhead of scalarizing an instructions unique
895900
/// non-constant operands. The (potentially vector) types to use for each of
896901
/// argument are passes via Tys.
@@ -1921,6 +1926,10 @@ class TargetTransformInfo::Concept {
19211926
getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
19221927
ArrayRef<Type *> Tys,
19231928
TargetCostKind CostKind) = 0;
1929+
1930+
virtual bool
1931+
hasScalarizationOverhead(ArrayRef<Value *> VL,
1932+
std::pair<bool, bool> &ScalarizationKind) = 0;
19241933
virtual bool supportsEfficientVectorElementLoadStore() = 0;
19251934
virtual bool supportsTailCalls() = 0;
19261935
virtual bool supportsTailCallFor(const CallBase *CB) = 0;
@@ -2456,6 +2465,13 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
24562465
return Impl.getScalarizationOverhead(Ty, DemandedElts, Insert, Extract,
24572466
CostKind);
24582467
}
2468+
2469+
bool
2470+
hasScalarizationOverhead(ArrayRef<Value *> VL,
2471+
std::pair<bool, bool> &ScalarizationKind) override {
2472+
return Impl.hasScalarizationOverhead(VL, ScalarizationKind);
2473+
}
2474+
24592475
InstructionCost
24602476
getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
24612477
ArrayRef<Type *> Tys,

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ class TargetTransformInfoImplBase {
371371
return 0;
372372
}
373373

374+
bool hasScalarizationOverhead(ArrayRef<Value *> VL,
375+
std::pair<bool, bool> &ScalarizationKind) {
376+
return false;
377+
}
378+
374379
InstructionCost
375380
getOperandsScalarizationOverhead(ArrayRef<const Value *> Args,
376381
ArrayRef<Type *> Tys,

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
807807
CostKind);
808808
}
809809

810+
bool hasScalarizationOverhead(ArrayRef<Value *> VL,
811+
std::pair<bool, bool> &ScalarizationKind) {
812+
return false;
813+
}
814+
810815
/// Estimate the overhead of scalarizing an instructions unique
811816
/// non-constant operands. The (potentially vector) types to use for each of
812817
/// argument are passes via Tys.

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,11 @@ InstructionCost TargetTransformInfo::getScalarizationOverhead(
594594
CostKind);
595595
}
596596

597+
bool TargetTransformInfo::hasScalarizationOverhead(
598+
ArrayRef<Value *> VL, std::pair<bool, bool> &ScalarizeKind) const {
599+
return TTIImpl->hasScalarizationOverhead(VLm ScalarizeKind);
600+
}
601+
597602
InstructionCost TargetTransformInfo::getOperandsScalarizationOverhead(
598603
ArrayRef<const Value *> Args, ArrayRef<Type *> Tys,
599604
TTI::TargetCostKind CostKind) const {

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9084,6 +9084,14 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
90849084
E, ScalarTy, *TTI, VectorizedVals, *this, CheckedExtracts);
90859085
}
90869086
InstructionCost CommonCost = 0;
9087+
std::pair<bool, bool> ScalarizationKind(false, false);
9088+
if (TTI->hasScalarizationOverhead(VL, ScalarizationKind)) {
9089+
APInt DemandedElts = APInt::getAllOnes(VL.size());
9090+
CommonCost -= TTI->getScalarizationOverhead(
9091+
VecTy, DemandedElts,
9092+
/*Insert*/ ScalarizationKind.first,
9093+
/*Extract*/ ScalarizationKind.second, CostKind);
9094+
}
90879095
SmallVector<int> Mask;
90889096
bool IsReverseOrder = isReverseOrder(E->ReorderIndices);
90899097
if (!E->ReorderIndices.empty() &&

0 commit comments

Comments
 (0)