unroll4.js (1016B)
1 // |jit-test| test-also=--setpref=wasm_unroll_loops=true 2 3 // Loop unrolling test: 2 exiting values, 1 exit target => can be unrolled. 4 // `a` and `b` are swapped every iteration and correct unrolling depends on 5 // the phi nodes being treated as parallel assignments. 6 7 let t = ` 8 (module 9 (func (export "f1") (param $limit i32) (result i64) 10 (local $a i64) 11 (local $b i64) 12 (local $tmp i64) 13 (local $x i32) 14 (local.set $a (i64.const 12345)) 15 (local.set $b (i64.const 67890)) 16 (loop $cont 17 ;; swap a and b 18 (local.set $tmp (local.get $a)) 19 (local.set $a (local.get $b)) 20 (local.set $b (local.get $tmp)) 21 ;; x = x + 1 22 (local.set $x (i32.add (local.get $x) (i32.const 1))) 23 ;; 24 (br_if $cont (i32.lt_u (local.get $x) (local.get $limit))) 25 ) 26 (i64.sub (local.get $a) (local.get $b)) 27 ) 28 )`; 29 30 let i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(t))); 31 32 assertEq(i.exports.f1(100), -55545n); 33 assertEq(i.exports.f1(101), 55545n);