diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-09 16:12:59 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-09 16:12:59 +0000 |
commit | 10edd2b79d04f70a72d85e57ac1cf7cf0190eb87 (patch) | |
tree | 80f60c2a404d01c3b3db8522e05c0c289847e843 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 49d9d17a77cb0bab1b7fb7b141af272a62856550 (diff) | |
download | llvm-10edd2b79d04f70a72d85e57ac1cf7cf0190eb87.zip llvm-10edd2b79d04f70a72d85e57ac1cf7cf0190eb87.tar.gz llvm-10edd2b79d04f70a72d85e57ac1cf7cf0190eb87.tar.bz2 |
[ValueTracking] Use computeConstantRange() in signed add overflow determination
This is D59386 for the signed add case. The computeConstantRange()
result is now intersected into the existing known bits information,
allowing to detect additional no-overflow/always-overflow conditions
(though the latter isn't used yet).
This (finally...) covers the motivating case from D59071.
Differential Revision: https://reviews.llvm.org/D60420
llvm-svn: 358014
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index ce55b9e..1407f24 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4086,8 +4086,8 @@ static ConstantRange computeConstantRangeIncludingKnownBits( V, DL, Depth, AC, CxtI, DT, ORE, UseInstrInfo); ConstantRange CR1 = ConstantRange::fromKnownBits(Known, ForSigned); ConstantRange CR2 = computeConstantRange(V, UseInstrInfo); - // TODO: Use ForSigned to determine preferred range. - ConstantRange::PreferredRangeType RangeType = ConstantRange::Smallest; + ConstantRange::PreferredRangeType RangeType = + ForSigned ? ConstantRange::Signed : ConstantRange::Unsigned; return CR1.intersectWith(CR2, RangeType); } @@ -4133,12 +4133,10 @@ static OverflowResult computeOverflowForSignedAdd(const Value *LHS, ComputeNumSignBits(RHS, DL, 0, AC, CxtI, DT) > 1) return OverflowResult::NeverOverflows; - KnownBits LHSKnown = computeKnownBits(LHS, DL, /*Depth=*/0, AC, CxtI, DT); - KnownBits RHSKnown = computeKnownBits(RHS, DL, /*Depth=*/0, AC, CxtI, DT); - ConstantRange LHSRange = - ConstantRange::fromKnownBits(LHSKnown, /*signed*/ true); - ConstantRange RHSRange = - ConstantRange::fromKnownBits(RHSKnown, /*signed*/ true); + ConstantRange LHSRange = computeConstantRangeIncludingKnownBits( + LHS, /*ForSigned=*/true, DL, /*Depth=*/0, AC, CxtI, DT); + ConstantRange RHSRange = computeConstantRangeIncludingKnownBits( + RHS, /*ForSigned=*/true, DL, /*Depth=*/0, AC, CxtI, DT); OverflowResult OR = mapOverflowResult(LHSRange.signedAddMayOverflow(RHSRange)); if (OR != OverflowResult::MayOverflow) |