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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139110 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2011-09-04 23:53:04 +00:00
parent fec0c6fa56
commit 26eb870d7e

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;
if (CV->isZero()) {
switch (CI->getPredicate()) {
case CmpInst::ICMP_EQ:
// Equal to zero is not expected to be taken.
// X == 0 -> Unlikely
isProb = false;
break;
case CmpInst::ICMP_NE:
// Not equal to zero is expected.
// 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:
return false;
};
}
} else if (CV->isOne() && CI->getPredicate() == CmpInst::ICMP_SLT) {
// InstCombine canonicalizes X <= 0 into X < 1.
// X <= 0 -> Unlikely
isProb = false;
} else if (CV->isAllOnesValue() && CI->getPredicate() == CmpInst::ICMP_SGT) {
// InstCombine canonicalizes X >= 0 into X > -1.
// X >= 0 -> Likely
isProb = true;
} else {
return false;
}
BasicBlock *Taken = BI->getSuccessor(0);
BasicBlock *NonTaken = BI->getSuccessor(1);