summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2017-06-08 09:44:40 +0000
committerJohn Brawn <john.brawn@arm.com>2017-06-08 09:44:40 +0000
commitda4a68a1d2ee735b0be33124c5c34aa91c7e74e2 (patch)
tree6220082625e16a52f410431051c94fbf840c8583 /llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
parent183d83b5b9ecf23c2de4bef9dd572b6e359e0a47 (diff)
downloadbcm5719-llvm-da4a68a1d2ee735b0be33124c5c34aa91c7e74e2.tar.gz
bcm5719-llvm-da4a68a1d2ee735b0be33124c5c34aa91c7e74e2.zip
[BPI] Don't assume that strcmp returning >0 is more likely than <0
The zero heuristic assumes that integers are more likely positive than negative, but this also has the effect of assuming that strcmp return values are more likely positive than negative. Given that for nonzero strcmp return values it's the ordering of arguments that determines the sign of the result there's no reason to assume that's true. Fix this by inspecting the LHS of the compare and using TargetLibraryInfo to decide if it's strcmp-like, and if so only assume that nonzero is more likely than zero i.e. strings are more often different than the same. This causes a slight code generation change in the spec2006 benchmark 403.gcc, but with no noticeable performance impact. The intent of this patch is to allow better optimisation of dhrystone on Cortex-M cpus, but currently it won't as there are also some changes that need to be made to if-conversion. Differential Revision: https://reviews.llvm.org/D33934 llvm-svn: 304970
Diffstat (limited to 'llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp')
-rw-r--r--llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp b/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
index b51c6beb795..e2884d0a456 100644
--- a/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
@@ -16,6 +16,7 @@
#include "llvm/Analysis/LazyBranchProbabilityInfo.h"
#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
using namespace llvm;
@@ -24,6 +25,7 @@ using namespace llvm;
INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
"Lazy Branch Probability Analysis", true, true)
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
"Lazy Branch Probability Analysis", true, true)
@@ -41,6 +43,7 @@ void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfoWrapperPass>();
+ AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.setPreservesAll();
}
@@ -48,16 +51,19 @@ void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
- LBPI = llvm::make_unique<LazyBranchProbabilityInfo>(&F, &LI);
+ TargetLibraryInfo &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
+ LBPI = llvm::make_unique<LazyBranchProbabilityInfo>(&F, &LI, &TLI);
return false;
}
void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
AU.addRequired<LazyBranchProbabilityInfoPass>();
AU.addRequired<LoopInfoWrapperPass>();
+ AU.addRequired<TargetLibraryInfoWrapperPass>();
}
void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
+ INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass);
}
OpenPOWER on IntegriCloud