Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006260OCamlOCaml backend (code generation)public2013-12-04 21:022014-03-25 09:58
Reportervbrankov 
Assigned Tofrisch 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.01.0 
Target VersionFixed in Version4.02.0+dev 
Summary0006260: Unnecessary boxing in [let]
DescriptionThis 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
Tagspatch
Attached Files

- Relationships

-  Notes
(0010692)
vbrankov (reporter)
2013-12-04 21:34

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.
(0011095)
frisch (developer)
2014-03-25 09:58

Thanks! Committed to trunk, rev 14486.

- Issue History
Date Modified Username Field Change
2013-12-04 21:02 vbrankov New Issue
2013-12-04 21:34 vbrankov Note Added: 0010692
2013-12-05 15:24 doligez Tag Attached: patch
2014-03-25 09:58 frisch Note Added: 0011095
2014-03-25 09:58 frisch Status new => resolved
2014-03-25 09:58 frisch Fixed in Version => 4.02.0+dev
2014-03-25 09:58 frisch Resolution open => fixed
2014-03-25 09:58 frisch Assigned To => frisch


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker