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
11 changes: 11 additions & 0 deletions src/ir/possible-contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,17 @@ void Flower::filterExpressionContents(PossibleContents& contents,
std::cout << "TNHOracle informs us that " << *exprLoc.expr << " contains "
<< maximalContents << "\n";
#endif

if (exprLoc.expr->is<ArrayLoad>()) {
// ArrayLoad cannot filter, as we can have writes of different sizes than
// the type of the location (e.g. write i32, do an i64.load). If there is
// any content, just report the maximal content, basically like a Memory.
if (!contents.isNone()) {
contents = maximalContents;
}
return;
}

contents.intersect(maximalContents);
if (contents.isNone()) {
// Nothing was left here at all.
Expand Down
61 changes: 61 additions & 0 deletions test/lit/passes/gufa-multibyte.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
;; 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 --closed-world -S -o - | filecheck %s

(module
;; CHECK: (type $0 (func))

;; CHECK: (type $array (array (mut i8)))
(type $array (array (mut i8)))

;; CHECK: (export "test" (func $test))

;; CHECK: (func $test (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.load32_u (type $array)
;; CHECK-NEXT: (array.new_default $array
;; CHECK-NEXT: (i32.const 69)
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test (export "test")
;; We initialize with i8s, and read an i64. That should not confuse us, and
;; we do not optimize here (though we could, in theory, if we tracked the
;; bytes and saw the i64 must be 0).
(drop
(i64.load32_u (type $array)
(array.new_default $array
(i32.const 69)
)
(i32.const 0)
)
)
)
)

(module
;; CHECK: (type $array (array (mut i8)))
(type $array (array (mut i8)))

;; CHECK: (type $1 (func (param (ref $array))))

;; CHECK: (export "test" (func $test))

;; CHECK: (func $test (type $1) (param $array (ref $array))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test (export "test") (param $array (ref $array))
;; As above, but now no $array is ever created (and we are in closed world).
;; We can optimize this to trap.
(drop
(i64.load32_u (type $array)
(local.get $array)
(i32.const 0)
)
)
)
)

Loading