Update the branch weight metadata in JumpThreading pass.
authorCong Hou <congh@google.com>
Wed, 14 Oct 2015 23:14:17 +0000 (23:14 +0000)
committerCong Hou <congh@google.com>
Wed, 14 Oct 2015 23:14:17 +0000 (23:14 +0000)
commita99158bbd8d2f9c4822f2e61173807e2039f61b3
tree276746dd990c1ea74f000abe8869554f59a7f022
parent73e2613bcae85f944720761d6a770cf55908ce3c
Update the branch weight metadata in JumpThreading pass.

Currently in JumpThreading pass, the branch weight metadata is not updated after CFG modification. Consider the jump threading on PredBB, BB, and SuccBB. After jump threading, the weight on BB->SuccBB should be adjusted as some of it is contributed by the edge PredBB->BB, which doesn't exist anymore. This patch tries to update the edge weight in metadata on BB->SuccBB by scaling it by 1 - Freq(PredBB->BB) / Freq(BB->SuccBB).

This is the third attempt to submit this patch, while the first two led to failures in some FDO tests. After investigation, it is the edge weight normalization that caused those failures. In this patch the edge weight normalization is fixed so that there is no zero weight in the output and the sum of all weights can fit in 32-bit integer. Several unit tests are added.

Differential revision: http://reviews.llvm.org/D10979

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250345 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Analysis/BlockFrequencyInfo.h
include/llvm/Analysis/BlockFrequencyInfoImpl.h
include/llvm/Support/BranchProbability.h
lib/Analysis/BlockFrequencyInfo.cpp
lib/Analysis/BlockFrequencyInfoImpl.cpp
lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/update-edge-weight.ll [new file with mode: 0644]
unittests/Support/BranchProbabilityTest.cpp