Use canonical forms for the branch probability zero heutistic.

- Drop support for X >u 0, it's equivalent to X != 0 and should be canonicalized into the latter.
- Add X < 1 -> unlikely, which is what instcombine canonicalizes X <= 0 into.
- Add X > -1 -> likely, which is what instcombine canonicalizes X >= 0 into.

llvm-svn: 139110
This commit is contained in:
Benjamin Kramer 2011-09-04 23:53:04 +00:00
parent 3f9211d322
commit 0ca1ad0783
1 changed files with 30 additions and 25 deletions

View File

@ -289,37 +289,42 @@ bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {
Value *RHS = CI->getOperand(1);
ConstantInt *CV = dyn_cast<ConstantInt>(RHS);
if (!CV || !CV->isZero())
if (!CV)
return false;
bool isProb;
switch (CI->getPredicate()) {
case CmpInst::ICMP_EQ:
// Equal to zero is not expected to be taken.
if (CV->isZero()) {
switch (CI->getPredicate()) {
case CmpInst::ICMP_EQ:
// X == 0 -> Unlikely
isProb = false;
break;
case CmpInst::ICMP_NE:
// X != 0 -> Likely
isProb = true;
break;
case CmpInst::ICMP_SLT:
// X < 0 -> Unlikely
isProb = false;
break;
case CmpInst::ICMP_SGT:
// X > 0 -> Likely
isProb = true;
break;
default:
return false;
}
} else if (CV->isOne() && CI->getPredicate() == CmpInst::ICMP_SLT) {
// InstCombine canonicalizes X <= 0 into X < 1.
// X <= 0 -> Unlikely
isProb = false;
break;
case CmpInst::ICMP_NE:
// Not equal to zero is expected.
} else if (CV->isAllOnesValue() && CI->getPredicate() == CmpInst::ICMP_SGT) {
// InstCombine canonicalizes X >= 0 into X > -1.
// X >= 0 -> Likely
isProb = true;
break;
case CmpInst::ICMP_SLT:
// Less or equal to zero is not expected.
// X < 0 -> Unlikely
isProb = false;
break;
case CmpInst::ICMP_UGT:
case CmpInst::ICMP_SGT:
// Greater or equal to zero is expected.
// X > 0 -> Likely
isProb = true;
break;
default:
} else {
return false;
};
}
BasicBlock *Taken = BI->getSuccessor(0);
BasicBlock *NonTaken = BI->getSuccessor(1);