1 ;; Test that optimizers don't do redundant-load, store-to-load, or dead-store
2 ;; optimizations when there are interfering stores, even of different types
3 ;; and to non-identical addresses.
8 (func (export "zero_everything")
9 (i32.store (i64.const 0) (i32.const 0))
10 (i32.store (i64.const 4) (i32.const 0))
11 (i32.store (i64.const 8) (i32.const 0))
12 (i32.store (i64.const 12) (i32.const 0))
15 (func (export "test_store_to_load") (result i32)
16 (i32.store (i64.const 8) (i32.const 0))
17 (f32.store (i64.const 5) (f32.const -0.0))
18 (i32.load (i64.const 8))
21 (func (export "test_redundant_load") (result i32)
24 (local.set $t (i32.load (i64.const 8)))
25 (i32.store (i64.const 5) (i32.const 0x80000000))
26 (local.set $s (i32.load (i64.const 8)))
27 (i32.add (local.get $t) (local.get $s))
30 (func (export "test_dead_store") (result f32)
32 (i32.store (i64.const 8) (i32.const 0x23232323))
33 (local.set $t (f32.load (i64.const 11)))
34 (i32.store (i64.const 8) (i32.const 0))
38 ;; A function named "malloc" which implementations nonetheless shouldn't
39 ;; assume behaves like C malloc.
40 (func $malloc (export "malloc")
46 ;; Call malloc twice, but unlike C malloc, we don't get non-aliasing pointers.
47 (func (export "malloc_aliasing")
51 (local.set $x (call $malloc (i64.const 4)))
52 (local.set $y (call $malloc (i64.const 4)))
53 (i32.store (local.get $x) (i32.const 42))
54 (i32.store (local.get $y) (i32.const 43))
55 (i32.load (local.get $x))
59 (assert_return (invoke "test_store_to_load") (i32.const 0x00000080))
60 (invoke "zero_everything")
61 (assert_return (invoke "test_redundant_load") (i32.const 0x00000080))
62 (invoke "zero_everything")
63 (assert_return (invoke "test_dead_store") (f32.const 0x1.18p-144))
64 (invoke "zero_everything")
65 (assert_return (invoke "malloc_aliasing") (i32.const 43))