|Anonymous | Login | Signup for a new account||2017-05-28 06:52 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0006339||OCaml||back end (clambda to assembly)||public||2014-03-06 15:42||2016-12-07 14:03|
|Priority||normal||Severity||feature||Reproducibility||have not tried|
|Target Version||Fixed in Version||4.03.0|
|Summary||0006339: Useless indirection to access a known top-level function|
|Description||Consider the following piece of code:|
let f x = x + 1 let fl l = List.map f l
ocamlopt will compile this structure by putting f and fl into fields of the global symbol corresponding to the current unit, and turn the reference to f (in fl) into a field access of this global symbol. Later in the compilation process (while mapping from lambda to ulambda), the compiler detects that f is actually a constant closure. This information is available (as a Value_closure approximation) when the code for fl is emitted, but there is no way to represent a reference to a known closure in the clambda code. The useless reference (to a statically known value) remains in the generated code as can be seen on the -dcmm or -S output.
The resulting assembly code for fl is:
movq %rax, %rbx movq camlTup@GOTPCREL(%rip), %rax movq (%rax), %rax jmp camlList__map_1040@PLT
while it could be:
movq %rax, %rbx movq camlTup__3@GOTPCREL(%rip), %rax jmp camlList__map_1040@PLT
Certainly not a big deal, but it should not be too difficult to improve it.
A possible approach would be to treat constant closures (Uclosure(_, )) as structured constants, allocated during the closure pass.
|Attached Files||pr_6339.diff [^] (22,890 bytes) 2014-03-10 19:07 [Show Content]|
Attached a diff, which keeps track of constant closure and allows to refer to them directly, thus avoiding some indirections. Moreover, since it considers constant closures as atomic values, they don't prevent inlining. This means that a function such as:
let foo l =
List.map (fun x -> x + 1) l
let foo l =
let f x = x + 1 in
List.map f l
can be inlined. This can give a non-negligible speedup (-20% when calling this function foo in a tight loop on an empty list).
Simply avoiding the indirection does not seem to bring much, even on small examples. It might still be a good idea to do so, since reducing the code size is always a good idea.
The patch also detects more cases of closure which don't need their environment.
|Flambda should fix these problems.|
|2014-03-06 15:42||frisch||New Issue|
|2014-03-06 15:48||frisch||Description Updated||View Revisions|
|2014-03-06 15:56||frisch||Description Updated||View Revisions|
|2014-03-10 19:07||frisch||File Added: pr_6339.diff|
|2014-03-10 19:15||frisch||Note Added: 0011036|
|2014-05-16 20:59||doligez||Tag Attached: patch|
|2014-07-16 15:33||doligez||Status||new => acknowledged|
|2016-12-07 14:03||shinwell||Note Added: 0016703|
|2016-12-07 14:03||shinwell||Status||acknowledged => resolved|
|2016-12-07 14:03||shinwell||Fixed in Version||=> 4.03.0|
|2016-12-07 14:03||shinwell||Resolution||open => fixed|
|2016-12-07 14:03||shinwell||Assigned To||=> shinwell|
|2017-02-23 16:35||doligez||Category||OCaml backend (code generation) => Back end (clambda to assembly)|
|2017-02-23 16:44||doligez||Category||Back end (clambda to assembly) => back end (clambda to assembly)|
|Copyright © 2000 - 2011 MantisBT Group|