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

Unnecessary boxing in [let] #6260

Closed
vicuna opened this issue Dec 4, 2013 · 2 comments
Closed

Unnecessary boxing in [let] #6260

vicuna opened this issue Dec 4, 2013 · 2 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Dec 4, 2013

Original bug ID: 6260
Reporter: vbrankov
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2015-12-11T18:26:26Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.01.0
Fixed in version: 4.02.0+dev
Category: back end (clambda to assembly)
Tags: patch
Monitored by: @gasche @hcarty @alainfrisch

Bug description

This code comes with a ton of unnecessary boxing:

let () =
let x = 0.5 in
let w =
let y =
let z = x +. x in
z +. z
in
y +. y
in
let u = w +. w in ()

Why does it matter? This means that short inlined functions which return float values do unnecessary boxing. This little change hopefully gets rid of it:

Index: asmcomp/cmmgen.ml

--- asmcomp/cmmgen.ml (revision 14338)
+++ asmcomp/cmmgen.ml (working copy)
@@ -1122,7 +1122,7 @@
| Boxed_float
| Boxed_integer of boxed_integer

-let is_unboxed_number = function
+let rec is_unboxed_number = function
Uconst(Const_base(Const_float f), _) ->
Boxed_float
| Uprim(p, _, _) ->
@@ -1164,6 +1164,7 @@
| Pbbswap bi -> Boxed_integer bi
| _ -> No_unboxing
end

  • | Ulet(_, _, body) -> is_unboxed_number body
    | _ -> No_unboxing

let subst_boxed_number unbox_fn boxed_id unboxed_id box_chunk box_offset exp =

The assembly before and after:

camlX87__entry:
.cfi_startproc
subq $8, %rsp
.cfi_adjust_cfa_offset 8
.L100:
movsd .L101(%rip), %xmm0
addsd %xmm0, %xmm0
call caml_alloc3@PLT
.L102:
leaq 8(%r15), %rax
movq $1277, -8(%rax)
addsd %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 16(%rax), %rbx
movq $1277, -8(%rbx)
movsd (%rax), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rbx)
movsd (%rbx), %xmm0
addsd (%rbx), %xmm0 cc-ed
movq $1, %rax
movq $1, %rax
addq $8, %rsp
.cfi_adjust_cfa_offset -8
ret
.cfi_adjust_cfa_offset 8
.cfi_endproc

camlX87__entry:
.cfi_startproc
.L100:
movsd .L101(%rip), %xmm0
addsd %xmm0, %xmm0
addsd %xmm0, %xmm0
addsd %xmm0, %xmm0
addsd %xmm0, %xmm0
movq $1, %rax
movq $1, %rax
ret
.cfi_endproc

@vicuna
Copy link
Author

vicuna commented Dec 4, 2013

Comment author: vbrankov

I'm sorry, there's no way for me to modify the "Summary" and I now see it's too long. Also, I think that the patch should be worked on, because I think it should handle things other than Ulet, for instance Usequence.

@vicuna
Copy link
Author

vicuna commented Mar 25, 2014

Comment author: @alainfrisch

Thanks! Committed to trunk, rev 14486.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants