aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2019-06-01 19:40:07 +0000
committerCraig Topper <craig.topper@intel.com>2019-06-01 19:40:07 +0000
commit7cebf0af4076c7d198ef8ef90b79d1ff422a42cd (patch)
tree525e928b02d880c35c6bf0972e4945b0cca81b86 /llvm/lib/Analysis/InlineCost.cpp
parentcd1878d0f957f72e34b378d25742dbc886f079bc (diff)
downloadllvm-7cebf0af4076c7d198ef8ef90b79d1ff422a42cd.zip
llvm-7cebf0af4076c7d198ef8ef90b79d1ff422a42cd.tar.gz
llvm-7cebf0af4076c7d198ef8ef90b79d1ff422a42cd.tar.bz2
[InlineCost] Don't add the soft float function call cost for the fneg idiom, fsub -0.0, %x
Summary: Fneg can be implemented with an xor rather than a function call so we don't need to add the function call overhead. This was pointed out in D62699 Reviewers: efriedma, cameron.mcinally Reviewed By: efriedma Subscribers: javed.absar, eraman, hiraditya, haicheng, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62747 llvm-svn: 362304
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index ced30d6..a332a439 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -35,6 +35,7 @@
#include "llvm/IR/InstVisitor.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
+#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -1095,9 +1096,11 @@ bool CallAnalyzer::visitBinaryOperator(BinaryOperator &I) {
// If the instruction is floating point, and the target says this operation
// is expensive, this may eventually become a library call. Treat the cost
- // as such.
+ // as such. Unless it's fneg which can be implemented with an xor.
+ using namespace llvm::PatternMatch;
if (I.getType()->isFloatingPointTy() &&
- TTI.getFPOpCost(I.getType()) == TargetTransformInfo::TCC_Expensive)
+ TTI.getFPOpCost(I.getType()) == TargetTransformInfo::TCC_Expensive &&
+ !match(&I, m_FNeg(m_Value())))
addCost(InlineConstants::CallPenalty);
return false;