forked from OSchip/llvm-project
Extend the floating point heuristic to consider NaN checks unlikely.
llvm-svn: 142687
This commit is contained in:
parent
8a8d6466ff
commit
606a50a9f8
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue