[llvm] Avoid BlockFrequency overflow problems (PR #66280)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 13:31:53 PDT 2023
================
@@ -36,3 +37,10 @@ BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
Freq /= Prob;
return Freq;
}
+
+bool BlockFrequency::mul(uint64_t Factor, BlockFrequency *Result) const {
----------------
kazutakahirata wrote:
This comment might a bit nitpicky, but how about an interface like this?
```
std::optional<BlockFrequency> BlockFrequency::mul(uint64_t Factor) const {
```
This way, the usage might look like:
```
auto Limit = BBFreq.mul(FreqRatioToSkipMerge);
return Limit && PredFreq <= *Limit;
```
Returning a single result is a little more intuitive to me. Plus, I don't have to remember whether `true` indicates an overflow or a successful multiplication.
https://github.com/llvm/llvm-project/pull/66280
More information about the llvm-commits
mailing list