binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Tail-Call optimization

Open HerrCai0907 opened this issue 7 months ago • 1 comments

I'm curious as to why binaryen doesn't implement an optimization pass for tailcall feature. Is the optimization itself not feasible?

If it is feasible, I would like to implement it.

The basic idea is we can convert

(func ...
   (call $f)
)

to

(func ...
   (return_call $f)
)
(func ...
   (return (call $f))
)

to

(func ...
   (return_call $f)
)
(func ...
   (if
      (condition)
      (call $f)
   )
)

to

(func ...
   (if
      (condition)
      (return_call $f)
   )
)

HerrCai0907 avatar Jun 10 '25 12:06 HerrCai0907

Linking to the corresponding PR: https://github.com/WebAssembly/binaryen/pull/7641

kripken avatar Jun 10 '25 19:06 kripken