From 6a2c71af0bc5beebf954e1970233fbeb3be0bf1c Mon Sep 17 00:00:00 2001 From: Cong Hou Date: Tue, 22 Dec 2015 23:45:55 +0000 Subject: [BPI] Fix two potential divide-by-zero operations that are introduced in r256263. llvm-svn: 256303 --- llvm/lib/Transforms/Scalar/JumpThreading.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp') diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index d30c336..5c16b2c 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1647,14 +1647,19 @@ void JumpThreading::UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB, uint64_t MaxBBSuccFreq = *std::max_element(BBSuccFreq.begin(), BBSuccFreq.end()); - SmallVector BBSuccProbs; - for (uint64_t Freq : BBSuccFreq) - BBSuccProbs.push_back( - BranchProbability::getBranchProbability(Freq, MaxBBSuccFreq)); - // Normalize edge probabilities so that they sum up to one. - BranchProbability::normalizeProbabilities(BBSuccProbs.begin(), - BBSuccProbs.end()); + SmallVector BBSuccProbs; + if (MaxBBSuccFreq == 0) + BBSuccProbs.assign(BBSuccFreq.size(), + {1, static_cast(BBSuccFreq.size())}); + else { + for (uint64_t Freq : BBSuccFreq) + BBSuccProbs.push_back( + BranchProbability::getBranchProbability(Freq, MaxBBSuccFreq)); + // Normalize edge probabilities so that they sum up to one. + BranchProbability::normalizeProbabilities(BBSuccProbs.begin(), + BBSuccProbs.end()); + } // Update edge probabilities in BPI. for (int I = 0, E = BBSuccProbs.size(); I < E; I++) -- cgit v1.1