English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] inlining of functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-12-17 (17:59)
From: Markus Mottl <markus@o...>
Subject: [Caml-list] inlining of functions

I would like to know why OCaml does not produce the same machine code for:

  let f x =
    let g n = x + n in
    g 1, g 2


  let f x =
    x + 1, x + 2

OCaml obviously performs some inlining, but otherwise produces more
redundant code in the first example. The reason why I ask is that it
often happens that I want to factor out computations that are shared
between different case-arms like in:

  let f x =
    let g y = ... h x y ... in
    match foo with
    | A -> g n
    | B -> g m

It may degrade performance in tight loops quite visibly if there is
extra-code to execute. One would have to use copy&paste to prevent this,
which is not really that elegant.

Markus Mottl

P.S.:  Congratulations to the whole OCaml-team for the recent release
       of OCaml-3.04! You should add some bugs from time to time so
       that people do not get bored marvelling about its unvaryingly
       superb quality! ;)

Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr