-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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