summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-04-14 15:20:37 +0000
committerDaniel Jasper <djasper@google.com>2015-04-14 15:20:37 +0000
commit8229ebb9263fb1a773ea48c632bc1e04ce6e1299 (patch)
treec71d7be567534f99f2eba546ebabc18ed2522b18 /llvm
parent2f16bc10957acf1e29306bc764cb4886d38024a9 (diff)
downloadbcm5719-llvm-8229ebb9263fb1a773ea48c632bc1e04ce6e1299.tar.gz
bcm5719-llvm-8229ebb9263fb1a773ea48c632bc1e04ce6e1299.zip
The code that originally made me discover this is:
if ((a & 0x1) == 0x1) { .. } In this case we don't actually have any branch probability information and should not assume to have any. LLVM transforms this into: %and = and i32 %a, 1 %tobool = icmp eq i32 %and, 0 So, in this case, the result of a bitwise and is compared against 0, but nevertheless, we should not assume to have probability information. llvm-svn: 234898
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Analysis/BranchProbabilityInfo.cpp8
-rw-r--r--llvm/test/Analysis/BranchProbabilityInfo/basic.ll28
-rw-r--r--llvm/test/CodeGen/AArch64/arm64-call-tailcalls.ll2
-rw-r--r--llvm/test/CodeGen/Mips/octeon.ll4
4 files changed, 39 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 14800f4a28b..d7cee3afaf5 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -379,6 +379,14 @@ bool BranchProbabilityInfo::calcZeroHeuristics(BasicBlock *BB) {
if (!CV)
return false;
+ // If the LHS is the result of AND'ing a value with a single bit bitmask,
+ // we don't have information about probabilities.
+ if (Instruction *LHS = dyn_cast<Instruction>(CI->getOperand(0)))
+ if (LHS->getOpcode() == Instruction::And)
+ if (ConstantInt *AndRHS = dyn_cast<ConstantInt>(LHS->getOperand(1)))
+ if (AndRHS->getUniqueInteger().isPowerOf2())
+ return false;
+
bool isProb;
if (CV->isZero()) {
switch (CI->getPredicate()) {
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
index 0f669119bfe..2c9c1561868 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/basic.ll
@@ -212,3 +212,31 @@ exit:
ret i32 %result
}
+define i32 @zero3(i32 %i, i32 %a, i32 %b) {
+; CHECK: Printing analysis {{.*}} for function 'zero3'
+entry:
+; AND'ing with a single bit bitmask essentially leads to a bool comparison,
+; meaning we don't have probability information.
+ %and = and i32 %i, 2
+ %tobool = icmp eq i32 %and, 0
+ br i1 %tobool, label %then, label %else
+; CHECK: edge entry -> then probability is 16 / 32
+; CHECK: edge entry -> else probability is 16 / 32
+
+then:
+; AND'ing with other bitmask might be something else, so we still assume the
+; usual probabilities.
+ %and2 = and i32 %i, 5
+ %tobool2 = icmp eq i32 %and2, 0
+ br i1 %tobool2, label %else, label %exit
+; CHECK: edge then -> else probability is 12 / 32
+; CHECK: edge then -> exit probability is 20 / 32
+
+else:
+ br label %exit
+
+exit:
+ %result = phi i32 [ %a, %then ], [ %b, %else ]
+ ret i32 %result
+}
+
diff --git a/llvm/test/CodeGen/AArch64/arm64-call-tailcalls.ll b/llvm/test/CodeGen/AArch64/arm64-call-tailcalls.ll
index 71d932787ce..6621db25da5 100644
--- a/llvm/test/CodeGen/AArch64/arm64-call-tailcalls.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-call-tailcalls.ll
@@ -53,9 +53,9 @@ bb: ; preds = %entry
define i32 @t8(i32 %x) nounwind ssp {
; CHECK-LABEL: t8:
+; CHECK: b _c
; CHECK: b _a
; CHECK: b _b
-; CHECK: b _c
%and = and i32 %x, 1
%tobool = icmp eq i32 %and, 0
br i1 %tobool, label %if.end, label %if.then
diff --git a/llvm/test/CodeGen/Mips/octeon.ll b/llvm/test/CodeGen/Mips/octeon.ll
index 97e12e721f5..499ce3c1ddb 100644
--- a/llvm/test/CodeGen/Mips/octeon.ll
+++ b/llvm/test/CodeGen/Mips/octeon.ll
@@ -93,7 +93,7 @@ entry:
; ALL-LABEL: bbit0:
; OCTEON: bbit0 $4, 3, $[[BB0:BB[0-9_]+]]
; MIPS64: andi $[[T0:[0-9]+]], $4, 8
-; MIPS64: beqz $[[T0]], $[[BB0:BB[0-9_]+]]
+; MIPS64: bnez $[[T0]], $[[BB0:BB[0-9_]+]]
%bit = and i64 %a, 8
%res = icmp eq i64 %bit, 0
br i1 %res, label %endif, label %if
@@ -111,7 +111,7 @@ entry:
; MIPS64: daddiu $[[T0:[0-9]+]], $zero, 1
; MIPS64: dsll $[[T1:[0-9]+]], $[[T0]], 35
; MIPS64: and $[[T2:[0-9]+]], $4, $[[T1]]
-; MIPS64: beqz $[[T2]], $[[BB0:BB[0-9_]+]]
+; MIPS64: bnez $[[T2]], $[[BB0:BB[0-9_]+]]
%bit = and i64 %a, 34359738368
%res = icmp eq i64 %bit, 0
br i1 %res, label %endif, label %if
OpenPOWER on IntegriCloud