[PATCH] D86017: [BPI] Improve static heuristics for integer comparisons with CST
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 02:24:04 PDT 2020
xbolva00 updated this revision to Diff 285945.
xbolva00 added a comment.
New logic
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86017/new/
https://reviews.llvm.org/D86017
Files:
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/test/Analysis/BranchProbabilityInfo/integer_heuristics.ll
Index: llvm/test/Analysis/BranchProbabilityInfo/integer_heuristics.ll
===================================================================
--- llvm/test/Analysis/BranchProbabilityInfo/integer_heuristics.ll
+++ llvm/test/Analysis/BranchProbabilityInfo/integer_heuristics.ll
@@ -142,8 +142,8 @@
entry:
%c = icmp ult i32 %x, %y
br i1 %c, label %then, label %else
-; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50%
-; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50%
+; CHECK: edge entry -> then probability is 0x40000000 / 0x80000000 = 50.00%
+; CHECK: edge entry -> else probability is 0x40000000 / 0x80000000 = 50.00%
then:
br label %else
; CHECK: edge then -> else probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
Index: llvm/lib/Analysis/BranchProbabilityInfo.cpp
===================================================================
--- llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -880,13 +880,17 @@
Value *RHS = CI->getOperand(1);
ConstantInt *CV = GetConstantInt(RHS);
if (!CV) {
- // X == Y -> Unlikely
- // Otherwise -> Likely
- if (CI->isTrueWhenEqual())
- std::swap(TakenProb, UntakenProb);
- setEdgeProbability(
- BB, SmallVector<BranchProbability, 2>({TakenProb, UntakenProb}));
- return true;
+ if (CI->isEquality()) {
+ // X == Y -> Unlikely
+ // X != Y -> Likely
+ if (CI->isTrueWhenEqual())
+ std::swap(TakenProb, UntakenProb);
+ setEdgeProbability(
+ BB, SmallVector<BranchProbability, 2>({TakenProb, UntakenProb}));
+ return true;
+ } else {
+ return false;
+ }
}
// If the LHS is the result of AND'ing a value with a single bit bitmask,
@@ -928,16 +932,12 @@
default:
return false;
}
+ } else if (CI->isEquality()) {
+ // X == C -> Unlikely
+ // X != C -> Likely
+ isProb = !CI->isTrueWhenEqual();
} else 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;
@@ -958,14 +958,6 @@
return false;
} else if (CV->isMinusOne()) {
switch (CI->getPredicate()) {
- case CmpInst::ICMP_EQ:
- // X == -1 -> Unlikely
- isProb = false;
- break;
- case CmpInst::ICMP_NE:
- // X != -1 -> Likely
- isProb = true;
- break;
case CmpInst::ICMP_SGT:
// InstCombine canonicalizes X >= 0 into X > -1.
// X >= 0 -> Likely
@@ -975,18 +967,7 @@
return false;
}
} else {
- // X == C -> Unlikely
- // X != C -> Likely
- switch (CI->getPredicate()) {
- case CmpInst::ICMP_EQ:
- isProb = false;
- break;
- case CmpInst::ICMP_NE:
- isProb = true;
- break;
- default:
- return false;
- }
+ return false;
}
if (!isProb)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86017.285945.patch
Type: text/x-patch
Size: 3081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200817/95fbf820/attachment.bin>
More information about the llvm-commits
mailing list