Skip to content

C++: IR-based range analysis of addition #12673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2023

Conversation

MathiasVP
Copy link
Contributor

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:

if(5 <= b && b <= 23) {
  int r = 11*b;
  total += r;
  range(total);
}

before, we were able to determine that r was always positive, and thus whatever lower bound we had for total before total += 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).

@MathiasVP MathiasVP requested a review from a team as a code owner March 27, 2023 13:35
@github-actions github-actions bot added the C++ label Mar 27, 2023
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Mar 27, 2023
@MathiasVP
Copy link
Contributor Author

MathiasVP commented Mar 27, 2023

Integration tests are failing due to unrelated Ruby changes. Now fixed.

@MathiasVP MathiasVP requested a review from rdmarsh2 March 27, 2023 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants