C++: IR-based range analysis of addition #12673
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds range analysis for binary addition. The library already provided less-than-optimal lower (resp. upper) bounds for addition when a one of the operands was guaranteed to be negative (resp. positive), and this PR replaces that logic by simple just calling
bounded
recursively on both operands.This provides us with many more bounds (since we're now analyzing all additions), and also more precise bounds (since we're no longer just giving a bound based on the sign analysis).
As can be seen in the 1a61864 commit, we're losing quite a few bounds on cases like:
before, we were able to determine that
r
was always positive, and thus whatever lower bound we had fortotal
beforetotal += r
continued to be valid. Now that we're throwing away the sign analysis, we can't deduce a lower bound here anymore since we still don't compute a range for multiplication (I'll do this in a follow-up PR).