diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-04-11 14:58:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 14:58:44 -0700 |
commit | 5f88dcdf0d308de12579d26d30f981b0689446af (patch) | |
tree | 7f39933ad9b58877c2e145be2504433b1b5bf1b0 /test | |
parent | 5d5e4654d0fd6165f7ddad88a20ce17ffa4caad6 (diff) | |
download | binaryen-5f88dcdf0d308de12579d26d30f981b0689446af.tar.gz binaryen-5f88dcdf0d308de12579d26d30f981b0689446af.tar.bz2 binaryen-5f88dcdf0d308de12579d26d30f981b0689446af.zip |
[Inlining] Preserve return_calls when possible (#4589)
We can preserve return_calls in inlined functions when the inlined call site is
itself a return_call, since the call result types must transitively match in
that case. This solves a problem where the previous inlining logic could
introduce stack exhaustion by downgrading recursive return_calls to normal
calls.
Fixes #4587.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/inlining_enable-tail-call.wast | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/lit/passes/inlining_enable-tail-call.wast b/test/lit/passes/inlining_enable-tail-call.wast index 646d2cf0d..0c460b552 100644 --- a/test/lit/passes/inlining_enable-tail-call.wast +++ b/test/lit/passes/inlining_enable-tail-call.wast @@ -705,3 +705,65 @@ (unreachable) ) ) + +(module + ;; CHECK: (type $i32_=>_i32 (func (param i32) (result i32))) + + ;; CHECK: (export "is_even" (func $is_even)) + (export "is_even" (func $is_even)) + ;; CHECK: (func $is_even (param $i i32) (result i32) + ;; CHECK-NEXT: (local $1 i32) + ;; CHECK-NEXT: (if (result i32) + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (local.get $i) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: (return + ;; CHECK-NEXT: (block $__inlined_func$is_odd (result i32) + ;; CHECK-NEXT: (local.set $1 + ;; CHECK-NEXT: (i32.sub + ;; CHECK-NEXT: (local.get $i) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (if (result i32) + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: (return_call $is_even + ;; CHECK-NEXT: (i32.sub + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $is_even (param $i i32) (result i32) + (if (result i32) + (i32.eqz (local.get $i)) + (i32.const 1) + (return_call $is_odd + (i32.sub + (local.get $i) + (i32.const 1) + ) + ) + ) + ) + (func $is_odd (param $i i32) (result i32) + (if (result i32) + (i32.eqz (local.get $i)) + (i32.const 0) + (return_call $is_even + (i32.sub + (local.get $i) + (i32.const 1) + ) + ) + ) + ) +) |