diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-10-21 21:13:47 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-10-21 21:13:47 +0000 |
commit | 675c02b0b9967f286b4d5aa8c3f7d8fc9e7988c4 (patch) | |
tree | 83e82d1d8795ca98bc1d74a5dfeb3d92dfd33b48 | |
parent | 7102b703bfacd7e8d1b3ef967d0e1b10b56714b7 (diff) | |
download | external_llvm-675c02b0b9967f286b4d5aa8c3f7d8fc9e7988c4.zip external_llvm-675c02b0b9967f286b4d5aa8c3f7d8fc9e7988c4.tar.gz external_llvm-675c02b0b9967f286b4d5aa8c3f7d8fc9e7988c4.tar.bz2 |
Extend the floating point heuristic to consider NaN checks unlikely.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142687 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/BranchProbabilityInfo.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index 6e8d7e0..fc69da9 100644 --- a/lib/Analysis/BranchProbabilityInfo.cpp +++ b/lib/Analysis/BranchProbabilityInfo.cpp @@ -391,15 +391,28 @@ bool BranchProbabilityAnalysis::calcFloatingPointHeuristics(BasicBlock *BB) { Value *Cond = BI->getCondition(); FCmpInst *FCmp = dyn_cast<FCmpInst>(Cond); - if (!FCmp || !FCmp->isEquality()) + if (!FCmp) return false; + bool isProb; + if (FCmp->isEquality()) { + // f1 == f2 -> Unlikely + // f1 != f2 -> Likely + isProb = !FCmp->isTrueWhenEqual(); + } else if (FCmp->getPredicate() == FCmpInst::FCMP_ORD) { + // !isnan -> Likely + isProb = true; + } else if (FCmp->getPredicate() == FCmpInst::FCMP_UNO) { + // isnan -> Unlikely + isProb = false; + } else { + return false; + } + BasicBlock *Taken = BI->getSuccessor(0); BasicBlock *NonTaken = BI->getSuccessor(1); - // f1 == f2 -> Unlikely - // f1 != f2 -> Likely - if (FCmp->isTrueWhenEqual()) + if (!isProb) std::swap(Taken, NonTaken); BP->setEdgeWeight(BB, Taken, FPH_TAKEN_WEIGHT); |