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

Simple missing case of float unboxing #6866

Closed
vicuna opened this issue May 13, 2015 · 4 comments
Closed

Simple missing case of float unboxing #6866

vicuna opened this issue May 13, 2015 · 4 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented May 13, 2015

Original bug ID: 6866
Reporter: @alainfrisch
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2017-02-16T14:15:02Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: back end (clambda to assembly)
Tags: patch
Monitored by: @gasche @diml @jmeber @hcarty

Bug description

The following code shows a case where float boxing is not eliminated:

type t = {mutable x: float}
let f r = r.x <- (let x = r.x in x)

It produces this cmm code:

(function{foo.ml:3,6-37} camlFoo__f_1326 (r/1327: addr)
 (store float64u r/1327
   (let (x/1333 (load float64u r/1327) x/1328 (alloc 1277 x/1333))
     (load float64u x/1328)))
 1a)

The reason is that the "let x =" is processed without the knowledge that its result will be used in a context which unboxes the float.

This kind of cases can easily occur because of inlining. It shouldn't be too hard to handle then in cmmgen.

(Note: the very simple example give above is simplified if we don't compile with -g.)

File attachments

@vicuna
Copy link
Author

vicuna commented May 13, 2015

Comment author: @alainfrisch

A patch is attached: the body of a let used in an unboxing context is itself compiled knowing it will be unboxed (before deciding whether to unbox the bound identifier).

However, the patch doesn't address:

let f r = r.x <- (if r.x > 0. then let x = r.x in x else 0.)

A better solution would probably to always pass to Cmm.transl some information about the unboxing context, instead of unboxing "after the fact".

@vicuna
Copy link
Author

vicuna commented May 13, 2015

Comment author: @alainfrisch

The second attached patch addresses the case from the previous note.

@vicuna
Copy link
Author

vicuna commented May 15, 2015

Comment author: @alainfrisch

Another simple case currently missed:

let f x =
  let v = ref 0. in
  v := (let y = 1. +. x in y)

The issue here is that the statement "v := ..." is first compiled without knowing that v will be unboxed. During this pass, nothing tells us that the "let y = .. in ..." will have its result unboxed. So boxing of "y" is not eliminated. It's only once "v := ..." is compiled to cmm that the compiler decides that "v" can be unboxed, but it's too late.

This results in (again in -g mode for such a simple example):

(let v/1332 0.
   (assign v/1332
             (let
               (y/1331 (+f 1. (load float64u x/1325))
                y/1327 (alloc 1277 y/1331))
               (load float64u y/1327)))
   1a))

One approach could be to keep in a table the fact that y/1331 is the unboxed version of y/1327 so that once "load y" is to be built (to unbox v), it is immediately simplified to y/1331 (and then eliminate the dead binding for y/1327).

@vicuna
Copy link
Author

vicuna commented Jul 27, 2015

Comment author: @alainfrisch

All the cases here are fixed by the new unboxing strategy.

@vicuna vicuna closed this as completed Feb 16, 2017
@vicuna vicuna added this to the 4.03.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
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