Retry: [BPI] Use a safer constructor to calculate branch probabilities
authorVedant Kumar <vsk@apple.com>
Sat, 17 Dec 2016 01:02:08 +0000 (01:02 +0000)
committerVedant Kumar <vsk@apple.com>
Sat, 17 Dec 2016 01:02:08 +0000 (01:02 +0000)
commita4bd1463c8dc04bcd9befd49a667dbfd7fec0f87
treeb0fec2fde39353039e21397a164d4bc08fff6023
parent10005d915e36eced0dab09782bf93d398b45936a
Retry: [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.

Changes since the initial commit:
  - Use explicit casts to ensure that multiplication operands are 64-bit
    ints.

rdar://problem/29368161

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

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