Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -4182,19 +4182,19 @@ return OverflowResult::MayOverflow; // If the sign of Add is the same as at least one of the operands, this add - // CANNOT overflow. This is particularly useful when the sum is - // @llvm.assume'ed non-negative rather than proved so from analyzing its - // operands. + // CANNOT overflow. Check if there is an assumption about the sign of the + // result. bool LHSOrRHSKnownNonNegative = (LHSKnown.isNonNegative() || RHSKnown.isNonNegative()); bool LHSOrRHSKnownNegative = (LHSKnown.isNegative() || RHSKnown.isNegative()); if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) { - KnownBits AddKnown = computeKnownBits(Add, DL, /*Depth=*/0, AC, CxtI, DT); + KnownBits AddKnown(LHSKnown.getBitWidth()); + computeKnownBitsFromAssume( + Add, AddKnown, /*Depth=*/0, Query(DL, AC, CxtI, DT, true)); if ((AddKnown.isNonNegative() && LHSOrRHSKnownNonNegative) || - (AddKnown.isNegative() && LHSOrRHSKnownNegative)) { + (AddKnown.isNegative() && LHSOrRHSKnownNegative)) return OverflowResult::NeverOverflows; - } } return OverflowResult::MayOverflow;