Skip to content

Reload registers early in branches#180

Closed
bobot wants to merge 1 commit intoocaml:trunkfrom
bobot:ifspill
Closed

Reload registers early in branches#180
bobot wants to merge 1 commit intoocaml:trunkfrom
bobot:ifspill

Conversation

@bobot
Copy link
Copy Markdown
Contributor

@bobot bobot commented May 4, 2015

During the discussion of #162, it appears that a call in one branch will always hindered a fast path in another branch because all the live registers will have to be reloaded after the join point. The problem is particularly patent in ocaml since there is no callee saved registers.

This request for comment implements the analogous of this existing optimisation1. Instead of pushing later spillings in the branch that needs them, it pushes earlier reloadings in the branch that destroys the registers.

With this optimization the following (dumb) function use only registers in the case x<y, and as many spilling/reloading than previously :

let fun_l (x:int) y =
  let r = if x < y then y else max x y in
  r + x + y

Deadcode elimination pass is added after the split pass because unneeded reloading can be added as in this function:

 let fun_i (x:int) y z =
  let r = if x < y then y else max x y in
  let w = max r r in
  w + r + x + y

This optimization has similar bad cases than the previous one and the interaction with the previous one (spill late) could add a lot of spilling. In this function (where fun_l is automatically inlined) x is spilled once more (in the slow path) by call to fun_l:

let fun_m x y =
  let r = fun_l x y in
  let r = fun_l r x in
  let r = fun_l r x in
  r

If the previous optimization (spill late) is deactivated there are as many spilling/reloading as before.

Does this optimization have already been considered? Do you think it can be interesting to investigate it more? with macro-benchmarks?

Regards,

That allows in such function to use only registers in the case `x<y` :

```ocaml
let fun_l (x:int) y z =
  let r = if x < y then y else max x y in
  r + x + y
```
@gasche
Copy link
Copy Markdown
Member

gasche commented May 4, 2015

For benchmarks you may want to try operf-macro (macro benchmarks) and operf-micro (micro benchmarks).

@bobot bobot mentioned this pull request May 4, 2015
@damiendoligez damiendoligez added this to the 4.04-or-later milestone Jan 25, 2016
@mshinwell mshinwell removed this from the 4.04 milestone Sep 7, 2016
@mshinwell
Copy link
Copy Markdown
Contributor

@bobot Could you rebase this patch and fix the conflicts? We can then try it on @AltGr 's benchmarking setup.

@mshinwell mshinwell changed the title [RFC] [Spill] add an optimisation which reload early registers in branches Reload registers early in branches Dec 27, 2016
@mshinwell
Copy link
Copy Markdown
Contributor

No response from the author for more than a year, so closing.

In general for pull requests proposing optimizations it would be helpful if benchmark numbers could be provided from the beginning. This is especially the case for ones like this where the benefit is unclear.

@bobot If you have further time to work on it then please provide a branch against the latest released OCaml (currently 4.05) and ping either myself or @AltGr so we can add it to the benchmarking framework.

@mshinwell mshinwell closed this Aug 9, 2017
stedolan added a commit to stedolan/ocaml that referenced this pull request Feb 20, 2020
…l#180)

It was only used to adjust the stack in caml_raise_exception,
but that function immediately calls SWITCH_C_TO_OCAML,
which resets the stack pointer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants