aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2020-02-07 10:31:35 +0000
committerFlorian Hahn <flo@fhahn.com>2020-02-07 10:41:18 +0000
commit14ef87bda67d53f351217c4522150e41fb5695e8 (patch)
tree011025f5ee49812fc927437a72365aafa49685a2 /llvm/lib/Analysis/ValueTracking.cpp
parent74734e809ac778beb01776ee207643184c09c2a0 (diff)
downloadllvm-14ef87bda67d53f351217c4522150e41fb5695e8.zip
llvm-14ef87bda67d53f351217c4522150e41fb5695e8.tar.gz
llvm-14ef87bda67d53f351217c4522150e41fb5695e8.tar.bz2
[ValueTracking] usub(a, b) cannot overflow if a >= b.
If we know that a >= b (unsigned), usub.with.overflow(a, b) cannot overflow. Similarly, if b > a, the same expression overflows. Reviewers: nikic, RKSimon, lebedev.ri, spatel Reviewed By: nikic, Gerolf Differential Revision: https://reviews.llvm.org/D74066
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 70d2bb6..3d3c912 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4439,6 +4439,16 @@ OverflowResult llvm::computeOverflowForUnsignedSub(const Value *LHS,
AssumptionCache *AC,
const Instruction *CxtI,
const DominatorTree *DT) {
+ // Checking for conditions implied by dominating conditions may be expensive.
+ // Limit it to usub_with_overflow calls for now.
+ if (match(CxtI,
+ m_Intrinsic<Intrinsic::usub_with_overflow>(m_Value(), m_Value())))
+ if (auto C =
+ isImpliedByDomCondition(CmpInst::ICMP_UGE, LHS, RHS, CxtI, DL)) {
+ if (*C)
+ return OverflowResult::NeverOverflows;
+ return OverflowResult::AlwaysOverflowsLow;
+ }
ConstantRange LHSRange = computeConstantRangeIncludingKnownBits(
LHS, /*ForSigned=*/false, DL, /*Depth=*/0, AC, CxtI, DT);
ConstantRange RHSRange = computeConstantRangeIncludingKnownBits(