diff options
| author | Duncan Sands <baldrick@free.fr> | 2011-11-23 16:26:47 +0000 |
|---|---|---|
| committer | Duncan Sands <baldrick@free.fr> | 2011-11-23 16:26:47 +0000 |
| commit | 81a2af12d61d8de39b20e647d637e4338d7e7cc5 (patch) | |
| tree | aaaa774fb2b2bd9e00ebfdca10f4f77606ace98d /llvm/lib | |
| parent | ebcb4518746e8e6303c8bed916fee4a09156701d (diff) | |
| download | bcm5719-llvm-81a2af12d61d8de39b20e647d637e4338d7e7cc5.tar.gz bcm5719-llvm-81a2af12d61d8de39b20e647d637e4338d7e7cc5.zip | |
Fix a crash in which a multiplication was being reported as being both negative
and positive: positive, because it could be directly computed to be positive;
negative, because the nsw flags means it is either negative or undefined (the
multiplication always overflowed).
llvm-svn: 145104
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 9f7b5b501a3..22f1c144ea2 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -248,9 +248,14 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, APInt::getHighBitsSet(BitWidth, LeadZ); KnownZero &= Mask; - if (isKnownNonNegative) + // Only make use of no-wrap flags if we failed to compute the sign bit + // directly. This matters if the multiplication always overflows, in + // which case we prefer to follow the result of the direct computation, + // though as the program is invoking undefined behaviour we can choose + // whatever we like here. + if (isKnownNonNegative && !KnownOne.isNegative()) KnownZero.setBit(BitWidth - 1); - else if (isKnownNegative) + else if (isKnownNegative && !KnownZero.isNegative()) KnownOne.setBit(BitWidth - 1); return; |

