mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 21:32:10 +00:00
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:
parent
fec0c6fa56
commit
26eb870d7e
@ -289,37 +289,42 @@ bool BranchProbabilityAnalysis::calcZeroHeuristics(BasicBlock *BB) {
|
|||||||
|
|
||||||
Value *RHS = CI->getOperand(1);
|
Value *RHS = CI->getOperand(1);
|
||||||
ConstantInt *CV = dyn_cast<ConstantInt>(RHS);
|
ConstantInt *CV = dyn_cast<ConstantInt>(RHS);
|
||||||
if (!CV || !CV->isZero())
|
if (!CV)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool isProb;
|
bool isProb;
|
||||||
switch (CI->getPredicate()) {
|
if (CV->isZero()) {
|
||||||
case CmpInst::ICMP_EQ:
|
switch (CI->getPredicate()) {
|
||||||
// Equal to zero is not expected to be taken.
|
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;
|
isProb = false;
|
||||||
break;
|
} else if (CV->isAllOnesValue() && CI->getPredicate() == CmpInst::ICMP_SGT) {
|
||||||
|
// InstCombine canonicalizes X >= 0 into X > -1.
|
||||||
case CmpInst::ICMP_NE:
|
// X >= 0 -> Likely
|
||||||
// Not equal to zero is expected.
|
|
||||||
isProb = true;
|
isProb = true;
|
||||||
break;
|
} else {
|
||||||
|
|
||||||
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;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
BasicBlock *Taken = BI->getSuccessor(0);
|
BasicBlock *Taken = BI->getSuccessor(0);
|
||||||
BasicBlock *NonTaken = BI->getSuccessor(1);
|
BasicBlock *NonTaken = BI->getSuccessor(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user