unroll8.js (1423B)
1 // |jit-test| skip-if: wasmCompileMode() != "ion" 2 3 // Check that the unroller properly takes account of dependencies 4 // through memory. See bug 1972116. 5 6 let t = ` 7 (module 8 (type $structTy (struct (field (mut f32)))) 9 (func (export "badness") (param $struct (ref null $structTy)) (result f32) 10 (local $f f32) 11 (local $i i32) 12 (block $break 13 (loop $cont 14 ;; f = struct->field0 15 (local.set $f (struct.get $structTy 0 (local.get $struct))) 16 ;; f = f + 360.0 17 (local.set $f (f32.add (local.get $f) (f32.const 360.0))) 18 ;; struct->field0 = f 19 (struct.set $structTy 0 (local.get $struct) (local.get $f)) 20 ;; loop control 21 (local.set $i (i32.add (local.get $i) (i32.const 1))) 22 (br_if $cont (i32.lt_u (local.get $i) (i32.const 12345))) 23 ) 24 ) 25 (struct.get $structTy 0 (local.get $struct)) 26 ) 27 28 (func (export "go") (result f32) 29 (struct.new_default $structTy) 30 (call 0) 31 ) 32 )`; 33 34 let i = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(t))); 35 36 // The correct result is 4444200. If the loop is unrolled and peeled without 37 // regard to dependencies through memory, and then GVNd, an observed incorrect 38 // result is 360, because the struct.gets in the unrolled iterations end up 39 // being GVNd out and replaced by the value of 0.0 returned by the struct.get 40 // in the peeled iteration. 41 assertEq(i.exports.go(), 4444200);