summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp36
-rw-r--r--llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h5
2 files changed, 35 insertions, 6 deletions
diff --git a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp
index bca856ae9cb..a496a17788d 100644
--- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp
@@ -35,6 +35,10 @@ static cl::opt<bool> EmitLookupTables("hexagon-emit-lookup-tables",
cl::init(true), cl::Hidden,
cl::desc("Control lookup table emission on Hexagon target"));
+// Constant "cost factor" to make floating point operations more expensive
+// in terms of vectorization cost. This isn't the best way, but it should
+// do. Ultimately, the cost should use cycles.
+static const unsigned FloatFactor = 4;
bool HexagonTTIImpl::useHVX() const {
return ST.useHVXOps() && HexagonAutoHVX;
@@ -54,6 +58,14 @@ bool HexagonTTIImpl::isTypeForHVX(Type *VecTy) const {
return Action == TargetLoweringBase::TypeWidenVector;
}
+unsigned HexagonTTIImpl::getTypeNumElements(Type *Ty) const {
+ if (Ty->isVectorTy())
+ return Ty->getVectorNumElements();
+ assert((Ty->isIntegerTy() || Ty->isFloatingPointTy()) &&
+ "Expecting scalar type");
+ return 1;
+}
+
TargetTransformInfo::PopcntSupportKind
HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {
// Return fast hardware support as every input < 64 bits will be promoted
@@ -161,8 +173,8 @@ unsigned HexagonTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
// Non-HVX vectors.
// Add extra cost for floating point types.
- unsigned Cost = VecTy->getElementType()->isFloatingPointTy() ? 4 : 1;
-
+ unsigned Cost = VecTy->getElementType()->isFloatingPointTy() ? FloatFactor
+ : 1;
Alignment = std::min(Alignment, 8u);
unsigned AlignWidth = 8 * std::max(1u, Alignment);
unsigned NumLoads = alignTo(VecWidth, AlignWidth) / AlignWidth;
@@ -202,10 +214,9 @@ unsigned HexagonTTIImpl::getInterleavedMemoryOpCost(unsigned Opcode,
unsigned HexagonTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy, const Instruction *I) {
if (ValTy->isVectorTy()) {
- auto *VecTy = dyn_cast<VectorType>(ValTy);
std::pair<int, MVT> LT = TLI.getTypeLegalizationCost(DL, ValTy);
if (Opcode == Instruction::FCmp)
- return LT.first + 4 * VecTy->getNumElements();
+ return LT.first + FloatFactor * getTypeNumElements(ValTy);
}
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, I);
}
@@ -214,12 +225,25 @@ unsigned HexagonTTIImpl::getArithmeticInstrCost(unsigned Opcode, Type *Ty,
TTI::OperandValueKind Opd1Info, TTI::OperandValueKind Opd2Info,
TTI::OperandValueProperties Opd1PropInfo,
TTI::OperandValueProperties Opd2PropInfo, ArrayRef<const Value*> Args) {
+ if (Ty->isVectorTy()) {
+ std::pair<int, MVT> LT = TLI.getTypeLegalizationCost(DL, Ty);
+ if (LT.second.isFloatingPoint())
+ return LT.first + FloatFactor * getTypeNumElements(Ty);
+ }
return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info,
Opd1PropInfo, Opd2PropInfo, Args);
}
-unsigned HexagonTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
- Type *Src, const Instruction *I) {
+unsigned HexagonTTIImpl::getCastInstrCost(unsigned Opcode, Type *DstTy,
+ Type *SrcTy, const Instruction *I) {
+ if (SrcTy->isFPOrFPVectorTy() || DstTy->isFPOrFPVectorTy()) {
+ unsigned SrcN = SrcTy->isFPOrFPVectorTy() ? getTypeNumElements(SrcTy) : 0;
+ unsigned DstN = DstTy->isFPOrFPVectorTy() ? getTypeNumElements(DstTy) : 0;
+
+ std::pair<int, MVT> SrcLT = TLI.getTypeLegalizationCost(DL, SrcTy);
+ std::pair<int, MVT> DstLT = TLI.getTypeLegalizationCost(DL, DstTy);
+ return std::max(SrcLT.first, DstLT.first) + FloatFactor * (SrcN + DstN);
+ }
return 1;
}
diff --git a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h
index 99de5c017e2..a232f99fc40 100644
--- a/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h
+++ b/llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h
@@ -46,6 +46,11 @@ class HexagonTTIImpl : public BasicTTIImplBase<HexagonTTIImpl> {
bool useHVX() const;
bool isTypeForHVX(Type *VecTy) const;
+ // Returns the number of vector elements of Ty, if Ty is a vector type,
+ // or 1 if Ty is a scalar type. It is incorrect to call this function
+ // with any other type.
+ unsigned getTypeNumElements(Type *Ty) const;
+
public:
explicit HexagonTTIImpl(const HexagonTargetMachine *TM, const Function &F)
: BaseT(TM, F.getParent()->getDataLayout()),
OpenPOWER on IntegriCloud