Skip to content
Open
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
1 change: 1 addition & 0 deletions src/passes/GUFA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ struct GUFAOptimizer
if (oracleType.isRef() && oracleType != curr->type &&
Type::isSubType(oracleType, curr->type)) {
replaceCurrent(Builder(*getModule()).makeRefCast(curr, oracleType));
optimized = true;
}
}
};
Expand Down
41 changes: 41 additions & 0 deletions test/lit/passes/gufa-cast-all.wast
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,44 @@
)
)
)

(module
;; CHECK: (type $struct (struct))
(type $struct (struct))

;; CHECK: (type $1 (func (result (ref $struct))))

;; CHECK: (global $g (mut (ref null $struct)) (struct.new_default $struct))
(global $g (mut (ref null $struct)) (struct.new $struct))

;; CHECK: (func $test (type $1) (result (ref $struct))
;; CHECK-NEXT: (ref.cast (ref (exact $struct))
;; CHECK-NEXT: (block $block (result (ref (exact $struct)))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (ref.cast (ref (exact $struct))
;; CHECK-NEXT: (br_on_cast $block (ref (exact $struct)) (ref (exact $struct))
;; CHECK-NEXT: (ref.cast (ref (exact $struct))
;; CHECK-NEXT: (global.get $g)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test (result (ref $struct))
(block $block (result (ref $struct))
(drop
(br_on_cast $block (ref null $struct) (ref $struct)
;; This will be cast to (ref (exact $struct)). We must refinalize to
;; update the br_on_cast output to (ref (exact $struct)) as well to
;; maintain the validation condition that the cast output is a subtype
;; of its input.
(global.get $g)
)
)
(unreachable)
)
)
)
Loading