Conversation
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Member
|
@llvm/pr-subscribers-llvm-ir Author: Mircea Trofin (mtrofin) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167593.diff 1 Files Affected:
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h b/llvm/include/llvm/IR/ProfDataUtils.h
index a7bcbf010d1bf..fade7a2dbac2b 100644
--- a/llvm/include/llvm/IR/ProfDataUtils.h
+++ b/llvm/include/llvm/IR/ProfDataUtils.h
@@ -18,6 +18,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Compiler.h"
+#include <type_traits>
namespace llvm {
struct MDProfLabels {
@@ -216,9 +217,12 @@ LLVM_ABI void scaleProfData(Instruction &I, uint64_t S, uint64_t T);
/// branch weights B1 and B2, respectively. In both B1 and B2, the first
/// position (index 0) is for the 'true' branch, and the second position (index
/// 1) is for the 'false' branch.
+template <typename T1, typename T2,
+ typename = typename std::enable_if<std::is_arithmetic_v<T1> &&
+ std::is_arithmetic_v<T2>>>
inline SmallVector<uint64_t, 2>
-getDisjunctionWeights(const SmallVector<uint32_t, 2> &B1,
- const SmallVector<uint32_t, 2> &B2) {
+getDisjunctionWeights(const SmallVector<T1, 2> &B1,
+ const SmallVector<T2, 2> &B2) {
// For the first conditional branch, the probability the "true" case is taken
// is p(b1) = B1[0] / (B1[0] + B1[1]). The "false" case's probability is
// p(not b1) = B1[1] / (B1[0] + B1[1]).
@@ -235,8 +239,8 @@ getDisjunctionWeights(const SmallVector<uint32_t, 2> &B1,
// the product of sums, the subtracted one cancels out).
assert(B1.size() == 2);
assert(B2.size() == 2);
- auto FalseWeight = B1[1] * B2[1];
- auto TrueWeight = B1[0] * B2[0] + B1[0] * B2[1] + B1[1] * B2[0];
+ uint64_t FalseWeight = B1[1] * B2[1];
+ uint64_t TrueWeight = B1[0] * (B2[0] + B2[1]) + B1[1] * B2[0];
return {TrueWeight, FalseWeight};
}
} // namespace llvm
|
| assert(B2.size() == 2); | ||
| auto FalseWeight = B1[1] * B2[1]; | ||
| auto TrueWeight = B1[0] * B2[0] + B1[0] * B2[1] + B1[1] * B2[0]; | ||
| uint64_t FalseWeight = B1[1] * B2[1]; |
Contributor
There was a problem hiding this comment.
What's the motivation for changing this? Previously it would default to the integer type, but now it's fixed.
Shouldn't be a big issue for uint64_t specifically, but maybe a good idea to add a static assert that the bit width of T1/T2 is less than or equal to 64?
Member
Author
There was a problem hiding this comment.
to avoid overflow. I missed the fact I should have declared it uint64_t explicitly the first time around.
added static asserts.
49b9823 to
967055b
Compare
boomanaiden154
approved these changes
Nov 12, 2025
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

No description provided.