aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorLU-JOHN <John.Lu@amd.com>2025-04-02 22:17:14 -0500
committerGitHub <noreply@github.com>2025-04-03 10:17:14 +0700
commit6a46c6c865270ceb01bcaef4a2e4c8df56a8800a (patch)
treed6b0a8db3ce63e04b3f2a8b6835b72b8e077d4a8 /llvm/lib/Analysis/ValueTracking.cpp
parentdcc2182bce3d2ef0e0a991664c51b4b3bfcf7197 (diff)
downloadllvm-6a46c6c865270ceb01bcaef4a2e4c8df56a8800a.zip
llvm-6a46c6c865270ceb01bcaef4a2e4c8df56a8800a.tar.gz
llvm-6a46c6c865270ceb01bcaef4a2e4c8df56a8800a.tar.bz2
Ensure KnownBits passed when calculating from range md has right size (#132985)
KnownBits passed to computeKnownBitsFromRangeMetadata must have the same bit width as the range metadata bit width. Otherwise the calculated results will be incorrect. --------- Signed-off-by: John Lu <John.Lu@amd.com>
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index fc0c749..3b0249f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -430,6 +430,10 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
ConstantInt *Upper =
mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
ConstantRange Range(Lower->getValue(), Upper->getValue());
+ // BitWidth must equal the Ranges BitWidth for the correct number of high
+ // bits to be set.
+ assert(BitWidth == Range.getBitWidth() &&
+ "Known bit width must match range bit width!");
// The first CommonPrefixBits of all values in Range are equal.
unsigned CommonPrefixBits =