summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2018-11-28 16:37:04 +0000
committerNikita Popov <nikita.ppv@gmail.com>2018-11-28 16:37:04 +0000
commitcf596a8c26ba08c473e567f2f8382602851fe1db (patch)
tree3cb600617f0bb0e987e8840002a96660d06eaf7d /llvm/lib/Analysis/ValueTracking.cpp
parent78a9295e150190c5a4efe345d731cb78e037d28f (diff)
downloadbcm5719-llvm-cf596a8c26ba08c473e567f2f8382602851fe1db.tar.gz
bcm5719-llvm-cf596a8c26ba08c473e567f2f8382602851fe1db.zip
[ValueTracking] Determine always-overflow condition for unsigned sub
Always-overflow was already determined for unsigned addition, but not subtraction. This patch establishes parity. This allows us to perform some additional simplifications for signed saturating subtractions. This change is part of https://reviews.llvm.org/D54534. llvm-svn: 347771
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ed17441d1e4..3c01d979560 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4001,13 +4001,11 @@ OverflowResult llvm::computeOverflowForUnsignedAdd(
if (LHSKnown.isNegative() && RHSKnown.isNegative()) {
// The sign bit is set in both cases: this MUST overflow.
- // Create a simple add instruction, and insert it into the struct.
return OverflowResult::AlwaysOverflows;
}
if (LHSKnown.isNonNegative() && RHSKnown.isNonNegative()) {
// The sign bit is clear in both cases: this CANNOT overflow.
- // Create a simple add instruction, and insert it into the struct.
return OverflowResult::NeverOverflows;
}
}
@@ -4124,11 +4122,18 @@ OverflowResult llvm::computeOverflowForUnsignedSub(const Value *LHS,
AssumptionCache *AC,
const Instruction *CxtI,
const DominatorTree *DT) {
- // If the LHS is negative and the RHS is non-negative, no unsigned wrap.
KnownBits LHSKnown = computeKnownBits(LHS, DL, /*Depth=*/0, AC, CxtI, DT);
- KnownBits RHSKnown = computeKnownBits(RHS, DL, /*Depth=*/0, AC, CxtI, DT);
- if (LHSKnown.isNegative() && RHSKnown.isNonNegative())
- return OverflowResult::NeverOverflows;
+ if (LHSKnown.isNonNegative() || LHSKnown.isNegative()) {
+ KnownBits RHSKnown = computeKnownBits(RHS, DL, /*Depth=*/0, AC, CxtI, DT);
+
+ // If the LHS is negative and the RHS is non-negative, no unsigned wrap.
+ if (LHSKnown.isNegative() && RHSKnown.isNonNegative())
+ return OverflowResult::NeverOverflows;
+
+ // If the LHS is non-negative and the RHS negative, we always wrap.
+ if (LHSKnown.isNonNegative() && RHSKnown.isNegative())
+ return OverflowResult::AlwaysOverflows;
+ }
return OverflowResult::MayOverflow;
}
OpenPOWER on IntegriCloud