| 1 |
// |jit-test| test-also=--setpref=wasm_lazy_tiering --setpref=wasm_lazy_tiering_synchronous; skip-if: wasmCompileMode() != "baseline+ion" || !getPrefValue("wasm_lazy_tiering") |
| 2 |
|
| 3 |
// Tests the inliner on a recursive function, in particular to establish that |
| 4 |
// the inlining heuristics have some way to stop the compiler looping |
| 5 |
// indefinitely and, more constrainingly, that it has some way to stop |
| 6 |
// excessive but finite inlining. |
| 7 |
|
| 8 |
// `func $recursive` has 95 bytecode bytes. With module- and function-level |
| 9 |
// inlining budgeting disabled, it is inlined into itself 1110 times, |
| 10 |
// processing an extra 105450 bytecode bytes. This is definitely excessive. |
| 11 |
// |
| 12 |
// With budgeting re-enabled, it is inlined just 9 times, as intended. |
| 13 |
|
| 14 |
let t = ` |
| 15 |
(module |
| 16 |
(func $recursive (export "recursive") (param i32) (result i32) |
| 17 |
(i32.le_u (local.get 0) (i32.const 1)) |
| 18 |
if (result i32) |
| 19 |
(i32.const 1) |
| 20 |
else |
| 21 |
(i32.const 1) |
| 22 |
|
| 23 |
(call $recursive (i32.sub (local.get 0) (i32.const 1))) |
| 24 |
i32.add |
| 25 |
(call $recursive (i32.sub (local.get 0) (i32.const 2))) |
| 26 |
i32.add |
| 27 |
|
| 28 |
(call $recursive (i32.sub (local.get 0) (i32.const 1))) |
| 29 |
i32.add |
| 30 |
(call $recursive (i32.sub (local.get 0) (i32.const 2))) |
| 31 |
i32.add |
| 32 |
|
| 33 |
(call $recursive (i32.sub (local.get 0) (i32.const 1))) |
| 34 |
i32.add |
| 35 |
(call $recursive (i32.sub (local.get 0) (i32.const 2))) |
| 36 |
i32.add |
| 37 |
|
| 38 |
(call $recursive (i32.sub (local.get 0) (i32.const 1))) |
| 39 |
i32.add |
| 40 |
(call $recursive (i32.sub (local.get 0) (i32.const 2))) |
| 41 |
i32.add |
| 42 |
|
| 43 |
(call $recursive (i32.sub (local.get 0) (i32.const 1))) |
| 44 |
i32.add |
| 45 |
(call $recursive (i32.sub (local.get 0) (i32.const 2))) |
| 46 |
i32.add |
| 47 |
end |
| 48 |
) |
| 49 |
)`; |
| 50 |
|
| 51 |
let i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(t))); |
| 52 |
|
| 53 |
assertEq(i.exports.recursive(10), 14517361); |
| 54 |
|
| 55 |
// This assertion will fail if there is runaway recursion, because the |
| 56 |
// optimised compilation will run long and hence not be completed by the time |
| 57 |
// the assertion is evaluated. |
| 58 |
assertEq(wasmFunctionTier(i.exports.recursive), "optimized"); |