Strengthen value range analysis in the compiler - #11038
Merged
bjorng merged 5 commits intoMay 20, 2026
Merged
Conversation
Contributor
CT Test Results 2 files 335 suites 9m 14s ⏱️ Results for commit 88e4098. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts
// Erlang/OTP Github Action Bot |
lucioleKi
previously approved these changes
Apr 20, 2026
bjorng
force-pushed
the
bjorn/compiler/better-ranges/GH-8157/OTP-19831
branch
4 times, most recently
from
April 27, 2026 04:57
905050f to
714c7b4
Compare
bjorng
force-pushed
the
bjorn/compiler/better-ranges/GH-8157/OTP-19831
branch
from
April 29, 2026 08:35
714c7b4 to
3b3c942
Compare
The signatures pass is run once, doing a type analysis of all functions
in the module to compute argument types and return types for all functions.
This pass must be conservative regarding the range for certain
operators. Consider this example:
fact(N) when is_integer(N, 0, 10_000) ->
fact(N, 1).
fact(0, P) -> P;
fact(N, P) -> fact(N - 1, P * N).
To ensure convergence, the signatures pass will compute the range of
the result of `N - 1` to be '-inf' to 9999, and `P * N` to be 1 to
'+inf'.
This commit improves the signatures pass by attempting to use a
tighter range for the result of the `+`, `-`, `*`, and
`bnot` operators. If the value range analysis converges, the tighter
range is kept; otherwise, the more conservative range is used.
For the example, the range for `N` will now be 0 to 10000.
Solves erlang#8157
The `opt_ranges` subpass is no longer needed after the improvements made to the signatures pass in the previous commit.
bjorng
force-pushed
the
bjorn/compiler/better-ranges/GH-8157/OTP-19831
branch
from
May 13, 2026 10:52
3b3c942 to
ec77c9e
Compare
Handle negative bounds for `bor` and `bxor`, and simplify handling of
`band`.
Also simplify all logical operators by canonicalizing the input
ranges: converting `any` to `{'-inf','+inf'} and replacing too large
integers with infinity. This reduces the number of special cases.
Thanks to Nelson Vides for the idea to replace large integers
with infinity.
bjorng
force-pushed
the
bjorn/compiler/better-ranges/GH-8157/OTP-19831
branch
from
May 19, 2026 11:50
ec77c9e to
eddb727
Compare
lucioleKi
reviewed
May 20, 2026
| inf_bnot(D), inf_bnot(C)), | ||
| {inf_bnot(Max),inf_bnot(Min)}. | ||
|
|
||
| -else. |
Contributor
There was a problem hiding this comment.
Did you mean to make a separate commit in this PR or later?
Contributor
Author
There was a problem hiding this comment.
Forgot that. I will do it in this PR.
bjorng
force-pushed
the
bjorn/compiler/better-ranges/GH-8157/OTP-19831
branch
from
May 20, 2026 08:23
eddb727 to
88e4098
Compare
lucioleKi
approved these changes
May 20, 2026
bjorng
added a commit
to bjorng/otp
that referenced
this pull request
Aug 13, 2026
The bounds for the `rem` operator is supposed to reach a fixpoint if the result is fed back to one of its operands, but for some values of its operands it didn't. This matters much more after erlang#11038. Resolves erlang#11400
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 pull request improves the value range analysis. It ensures that the original example in #8157 is properly optimized, and it also optimizes the
factfunction added by me to that issue. Also, the expressionC bxor (B bor (bnot D))(part of an MD5 calculation) will now have a range.See the commit messages for more details.
This PR is meant for OTP 30, since we usually don't add new optimizations after RC1.
Resolves #8157