[llvm-commits] [llvm] r142687 - /llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
Benjamin Kramer
benny.kra at googlemail.com
Fri Oct 21 14:13:48 PDT 2011
Author: d0k
Date: Fri Oct 21 16:13:47 2011
New Revision: 142687
URL: http://llvm.org/viewvc/llvm-project?rev=142687&view=rev
Log:
Extend the floating point heuristic to consider NaN checks unlikely.
Modified:
llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=142687&r1=142686&r2=142687&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Fri Oct 21 16:13:47 2011
@@ -391,15 +391,28 @@
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);
More information about the llvm-commits
mailing list