-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[PGO] Fix branch weights overflow #96541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-pgo Author: Dmitry Nechitaev (Nechda) ChangesThis MR fixes the issue described in #88361 Full diff: https://github.com/llvm/llvm-project/pull/96541.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 61078c4194b81..8e6f982373a6a 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1711,9 +1711,9 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
// Use uint32_t saturated arithmetic to adjust the incoming weights,
// if needed. Sample counts in profiles are 64-bit unsigned values,
// but internally branch weights are expressed as 32-bit values.
- if (Weight > std::numeric_limits<uint32_t>::max()) {
+ if (Weight >= std::numeric_limits<uint32_t>::max()) {
LLVM_DEBUG(dbgs() << " (saturated due to uint32_t overflow)\n");
- Weight = std::numeric_limits<uint32_t>::max();
+ Weight = std::numeric_limits<uint32_t>::max() - 1;
}
if (!SampleProfileUseProfi) {
// Weight is added by one to avoid propagation errors introduced by
|
@llvm/pr-subscribers-llvm-transforms Author: Dmitry Nechitaev (Nechda) ChangesThis MR fixes the issue described in #88361 Full diff: https://github.com/llvm/llvm-project/pull/96541.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 61078c4194b81..8e6f982373a6a 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1711,9 +1711,9 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
// Use uint32_t saturated arithmetic to adjust the incoming weights,
// if needed. Sample counts in profiles are 64-bit unsigned values,
// but internally branch weights are expressed as 32-bit values.
- if (Weight > std::numeric_limits<uint32_t>::max()) {
+ if (Weight >= std::numeric_limits<uint32_t>::max()) {
LLVM_DEBUG(dbgs() << " (saturated due to uint32_t overflow)\n");
- Weight = std::numeric_limits<uint32_t>::max();
+ Weight = std::numeric_limits<uint32_t>::max() - 1;
}
if (!SampleProfileUseProfi) {
// Weight is added by one to avoid propagation errors introduced by
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to add a test case?
This was already fixed in #90217 I believe and this change doesn't add anything on top of it, or am I missing something? |
Hmm, seems you are right, I'll close this MR & Issue. |
This MR fixes the issue described in #88361