[WIP] Unbox numbers across static handlers#2162
Closed
alainfrisch wants to merge 1 commit intoocaml:trunkfrom
Closed
[WIP] Unbox numbers across static handlers#2162alainfrisch wants to merge 1 commit intoocaml:trunkfrom
alainfrisch wants to merge 1 commit intoocaml:trunkfrom
Conversation
Contributor
Author
The same problem can already occur with unboxing of let bindings. I'm experimenting in #2165 with basing the unboxing criterion on cmm, not clambda. |
Contributor
Author
|
Subsumed by #2165. |
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 is to resume the discussion on the proposal from #2156 to unbox numbers (floats, boxed ints) when passed as arguments to static handlers.
Static handlers are introduced by the compiler in a number of cases that can benefit from unboxing:
The unboxing decision for staticcatch parameters (in Cmmgen) is currently only based on value kind annotations (inherit from Lambda). One bad case is when all staticraise sites naturally produce a boxed version (e.g. by calling a float-returning function, or reading from a boxed data structure), and the statichandler can use this boxed version directly. With the new heuristics, those floats will be unboxed and then reboxed when accessed in the handler. This is similar to what happens for float mutable variables, which are always unboxed (independently of the bound expression), and I think one can live with that.
An alternative approach would be to do as for immutable let bindings:
If the bound variable is known to be a boxed number (from its value kind), one checks that unboxing the variable effectively result in removing at least one explicit boxing site when producing the bound value.
If the bound variable is not known to be a boxed number, one needs to be more restrictive (since different sites can produce values of different types), and one checks that the bound value is necessarily a boxed number (all sites resulting in the same kind of boxed numbers).
The equivalent here would be to translate the body of the statichandler, look at all staticraise sites in it matching the current handler, check all possible ways each argument is produced, and determine the unboxing decision as above (and then traversing the compiled body to add unboxing instructions around each unboxed argument, for all staticraise sites).
For let bindings, the check is done on clambda terms. I've tried doing the same, but this misses some cases as in:
This is because the
bvariable itself it not marked as a float (and this might suggest one could improve further the propagations of value kinds). Even if we managed to annotate the b/27 with Pfloatval, one would need to track the information to theexit 1 b/27 a/26. The alternative is to look instead at the generated cmm (which might benefit from inlining and other optimizations) to detect if a sub-expression is a boxed number. I've started working on that. One trouble is with constants, which are already turned into symbols (so one would need a lookup to check if a symbol represents a boxed number, which is not so nice).