Debian Codegraph @

js/src/jit-test/tests/wasm/unroll3.js

raw
1 // |jit-test| test-also=--setpref=wasm_unroll_loops=true
2
3 // Loop unrolling test: 1 exiting value, 1 exit target => can be unrolled.
4 // The value defined in the loop, which is used after,
5 // is also phi'd with a value defined before the loop.
6
7 let t = `
8 (module
9 (func (export "f1") (param $enterloopP i32) (param $limit i32) (result i32)
10 (local $merge i32)
11 (local $x i32)
12 (local.set $merge (i32.const 5000))
13 (local.set $x (i32.const 1))
14 (if (i32.ne (local.get $enterloopP) (i32.const 0))
15 (then
16 (loop $cont
17 ;; x = x + 1
18 (local.set $x (i32.add (local.get $x) (i32.const 1)))
19 ;; merge = x
20 (local.set $merge (i32.add (local.get $x) (i32.const 1111)))
21 ;; continue if x < limit
22 (br_if $cont (i32.lt_u (local.get $x) (local.get $limit)))
23 )
24 )
25 )
26 (i32.mul (local.get $merge) (i32.const 17))
27 )
28 )`;
29
30 let i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(t)));
31
32 assertEq(i.exports.f1(0, 100), 85000); // loop not entered
33 assertEq(i.exports.f1(1, 100), 20587) // loop entered