Skip to content

Commit ce534dc

Browse files
Addressing reviewers
1 parent d11c1c4 commit ce534dc

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

llvm/include/llvm/Analysis/VectorUtils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/MapVector.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/Analysis/LoopAccessAnalysis.h"
19+
#include "llvm/Analysis/TargetTransformInfo.h"
1920
#include "llvm/IR/VFABIDemangler.h"
2021
#include "llvm/Support/CheckedArithmetic.h"
2122

@@ -119,7 +120,6 @@ template <typename InstTy> class InterleaveGroup;
119120
class IRBuilderBase;
120121
class Loop;
121122
class ScalarEvolution;
122-
class TargetTransformInfo;
123123
class Type;
124124
class Value;
125125

@@ -410,6 +410,14 @@ bool maskIsAllOneOrUndef(Value *Mask);
410410
/// for each lane which may be active.
411411
APInt possiblyDemandedEltsInMask(Value *Mask);
412412

413+
/// Returns the cost of a call when a target has a vector library function for
414+
/// the given \p VecTy, otherwise an invalid cost.
415+
InstructionCost getVecLibCallCost(const Instruction *I,
416+
const TargetTransformInfo *TTI,
417+
const TargetLibraryInfo *TLI,
418+
VectorType *VecTy,
419+
TargetTransformInfo::TargetCostKind CostKind);
420+
413421
/// The group of interleaved loads/stores sharing the same stride and
414422
/// close to each other.
415423
///

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Analysis/LoopIterator.h"
1919
#include "llvm/Analysis/ScalarEvolution.h"
2020
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
21+
#include "llvm/Analysis/TargetLibraryInfo.h"
2122
#include "llvm/Analysis/TargetTransformInfo.h"
2223
#include "llvm/Analysis/ValueTracking.h"
2324
#include "llvm/IR/Constants.h"
@@ -1031,6 +1032,22 @@ APInt llvm::possiblyDemandedEltsInMask(Value *Mask) {
10311032
return DemandedElts;
10321033
}
10331034

1035+
InstructionCost
1036+
llvm::getVecLibCallCost(const Instruction *I, const TargetTransformInfo *TTI,
1037+
const TargetLibraryInfo *TLI, VectorType *VecTy,
1038+
TargetTransformInfo::TargetCostKind CostKind) {
1039+
SmallVector<Type *, 4> OpTypes;
1040+
for (auto &Op : I->operands())
1041+
OpTypes.push_back(Op->getType());
1042+
1043+
LibFunc Func;
1044+
if (TLI->getLibFunc(I->getOpcode(), I->getType(), Func) &&
1045+
TLI->isFunctionVectorizable(TLI->getName(Func), VecTy->getElementCount()))
1046+
return TTI->getCallInstrCost(nullptr, VecTy, OpTypes, CostKind);
1047+
1048+
return InstructionCost::getInvalid();
1049+
}
1050+
10341051
bool InterleavedAccessInfo::isStrided(int Stride) {
10351052
unsigned Factor = std::abs(Stride);
10361053
return Factor >= 2 && Factor <= MaxInterleaveGroupFactor;

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8619,17 +8619,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
86198619
auto VecCost = TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind,
86208620
Op1Info, Op2Info);
86218621
// Some targets can replace frem with vector library calls.
8622-
if (ShuffleOrOp == Instruction::FRem) {
8623-
LibFunc Func;
8624-
if (TLI->getLibFunc(ShuffleOrOp, ScalarTy, Func) &&
8625-
TLI->isFunctionVectorizable(TLI->getName(Func),
8626-
VecTy->getElementCount())) {
8627-
auto VecCallCost = TTI->getCallInstrCost(
8628-
nullptr, VecTy, {ScalarTy, ScalarTy}, CostKind);
8629-
VecCost = std::min(VecCost, VecCallCost);
8630-
}
8631-
}
8632-
return VecCost + CommonCost;
8622+
InstructionCost VecCallCost =
8623+
getVecLibCallCost(VL0, TTI, TLI, VecTy, CostKind);
8624+
return std::min(VecInstrCost, VecCallCost) + CommonCost;
86338625
};
86348626
return GetCostDiff(GetScalarCost, GetVectorCost);
86358627
}

0 commit comments

Comments
 (0)