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 all commits
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)

- #10228: Better code-generation for inlined comparisons
(Stephen Dolan, review by Alain Frisch and Xavier Leroy)

### Standard library:

- #9533: Added String.starts_with and String.ends_with.
Expand Down
15 changes: 9 additions & 6 deletions asmcomp/cmmgen.ml
Expand Up @@ -424,7 +424,7 @@ let rec transl env e =
let args = List.map (transl env) args in
send kind met obj args dbg
| Ulet(str, kind, id, exp, body) ->
transl_let env str kind id exp body
transl_let env str kind id exp (fun env -> transl env body)
| Uphantom_let (var, defining_expr, body) ->
let defining_expr =
match defining_expr with
Expand Down 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,16 +1151,16 @@ 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)
Expand Down Expand Up @@ -1202,6 +1202,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