diff options
-rw-r--r-- | src/ir/possible-contents.cpp | 3 | ||||
-rw-r--r-- | test/lit/passes/gufa-strings.wast | 59 |
2 files changed, 61 insertions, 1 deletions
diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index 2f900f0ed..8d6891017 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -1065,7 +1065,8 @@ struct InfoCollector addRoot(curr, PossibleContents::exactType(curr->type)); } void visitStringConst(StringConst* curr) { - addRoot(curr, PossibleContents::exactType(curr->type)); + addRoot(curr, + PossibleContents::literal(Literal(std::string(curr->string.str)))); } void visitStringMeasure(StringMeasure* curr) { // TODO: optimize when possible diff --git a/test/lit/passes/gufa-strings.wast b/test/lit/passes/gufa-strings.wast new file mode 100644 index 000000000..0501e3f56 --- /dev/null +++ b/test/lit/passes/gufa-strings.wast @@ -0,0 +1,59 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-opt -all --gufa -S -o - | filecheck %s + +(module + ;; CHECK: (type $0 (func)) + + ;; CHECK: (global $foo (mut (ref string)) (string.const "foo")) + (global $foo (mut (ref string)) (string.const "foo")) + + ;; CHECK: (global $bar (mut (ref string)) (string.const "bar")) + (global $bar (mut (ref string)) (string.const "bar")) + + ;; CHECK: (global $baz (mut (ref string)) (string.const "baz")) + (global $baz (mut (ref string)) (string.const "baz")) + + ;; CHECK: (func $set (type $0) + ;; CHECK-NEXT: (global.set $foo + ;; CHECK-NEXT: (string.const "foo") + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (global.set $bar + ;; CHECK-NEXT: (string.const "BAR_BAR_BAR") + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $set + ;; Modify $foo to the same value as it begins. + (global.set $foo + (string.const "foo") + ) + ;; Modify $bar to a new value + (global.set $bar + (string.const "BAR_BAR_BAR") + ) + ;; Do not modify $baz at all. + ) + + ;; CHECK: (func $get (type $0) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (string.const "foo") + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $bar) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (string.const "baz") + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $get + ;; $foo and $baz can be optimized, but not $bar. + (drop + (global.get $foo) + ) + (drop + (global.get $bar) + ) + (drop + (global.get $baz) + ) + ) +) |