diff options
author | Oliver Stannard <oliver.stannard@arm.com> | 2017-03-14 10:13:17 +0000 |
---|---|---|
committer | Oliver Stannard <oliver.stannard@arm.com> | 2017-03-14 10:13:17 +0000 |
commit | 062041113f86993cc0bb1488e90184ce5adf1e59 (patch) | |
tree | 98358496888a47e46834fc1c8a3d087d1223d354 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | d0bee506a04f012052d566baa206d8c8af95a3af (diff) | |
download | bcm5719-llvm-062041113f86993cc0bb1488e90184ce5adf1e59.tar.gz bcm5719-llvm-062041113f86993cc0bb1488e90184ce5adf1e59.zip |
[ValueTracking] Out of range shifts might be undef
If it is possible for the RHS of a shift operation to be greater than or equal
to the bit-width, then the result might be undef, and we can't report any known
bits.
In some cases, this was allowing a transformation in instcombine which widened
an undef value from i1 to i32, increasing the range of values that a function
could return.
Differential revision: https://reviews.llvm.org/D30781
llvm-svn: 297724
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 1761dac269d..a3d4198edcb 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -848,6 +848,14 @@ static void computeKnownBitsFromShiftOperator( computeKnownBits(I->getOperand(1), KnownZero, KnownOne, Depth + 1, Q); + // If the shift amount could be greater than or equal to the bit-width of the LHS, the + // value could be undef, so we don't know anything about it. + if ((~KnownZero).uge(BitWidth)) { + KnownZero.clearAllBits(); + KnownOne.clearAllBits(); + return; + } + // Note: We cannot use KnownZero.getLimitedValue() here, because if // BitWidth > 64 and any upper bits are known, we'll end up returning the // limit value (which implies all bits are known). |