-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Ensure KnownBits passed when calculating from range md has right size #132985
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
|
@llvm/pr-subscribers-llvm-selectiondag @llvm/pr-subscribers-llvm-analysis Author: None (LU-JOHN) ChangesKnownBits passed to computeKnownBitsFromRangeMetadata must have the same bit width as the range metadata bit width. Otherwise the calculated results will be incorrect. Full diff: https://github.com/llvm/llvm-project/pull/132985.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 880781742fae0..4e3d5d8f12cbc 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -433,6 +433,8 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
// The first CommonPrefixBits of all values in Range are equal.
unsigned CommonPrefixBits =
(Range.getUnsignedMax() ^ Range.getUnsignedMin()).countl_zero();
+ // BitWidth must equal the Ranges BitWidth for the correct number of high bits to be set.
+ assert(BitWidth == Lower->getBitWidth() );
APInt Mask = APInt::getHighBitsSet(BitWidth, CommonPrefixBits);
APInt UnsignedMax = Range.getUnsignedMax().zextOrTrunc(BitWidth);
Known.One &= UnsignedMax & Mask;
|
…ect size Signed-off-by: John Lu <[email protected]>
Signed-off-by: John Lu <[email protected]>
Signed-off-by: John Lu <[email protected]>
Signed-off-by: John Lu <[email protected]>
| assert((!MMO->getRanges() || | ||
| (mdconst::extract<ConstantInt>(MMO->getRanges()->getOperand(0)) | ||
| ->getBitWidth() == MemVT.getScalarSizeInBits() && | ||
| MemVT.isInteger())) && | ||
| "Range metadata and load type must match!"); |
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.
We do need something like this as it's the closest thing we have to a DAG verifier
Signed-off-by: John Lu <[email protected]>
KnownBits passed to computeKnownBitsFromRangeMetadata must have the same bit width as the range metadata bit width. Otherwise the calculated results will be incorrect.