|
| 1 | +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. |
| 2 | + |
| 3 | +;; RUN: foreach %s %t wasm-opt --propagate-globals-globally -all -S -o - | filecheck %s |
| 4 | +;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s --check-prefix SIMGB |
| 5 | + |
| 6 | +;; Check that propagate-globals-globally propagates constants globally but not |
| 7 | +;; to code. Also run simplify-globals for comparison, which does do that. |
| 8 | + |
| 9 | +(module |
| 10 | + ;; CHECK: (type $struct (struct (field stringref) (field stringref))) |
| 11 | + ;; SIMGB: (type $struct (struct (field stringref) (field stringref))) |
| 12 | + (type $struct (struct stringref stringref)) |
| 13 | + |
| 14 | + ;; CHECK: (type $1 (func)) |
| 15 | + |
| 16 | + ;; CHECK: (global $A i32 (i32.const 42)) |
| 17 | + ;; SIMGB: (type $1 (func)) |
| 18 | + |
| 19 | + ;; SIMGB: (global $A i32 (i32.const 42)) |
| 20 | + (global $A i32 (i32.const 42)) |
| 21 | + |
| 22 | + ;; CHECK: (global $B i32 (i32.const 42)) |
| 23 | + ;; SIMGB: (global $B i32 (i32.const 42)) |
| 24 | + (global $B i32 (global.get $A)) |
| 25 | + |
| 26 | + ;; CHECK: (global $C i32 (i32.add |
| 27 | + ;; CHECK-NEXT: (i32.const 42) |
| 28 | + ;; CHECK-NEXT: (i32.const 42) |
| 29 | + ;; CHECK-NEXT: )) |
| 30 | + ;; SIMGB: (global $C i32 (i32.add |
| 31 | + ;; SIMGB-NEXT: (i32.const 42) |
| 32 | + ;; SIMGB-NEXT: (i32.const 42) |
| 33 | + ;; SIMGB-NEXT: )) |
| 34 | + (global $C i32 (i32.add |
| 35 | + ;; Both of these can be optimized, including $B which reads from $A. |
| 36 | + (global.get $B) |
| 37 | + (global.get $A) |
| 38 | + )) |
| 39 | + |
| 40 | + ;; CHECK: (global $D (ref string) (string.const "foo")) |
| 41 | + ;; SIMGB: (global $D (ref string) (string.const "foo")) |
| 42 | + (global $D (ref string) (string.const "foo")) |
| 43 | + |
| 44 | + ;; CHECK: (global $E (ref string) (string.const "bar")) |
| 45 | + ;; SIMGB: (global $E (ref string) (string.const "bar")) |
| 46 | + (global $E (ref string) (string.const "bar")) |
| 47 | + |
| 48 | + ;; CHECK: (global $G (ref $struct) (struct.new $struct |
| 49 | + ;; CHECK-NEXT: (string.const "foo") |
| 50 | + ;; CHECK-NEXT: (string.const "bar") |
| 51 | + ;; CHECK-NEXT: )) |
| 52 | + ;; SIMGB: (global $G (ref $struct) (struct.new $struct |
| 53 | + ;; SIMGB-NEXT: (string.const "foo") |
| 54 | + ;; SIMGB-NEXT: (string.const "bar") |
| 55 | + ;; SIMGB-NEXT: )) |
| 56 | + (global $G (ref $struct) (struct.new $struct |
| 57 | + (global.get $D) |
| 58 | + (global.get $E) |
| 59 | + )) |
| 60 | + |
| 61 | + ;; CHECK: (func $test (type $1) |
| 62 | + ;; CHECK-NEXT: (drop |
| 63 | + ;; CHECK-NEXT: (global.get $A) |
| 64 | + ;; CHECK-NEXT: ) |
| 65 | + ;; CHECK-NEXT: (drop |
| 66 | + ;; CHECK-NEXT: (global.get $B) |
| 67 | + ;; CHECK-NEXT: ) |
| 68 | + ;; CHECK-NEXT: (drop |
| 69 | + ;; CHECK-NEXT: (global.get $C) |
| 70 | + ;; CHECK-NEXT: ) |
| 71 | + ;; CHECK-NEXT: (drop |
| 72 | + ;; CHECK-NEXT: (global.get $D) |
| 73 | + ;; CHECK-NEXT: ) |
| 74 | + ;; CHECK-NEXT: ) |
| 75 | + ;; SIMGB: (func $test (type $1) |
| 76 | + ;; SIMGB-NEXT: (drop |
| 77 | + ;; SIMGB-NEXT: (i32.const 42) |
| 78 | + ;; SIMGB-NEXT: ) |
| 79 | + ;; SIMGB-NEXT: (drop |
| 80 | + ;; SIMGB-NEXT: (i32.const 42) |
| 81 | + ;; SIMGB-NEXT: ) |
| 82 | + ;; SIMGB-NEXT: (drop |
| 83 | + ;; SIMGB-NEXT: (global.get $C) |
| 84 | + ;; SIMGB-NEXT: ) |
| 85 | + ;; SIMGB-NEXT: (drop |
| 86 | + ;; SIMGB-NEXT: (string.const "foo") |
| 87 | + ;; SIMGB-NEXT: ) |
| 88 | + ;; SIMGB-NEXT: ) |
| 89 | + (func $test |
| 90 | + ;; We should not change anything here: this pass propagates globals |
| 91 | + ;; *globally*, and not to functions. (but simplify-globals does, except for |
| 92 | + ;; $C which is not constant) |
| 93 | + (drop |
| 94 | + (global.get $A) |
| 95 | + ) |
| 96 | + (drop |
| 97 | + (global.get $B) |
| 98 | + ) |
| 99 | + (drop |
| 100 | + (global.get $C) |
| 101 | + ) |
| 102 | + (drop |
| 103 | + (global.get $D) |
| 104 | + ) |
| 105 | + ) |
| 106 | +) |
0 commit comments