jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Remove unused return is not recursive

Open eponier opened this issue 1 year ago • 1 comments

If removing a return reveals a new opportunity to remove a return, the compiler does not take advantage of it.

For instance,

fn g () -> reg u32 {
  reg u32 x;
  x = 0;
  return x;
}

fn f () -> reg u32 {
  reg u32 x;
  x = g ();
  return x;
}

export fn main () -> reg u32 {
  reg u32 res;
  res = 0;
  _ = f();
  return res;
}

The compiler removes the return value of f and thus could remove the return value of g, but it does not do it.

eponier avatar Jun 14 '24 15:06 eponier

Here is a variant: the unused arguments are not removed.

fn id2(reg u32 x y) -> reg u32, reg u32 {
  return x, y;
}

export
fn main(reg u32 a b) -> reg u32 {
  a = a;
  b += 42; //dead
  a, _ = id2(a, b);
  return a;
}

vbgl avatar May 02 '25 11:05 vbgl