diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2020-01-13 14:19:45 -0800 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2020-01-13 14:38:58 -0800 |
commit | 7b9f8e17d15d7516b186c0a85de71133b780f939 (patch) | |
tree | 30bf5c3c8409f69d23da171579cfb1572d94cb13 /llvm/lib/Transforms | |
parent | a506f7f9105eec4baac296d21c922457d6f4b52a (diff) | |
download | bcm5719-llvm-7b9f8e17d15d7516b186c0a85de71133b780f939.tar.gz bcm5719-llvm-7b9f8e17d15d7516b186c0a85de71133b780f939.zip |
[PGO][CHR] Guard against 0-to-0 branch weight and avoid division by zero crash.
Summary: This fixes a crash in internal builds under SamplePGO.
Reviewers: davidxl
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72653
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp index 9bd1596852d..d35abb92dd0 100644 --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -625,6 +625,10 @@ static bool checkMDProf(MDNode *MD, BranchProbability &TrueProb, assert(SumWt >= TrueWt && SumWt >= FalseWt && "Overflow calculating branch probabilities."); + // Guard against 0-to-0 branch weights to avoid a division-by-zero crash. + if (SumWt == 0) + return false; + TrueProb = BranchProbability::getBranchProbability(TrueWt, SumWt); FalseProb = BranchProbability::getBranchProbability(FalseWt, SumWt); return true; |