[BPI] Detect branches in loops that make themselves not taken
authorJohn Brawn <john.brawn@arm.com>
Fri, 23 Feb 2018 17:17:31 +0000 (17:17 +0000)
committerJohn Brawn <john.brawn@arm.com>
Fri, 23 Feb 2018 17:17:31 +0000 (17:17 +0000)
commit29bbed3613c49f441d8cc6cf01db4b257ad88837
tree059343bae7d39422736139101aee217541ce3f00
parent6b9c7a9c83fed425ac6f71d9378c749f3c496045
[BPI] Detect branches in loops that make themselves not taken

If we have a loop like this:
 int n = 0;
 while (...) {
  if (++n >= MAX) {
    n = 0;
  }
 }
then the body of the 'if' statement will only be executed once every MAX
iterations. Detect this by looking for branches in loops where taking the branch
makes the branch condition evaluate to 'not taken' in the next iteration of the
loop, and reduce the probability of such branches.

This slightly improves EEMBC benchmarks on cortex-m4/cortex-m33 due to making
better choices in if-conversion, but has no effect on any other cpu/benchmark
that I could detect.

Differential Revision: https://reviews.llvm.org/D35804

llvm-svn: 325925
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/test/Analysis/BranchProbabilityInfo/loop.ll