github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/memory_redundancy.wast (about)

     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.
     4  
     5  (module
     6    (memory 1 1)
     7  
     8    (func (export "zero_everything")
     9      (i32.store (i32.const 0) (i32.const 0))
    10      (i32.store (i32.const 4) (i32.const 0))
    11      (i32.store (i32.const 8) (i32.const 0))
    12      (i32.store (i32.const 12) (i32.const 0))
    13    )
    14  
    15    (func (export "test_store_to_load") (result i32)
    16      (i32.store (i32.const 8) (i32.const 0))
    17      (f32.store (i32.const 5) (f32.const -0.0))
    18      (i32.load (i32.const 8))
    19    )
    20  
    21    (func (export "test_redundant_load") (result i32)
    22      (local $t i32)
    23      (local $s i32)
    24      (local.set $t (i32.load (i32.const 8)))
    25      (i32.store (i32.const 5) (i32.const 0x80000000))
    26      (local.set $s (i32.load (i32.const 8)))
    27      (i32.add (local.get $t) (local.get $s))
    28    )
    29  
    30    (func (export "test_dead_store") (result f32)
    31      (local $t f32)
    32      (i32.store (i32.const 8) (i32.const 0x23232323))
    33      (local.set $t (f32.load (i32.const 11)))
    34      (i32.store (i32.const 8) (i32.const 0))
    35      (local.get $t)
    36    )
    37  
    38    ;; A function named "malloc" which implementations nonetheless shouldn't
    39    ;; assume behaves like C malloc.
    40    (func $malloc (export "malloc")
    41       (param $size i32)
    42       (result i32)
    43       (i32.const 16)
    44    )
    45  
    46    ;; Call malloc twice, but unlike C malloc, we don't get non-aliasing pointers.
    47    (func (export "malloc_aliasing")
    48       (result i32)
    49       (local $x i32)
    50       (local $y i32)
    51       (local.set $x (call $malloc (i32.const 4)))
    52       (local.set $y (call $malloc (i32.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))
    56    )
    57  )
    58  
    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))