[BPI] Use a safer constructor to calculate branch probabilities
authorVedant Kumar <vsk@apple.com>
Sat, 17 Dec 2016 00:09:51 +0000 (00:09 +0000)
committerVedant Kumar <vsk@apple.com>
Sat, 17 Dec 2016 00:09:51 +0000 (00:09 +0000)
commit9529643e644766d3757981a7e76f7c44927c8029
tree9bbe4ebeda76c40bc1d517e3e47dc4dff3f0a0f4
parente876094038768cacd0fb33ad7355ba3f0023ace8
[BPI] Use a safer constructor to calculate branch probabilities

BPI may trigger signed overflow UB while computing branch probabilities
for cold calls or to unreachables. For example, with our current choice
of weights, we'll crash if there are >= 2^12 branches to an unreachable.

Use a safer BranchProbability constructor which is better at handling
fractions with large denominators.

rdar://problem/29368161

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

llvm-svn: 290016
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/unittests/Analysis/BranchProbabilityInfoTest.cpp [new file with mode: 0644]
llvm/unittests/Analysis/CMakeLists.txt