Extend the floating point heuristic to consider NaN checks unlikely.

llvm-svn: 142687
This commit is contained in:
Benjamin Kramer 2011-10-21 21:13:47 +00:00
parent 8a8d6466ff
commit 606a50a9f8
1 changed files with 17 additions and 4 deletions

View File

@ -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);