aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2023-09-14 11:11:27 -0700
committerGitHub <noreply@github.com>2023-09-14 11:11:27 -0700
commitb0c8c454238b495ebe4df25a161a120d1707c230 (patch)
treeb985db632cc8d541c3e0dd642df4b828fe935874 /llvm/lib/CodeGen/CodeGenPrepare.cpp
parente80a8b4ab61ef6aba119adf5f64a4644b7e0a44b (diff)
downloadllvm-b0c8c454238b495ebe4df25a161a120d1707c230.zip
llvm-b0c8c454238b495ebe4df25a161a120d1707c230.tar.gz
llvm-b0c8c454238b495ebe4df25a161a120d1707c230.tar.bz2
Avoid BlockFrequency overflow problems (#66280)
Multiplying raw block frequency with an integer carries a high risk of overflow. - Add `BlockFrequency::mul` return an std::optional with the product or `nullopt` to indicate an overflow. - Fix two instances where overflow was likely.
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index f07fc4f..faee623 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -198,7 +198,7 @@ static cl::opt<bool> BBSectionsGuidedSectionPrefix(
"impacted, i.e., their prefixes will be decided by FDO/sampleFDO "
"profiles."));
-static cl::opt<unsigned> FreqRatioToSkipMerge(
+static cl::opt<uint64_t> FreqRatioToSkipMerge(
"cgp-freq-ratio-to-skip-merge", cl::Hidden, cl::init(2),
cl::desc("Skip merging empty blocks if (frequency of empty block) / "
"(frequency of destination block) is greater than this ratio"));
@@ -986,8 +986,8 @@ bool CodeGenPrepare::isMergingEmptyBlockProfitable(BasicBlock *BB,
DestBB == findDestBlockOfMergeableEmptyBlock(SameValueBB))
BBFreq += BFI->getBlockFreq(SameValueBB);
- return PredFreq.getFrequency() <=
- BBFreq.getFrequency() * FreqRatioToSkipMerge;
+ std::optional<BlockFrequency> Limit = BBFreq.mul(FreqRatioToSkipMerge);
+ return !Limit || PredFreq <= *Limit;
}
/// Return true if we can merge BB into DestBB if there is a single