-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[Float2Int] Fix pessimization in the MinBW calculation. #86051
Conversation
The MinBW was being calculated using the significant bits of the upper and lower bounds. The upper bound is 1 past the last value in the range so I don't think it should be included. Instead get the min and max signed values from the range and use the significant bits of those. I'm still not sure if the +1 is needed after the std::max. I haven't investigated if its possible to add a test for this. We only look at whether the MinBW is > 32 right now. So the ranges need to be carefully crafted to see a difference.
@llvm/pr-subscribers-llvm-transforms Author: Craig Topper (topperc) ChangesThe MinBW was being calculated using the significant bits of the upper and lower bounds. The upper bound is 1 past the last value in the range so I don't think it should be included. Instead get the min and max signed values from the range and use the significant bits of those. I'm still not sure if the +1 is needed after the std::max. I haven't investigated if its possible to add a test for this. We only look at whether the MinBW is > 32 right now. So the ranges need to be carefully crafted to see a difference. CC: @AtariDreams Full diff: https://github.com/llvm/llvm-project/pull/86051.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp
index ccca8bcc1a56ac..47042d96b46571 100644
--- a/llvm/lib/Transforms/Scalar/Float2Int.cpp
+++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp
@@ -359,8 +359,8 @@ bool Float2IntPass::validateAndTransform() {
// The number of bits required is the maximum of the upper and
// lower limits, plus one so it can be signed.
- unsigned MinBW = std::max(R.getLower().getSignificantBits(),
- R.getUpper().getSignificantBits()) +
+ unsigned MinBW = std::max(R.getSignedMin().getSignificantBits(),
+ R.getSignedMax().getSignificantBits()) +
1;
LLVM_DEBUG(dbgs() << "F2I: MinBitwidth=" << MinBW << ", R: " << R << "\n");
|
unsigned MinBW = std::max(R.getLower().getSignificantBits(), | ||
R.getUpper().getSignificantBits()) + | ||
unsigned MinBW = std::max(R.getSignedMin().getSignificantBits(), | ||
R.getSignedMax().getSignificantBits()) + |
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.
Use R.getMinSignedBits()
instead?
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.
LGTM -- but should probably only land after your ConstantRange fix. I think they might be partially canceling each other out right now...
The MinBW was being calculated using the significant bits of the upper and lower bounds. The upper bound is 1 past the last value in the range so I don't think it should be included. Instead use ConstantRange::getMinSignedBits. I'm still not sure if the +1 is needed after the getMinSignedBits call.
The MinBW was being calculated using the significant bits of the upper and lower bounds. The upper bound is 1 past the last value in the range so I don't think it should be included. Instead get the min and max signed values from the range and use the significant bits of those.
I'm still not sure if the +1 is needed after the std::max.
I haven't investigated if its possible to add a test for this. We only look at whether the MinBW is > 32 right now. So the ranges need to be carefully crafted to see a difference.
CC: @AtariDreams