unroll1.js (1292B)
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 5 let t = ` 6 (module 7 (func (export "f1") (param $limit i32) (result i32) 8 (local $x i32) 9 (local $y i32) 10 (local.set $x (i32.const 1)) 11 (local.set $y (i32.const 1000)) 12 (loop $cont 13 ;; x = x + 1 14 (local.set $x (i32.add (local.get $x) (i32.const 1))) 15 ;; y = y - 7 16 (local.set $y (i32.sub (local.get $x) (i32.const 7))) 17 ;; 18 (br_if $cont (i32.lt_u (local.get $x) (local.get $limit))) 19 ) 20 (i32.mul (local.get $x) (local.get $y)) 21 ) 22 )`; 23 24 let i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(t))); 25 26 // Run the loop some varying number of times, with the aim of exiting it at 27 // each copy of the loop, so as to check that the post-loop values of `x` and 28 // `y` are correct, regardless of which copy of the original loop exited. 29 30 assertEq(i.exports.f1(100), 9300); 31 assertEq(i.exports.f1(101), 9494); 32 assertEq(i.exports.f1(102), 9690); 33 assertEq(i.exports.f1(103), 9888); 34 assertEq(i.exports.f1(104), 10088); 35 assertEq(i.exports.f1(105), 10290); 36 assertEq(i.exports.f1(106), 10494); 37 assertEq(i.exports.f1(107), 10700); 38 assertEq(i.exports.f1(108), 10908); 39 assertEq(i.exports.f1(109), 11118);