Skip to content
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

Improve code-generation for inlined comparisons #10228

Merged
merged 3 commits into from Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -70,6 +70,9 @@ Working version
- #9937: improvements in ARM64 code generation (constants, sign extensions)
(Xavier Leroy, review by Stephen Dolan)

- #??: Better code-generation for inlined comparisons
(Stephen Dolan, review by ??)

### Standard library:

- #9533: Added String.starts_with and String.ends_with.
Expand Down
16 changes: 11 additions & 5 deletions asmcomp/cmmgen.ml
Expand Up @@ -1117,7 +1117,7 @@ and transl_unbox_sized size dbg env exp =
| Thirty_two -> transl_unbox_int dbg env Pint32 exp
| Sixty_four -> transl_unbox_int dbg env Pint64 exp

and transl_let env str kind id exp body =
and transl_let' env str kind id exp transl_body =
let dbg = Debuginfo.none in
let cexp = transl env exp in
let unboxing =
Expand Down Expand Up @@ -1151,21 +1151,24 @@ and transl_let env str kind id exp body =
(* N.B. [body] must still be traversed even if [exp] will never return:
there may be constant closures inside that need lifting out. *)
begin match str, kind with
| Immutable, _ -> Clet(id, cexp, transl env body)
| Mutable, Pintval -> Clet_mut(id, typ_int, cexp, transl env body)
| Mutable, _ -> Clet_mut(id, typ_val, cexp, transl env body)
| Immutable, _ -> Clet(id, cexp, transl_body env)
| Mutable, Pintval -> Clet_mut(id, typ_int, cexp, transl_body env)
| Mutable, _ -> Clet_mut(id, typ_val, cexp, transl_body env)
end
| Boxed (boxed_number, false) ->
let unboxed_id = V.create_local (VP.name id) in
let v = VP.create unboxed_id in
let cexp = unbox_number dbg boxed_number cexp in
let body =
transl (add_unboxed_id (VP.var id) unboxed_id boxed_number env) body in
transl_body (add_unboxed_id (VP.var id) unboxed_id boxed_number env) in
begin match str, boxed_number with
| Immutable, _ -> Clet (v, cexp, body)
| Mutable, bn -> Clet_mut (v, typ_of_boxed_number bn, cexp, body)
end

and transl_let env str kind id exp body =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the name transl_let for what is now called transl_let' and call it directly from the only call site (for dealing with Ulet).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

transl_let' env str kind id exp (fun env -> transl env body)

and make_catch ncatch body handler dbg = match body with
| Cexit (nexit,[]) when nexit=ncatch -> handler
| _ -> ccatch (ncatch, [], body, handler, dbg)
Expand Down Expand Up @@ -1202,6 +1205,9 @@ and transl_if env (approx : then_else)
ifso_dbg arg2
then_dbg then_
else_dbg else_
| Ulet(str, kind, id, exp, cond) ->
transl_let' env str kind id exp (fun env ->
transl_if env approx dbg cond then_dbg then_ else_dbg else_)
| Uprim (Psequand, [arg1; arg2], inner_dbg) ->
transl_sequand env approx
inner_dbg arg1
Expand Down