From 675c02b0b9967f286b4d5aa8c3f7d8fc9e7988c4 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 21 Oct 2011 21:13:47 +0000 Subject: [PATCH] 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 --- lib/Analysis/BranchProbabilityInfo.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index 6e8d7e0115d..fc69da9e672 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(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); -- 2.34.1