1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.
;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s
;; A global that is written its initial value in all subsequent writes can
;; remove those writes.
(module
;; CHECK: (type $0 (func))
;; CHECK: (global $global-0 i32 (i32.const 0))
(global $global-0 (mut i32) (i32.const 0))
;; CHECK: (global $global-1 i32 (i32.const 1))
(global $global-1 (mut i32) (i32.const 1))
;; CHECK: (func $sets (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $sets
;; All these writes can be turned into drops.
(global.set $global-0 (i32.const 0))
(global.set $global-0 (i32.const 0))
(global.set $global-1 (i32.const 1))
(global.set $global-1 (i32.const 1))
)
;; CHECK: (func $gets (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $gets
;; Add gets to avoid other opts from removing the sets.
(drop (global.get $global-0))
(drop (global.get $global-1))
)
)
;; As above, but now we write other values.
(module
;; CHECK: (type $0 (func (param i32)))
;; CHECK: (type $1 (func))
;; CHECK: (global $global-0 (mut i32) (i32.const 0))
(global $global-0 (mut i32) (i32.const 0))
;; CHECK: (global $global-1 (mut i32) (i32.const 1))
(global $global-1 (mut i32) (i32.const 1))
;; CHECK: (func $sets (type $0) (param $unknown i32)
;; CHECK-NEXT: (global.set $global-0
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global-0
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global-1
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global-1
;; CHECK-NEXT: (local.get $unknown)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $sets (param $unknown i32)
(global.set $global-0 (i32.const 0))
(global.set $global-0 (i32.const 1)) ;; a non-init value
(global.set $global-1 (i32.const 1))
(global.set $global-1 (local.get $unknown)) ;; a totally unknown value
)
;; CHECK: (func $gets (type $1)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global-0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global-1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $gets
(drop (global.get $global-0))
(drop (global.get $global-1))
)
)
;; Globals without constant initial values.
(module
;; An imported global.
;; CHECK: (type $0 (func (param i32)))
;; CHECK: (type $1 (func))
;; CHECK: (import "env" "import_global" (global $global-0 i32))
(import "env" "import_global" (global $global-0 i32))
;; A global that initializes with another global.
;; CHECK: (global $global-1 (mut i32) (global.get $global-0))
(global $global-1 (mut i32) (global.get $global-0))
;; CHECK: (func $sets (type $0) (param $unknown i32)
;; CHECK-NEXT: (global.set $global-1
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $sets (param $unknown i32)
(global.set $global-1 (i32.const 1))
)
;; CHECK: (func $gets (type $1)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global-0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (global.get $global-1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $gets
;; Add gets to avoid other opts from removing the sets.
(drop (global.get $global-0))
(drop (global.get $global-1))
)
)
|