Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ir/possible-contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions test/lit/passes/gufa-strings.wast
Original file line number Diff line number Diff line change
@@ -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)
)
)
)