diff options
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index a6c256f..4ae1c6d 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4955,11 +4955,18 @@ OverflowResult llvm::computeOverflowForUnsignedSub(const Value *LHS, // X - (X % ?) // The remainder of a value can't have greater magnitude than itself, // so the subtraction can't overflow. + + // X - (X -nuw ?) + // In the minimal case, this would simplify to "?", so there's no subtract + // at all. But if this analysis is used to peek through casts, for example, + // then determining no-overflow may allow other transforms. + // TODO: There are other patterns like this. // See simplifyICmpWithBinOpOnLHS() for candidates. - if (match(RHS, m_URem(m_Specific(LHS), m_Value())) && - isGuaranteedNotToBeUndefOrPoison(LHS, AC, CxtI, DT)) - return OverflowResult::NeverOverflows; + if (match(RHS, m_URem(m_Specific(LHS), m_Value())) || + match(RHS, m_NUWSub(m_Specific(LHS), m_Value()))) + if (isGuaranteedNotToBeUndefOrPoison(LHS, AC, CxtI, DT)) + return OverflowResult::NeverOverflows; // Checking for conditions implied by dominating conditions may be expensive. // Limit it to usub_with_overflow calls for now. |