ocaml-flambda / flambda-backend

The Flambda backend project for OCaml
93 stars 67 forks source link

Join: only generate alias types to older variables #2705

Closed lthls closed 2 weeks ago

lthls commented 2 weeks ago

This ensures that we don't forget to join head types when several parameters are all aliases of each other without a common alias in the environment at fork

This problem starts appearing very frequently after #2628, and was causing a number of allocations to be kept because the absence of a head type made unboxing fail.

Here is an example that doesn't involve #2628:

let f x y z =
  let[@local] k a b =
    a +. b
  in
  if x then
    let arg = y -. z in k arg arg
  else
    let arg = z -. y in k arg arg

With this PR, a and b are unboxed properly and the result contains a single allocation at the end. We still keep both variables though, I'll see if I can fix that too but I think this PR should be merged anyway (assuming it doesn't cause any regressions).

lthls commented 2 weeks ago

We still keep both variables though, I'll see if I can fix that too but I think this PR should be merged anyway (assuming it doesn't cause any regressions).

It looks like I mistakenly ran the test without join points, in which case it is expected that we still get two unboxed variables. With join points we only keep a single unboxed variable, as expected.