Index: include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- include/llvm/Analysis/TargetTransformInfo.h +++ include/llvm/Analysis/TargetTransformInfo.h @@ -311,6 +311,10 @@ /// \brief Return true if the hardware has a fast square-root instruction. virtual bool haveFastSqrt(Type *Ty) const; + /// \brief Return the expected cost of supporting the floating point operation + /// of the specified type. + virtual unsigned getFPOpCost(Type *Ty) const; + /// \brief Return the expected cost of materializing for the given integer /// immediate of the specified type. virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) const; Index: lib/Analysis/IPA/InlineCost.cpp =================================================================== --- lib/Analysis/IPA/InlineCost.cpp +++ lib/Analysis/IPA/InlineCost.cpp @@ -907,6 +907,12 @@ if (isa(I) || I->getType()->isVectorTy()) ++NumVectorInstructions; + // If the instruction is floating point, and the target says this operation is + // expensive, this will eventually become a library call. Treat the cost as such. + if (I->getType()->isFloatingPointTy() && + TTI.getFPOpCost(I->getType()) == TargetTransformInfo::TCC_Expensive) + Cost += InlineConstants::CallPenalty; + // If the instruction simplified to a constant, there is no cost to this // instruction. Visit the instructions using our InstVisitor to account for // all of the per-instruction logic. The visit tree returns true if we Index: lib/Analysis/TargetTransformInfo.cpp =================================================================== --- lib/Analysis/TargetTransformInfo.cpp +++ lib/Analysis/TargetTransformInfo.cpp @@ -157,6 +157,10 @@ return PrevTTI->haveFastSqrt(Ty); } +unsigned TargetTransformInfo::getFPOpCost(Type *Ty) const { + return PrevTTI->getFPOpCost(Ty); +} + unsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { return PrevTTI->getIntImmCost(Imm, Ty); } @@ -561,6 +565,12 @@ return false; } + unsigned getFPOpCost(Type *Ty) const override { + // By default, FP instructions are no more expensive since they are + // implemented in HW. Target specific TTI can override this. + return TCC_Basic; + } + unsigned getIntImmCost(const APInt &Imm, Type *Ty) const override { return TCC_Basic; } Index: lib/Target/ARM/ARMSubtarget.h =================================================================== --- lib/Target/ARM/ARMSubtarget.h +++ lib/Target/ARM/ARMSubtarget.h @@ -310,7 +310,12 @@ bool hasCRC() const { return HasCRC; } bool hasVirtualization() const { return HasVirtualization; } bool useNEONForSinglePrecisionFP() const { - return hasNEON() && UseNEONForSinglePrecisionFP; } + return hasNEON() && UseNEONForSinglePrecisionFP; + } + + bool hasFloatingPoint() const { + return HasVFPv2 || HasVFPv3 || HasVFPv4 || HasFPARMv8; + } bool hasDivide() const { return HasHardwareDivide; } bool hasDivideInARMMode() const { return HasHardwareDivideInARM; } Index: lib/Target/ARM/ARMTargetTransformInfo.cpp =================================================================== --- lib/Target/ARM/ARMTargetTransformInfo.cpp +++ lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -111,6 +111,8 @@ return 1; } + unsigned getFPOpCost(Type *Ty) const override; + unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, int Index, Type *SubTp) const override; @@ -449,6 +451,20 @@ return 1; } +unsigned ARMTTI::getFPOpCost(Type *Ty) const { + if (ST->hasFloatingPoint()) { + if (Ty->isFloatTy()) { + return TCC_Basic; + } + + if (Ty->isDoubleTy()) { + return ST->isFPOnlySP() ? TCC_Expensive : TCC_Basic; + } + } + + return TCC_Expensive; +} + unsigned ARMTTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index, Type *SubTp) const { // We only handle costs of reverse and alternate shuffles for now.