[llvm] MachineBlockPlacement: Add tolerance to comparisons (PR #67197)
Rahman Lavaee via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 14:19:11 PDT 2023
================
@@ -93,6 +94,28 @@ class BlockFrequency {
return *this;
}
+ /// Returns true if `this` is greater than `other` and the magnitude of the
+ /// difference falls within the topmost `SignificantBits` of `this`.
+ ///
+ /// The formula is related to comparing a "relative change" to a threshold.
+ /// When choosing the threshold as a negative power-of-two things can be
+ /// computed cheaply:
+ /// with A = this->Frequency; B = Other.Frequency; T = SignificantBits
+ /// relative_change(A, B) = abs(A - B) / A
----------------
rlavaee wrote:
I think we can make this reflexive by changing the formular to
`relative_change(A, B) = abs(A - B) / min(A, B)`. This should simplify your code below too.
https://github.com/llvm/llvm-project/pull/67197
More information about the llvm-commits
mailing list