diff options
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 3 | ||||
-rw-r--r-- | test/lit/passes/optimize-instructions-gc-tnh.wast | 42 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index f5a0c6756..3a5f56be9 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -1644,7 +1644,8 @@ struct OptimizeInstructions builder.makeDrop(select->condition))); return false; } - if (select->ifFalse->type.isNull()) { + if (select->ifFalse->type.isNull() && + select->ifTrue->type != Type::unreachable) { ref = getResultOfFirst( select->ifTrue, builder.makeSequence(builder.makeDrop(select->ifFalse), diff --git a/test/lit/passes/optimize-instructions-gc-tnh.wast b/test/lit/passes/optimize-instructions-gc-tnh.wast index 5815f8e1f..7902c2161 100644 --- a/test/lit/passes/optimize-instructions-gc-tnh.wast +++ b/test/lit/passes/optimize-instructions-gc-tnh.wast @@ -817,6 +817,48 @@ ) ) + ;; TNH: (func $select.unreachable.child.flip (type $none_=>_ref|$struct|) (result (ref $struct)) + ;; TNH-NEXT: (select + ;; TNH-NEXT: (unreachable) + ;; TNH-NEXT: (ref.as_non_null + ;; TNH-NEXT: (ref.null none) + ;; TNH-NEXT: ) + ;; TNH-NEXT: (i32.const 1) + ;; TNH-NEXT: ) + ;; TNH-NEXT: ) + ;; NO_TNH: (func $select.unreachable.child.flip (type $none_=>_ref|$struct|) (result (ref $struct)) + ;; NO_TNH-NEXT: (select + ;; NO_TNH-NEXT: (block + ;; NO_TNH-NEXT: (drop + ;; NO_TNH-NEXT: (ref.as_non_null + ;; NO_TNH-NEXT: (ref.null none) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: (unreachable) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: (ref.as_non_null + ;; NO_TNH-NEXT: (ref.null none) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: (i32.const 1) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: ) + (func $select.unreachable.child.flip (result (ref $struct)) + ;; Flip case of the above. + (ref.cast $struct + (select (result (ref $struct)) + (ref.cast $struct + (ref.as_non_null + (ref.null none) + ) + ) + (ref.as_non_null + (ref.null none) + ) + (i32.const 1) + ) + ) + ) + ;; Helper functions. ;; TNH: (func $get-i32 (type $none_=>_i32) (result i32) |