Skip to content

Improve boxing behaviour with flambda#567

Merged
lpw25 merged 1 commit intoocaml:4.04from
lpw25:fix-float-boxing
Sep 7, 2016
Merged

Improve boxing behaviour with flambda#567
lpw25 merged 1 commit intoocaml:4.04from
lpw25:fix-float-boxing

Conversation

@lpw25
Copy link
Contributor

@lpw25 lpw25 commented Apr 29, 2016

For code like:

let foo x = x +. 10.

let bar () =
  let y = 12.0 in
    (foo [@inlined never]) y +. (foo [@inlined never]) y

Flambda will currently produce clambda equivalent to:

(let (y 12.0)
  ((apply foo y)
   (apply foo y))

which, because of how unboxing now works, causes y to be unboxed and then re-boxed for both calls to foo.

This patch changes how flambda is converted to clambda, so that we instead get clambda like:

  ((apply foo 12.0)
   (apply foo 12.0))

which avoids the unnecessary allocation.

@alainfrisch
Copy link
Contributor

The problem is in the new unboxing strategy in cmmgen (see my email to caml-devel this morning), which currently wrongly interprets constants as boxing constructions. This should be easy to fix, and I think it's a better place than in flambda-specific passes.

@lpw25
Copy link
Contributor Author

lpw25 commented Apr 29, 2016

Even with fixes to cmmgen this patch will still be an improvement. It "un-anfs" constant expressions, which means that any optimisations which cmmgen performs will have more freedom. For example, if one of the uses of y should be unboxed and the other shouldn't then this patch makes it easy for cmmgen to naturally do the right thing.

@chambart
Copy link
Contributor

As this is not obvious in leo's comment, since flambda try quite aggressively to share constants, writing

let bar () =
  (foo [@inlined never]) 12.0 +. (foo [@inlined never]) 12.0

will also result in the same code.

The change is simple and mix well with the 'spirit' of this pass and fix some flambda specific problem, so I think this is ok to be flambda specific here.

@mshinwell
Copy link
Contributor

I think Un_anf should probably have been able to cope with variables used non-linearly (when appropriate, e.g. when bound to a constant) in the first place, so this patch seems appropriate. I have not yet checked the details.

@chambart
Copy link
Contributor

This applies to all kinds of constants. We may want to restrict this to some.

@damiendoligez damiendoligez added this to the 4.04 milestone May 2, 2016
@mshinwell
Copy link
Contributor

@chambart We think this can go into 4.04. What do you want to do about your comment about restricting to certain varieties of constants?

@chambart
Copy link
Contributor

@mshinwell @lpw25 , No this is not really important. This can be accepted as it is

@chambart
Copy link
Contributor

I forgot to mark this as approved before, here it is !

@lpw25 lpw25 changed the base branch from trunk to 4.04 September 7, 2016 15:04
@lpw25 lpw25 merged commit 4d78b0f into ocaml:4.04 Sep 7, 2016
EduardoRFS pushed a commit to esy-ocaml/ocaml that referenced this pull request Jul 23, 2021
chambart pushed a commit to chambart/ocaml-1 that referenced this pull request Aug 4, 2021
Import middle_end/flambda2 from ocaml-flambda/ocaml rev 068eb9f (Fexpr support for rec info, coercions (ocaml#567)) squashed with the following fixes (from mshinwell/flambda-backend branch import-flambda2):

* Fix inlining attributes in middle_end/flambda2/compilenv_deps/patricia_tree.ml
* Fix inlining attributes in middle_end/flambda2/naming/name_abstraction.ml
* Update Lambda_conversions to cope with the removal of the size+tag propagation
* dune file fixes for Flambda 2 compilation in the Flambda backend
* Stub out Flambda_features temporarily
* Fixes for Immutable_unique and tag/size removal patch
* is_c_builtin
* probes
* Support for probes and C builtins (as used for intrinisics)
* Removal of Double_u, use Double instead
* Use exhaustive match in close_c_call
* menhir version change in middle_end/flambda2/parser/flambda_parser.ml
* Avoid Location.print_compact
* Avoid Lambda.print_scoped_location
chambart pushed a commit to Gbury/ocaml that referenced this pull request Aug 5, 2021
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Oct 5, 2021
Import middle_end/flambda2 from ocaml-flambda/ocaml rev 068eb9f (Fexpr support for rec info, coercions (ocaml#567)) squashed with the following fixes (from mshinwell/flambda-backend branch import-flambda2):

* Fix inlining attributes in middle_end/flambda2/compilenv_deps/patricia_tree.ml
* Fix inlining attributes in middle_end/flambda2/naming/name_abstraction.ml
* Update Lambda_conversions to cope with the removal of the size+tag propagation
* dune file fixes for Flambda 2 compilation in the Flambda backend
* Stub out Flambda_features temporarily
* Fixes for Immutable_unique and tag/size removal patch
* is_c_builtin
* probes
* Support for probes and C builtins (as used for intrinisics)
* Removal of Double_u, use Double instead
* Use exhaustive match in close_c_call
* menhir version change in middle_end/flambda2/parser/flambda_parser.ml
* Avoid Location.print_compact
* Avoid Lambda.print_scoped_location
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Sep 21, 2022
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants