summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/MergeSimilarFunctions.cpp5
-rw-r--r--test/lit/passes/merge-similar-functions_all-features.wast80
2 files changed, 83 insertions, 2 deletions
diff --git a/src/passes/MergeSimilarFunctions.cpp b/src/passes/MergeSimilarFunctions.cpp
index 8e039566a..525d7c38f 100644
--- a/src/passes/MergeSimilarFunctions.cpp
+++ b/src/passes/MergeSimilarFunctions.cpp
@@ -565,7 +565,9 @@ Function* EquivalentClass::createShared(Module* module,
operands.push_back(
ExpressionManipulator::flexibleCopy(operand, *module, copier));
}
- return builder.makeCallRef(paramExpr, operands, call->type);
+ auto returnType = module->getFunction(call->target)->getResults();
+ return builder.makeCallRef(
+ paramExpr, operands, returnType, call->isReturn);
}
}
}
@@ -616,6 +618,7 @@ EquivalentClass::replaceWithThunk(Builder& builder,
callOperands.push_back(value);
}
+ // TODO: make a return_call when possible?
auto ret = builder.makeCall(shared->name, callOperands, target->getResults());
target->vars.clear();
target->body = ret;
diff --git a/test/lit/passes/merge-similar-functions_all-features.wast b/test/lit/passes/merge-similar-functions_all-features.wast
index 873b6453a..15929894f 100644
--- a/test/lit/passes/merge-similar-functions_all-features.wast
+++ b/test/lit/passes/merge-similar-functions_all-features.wast
@@ -1,10 +1,16 @@
-;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt --all-features --merge-similar-functions -S -o - | filecheck %s
(module
+ ;; CHECK: (type $none_=>_none (func))
+
;; CHECK: (type $[i8] (array i8))
(type $[i8] (array i8))
+ ;; CHECK: (type $arrayref_=>_none (func (param arrayref)))
+
+ ;; CHECK: (type $ref|eq|_=>_none (func (param (ref eq))))
+
;; CHECK: (func $take-ref-null-array (type $arrayref_=>_none) (param $0 arrayref)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
@@ -86,5 +92,77 @@
(array.new_fixed $[i8])
)
)
+)
+
+;; Test that we can merge properly when there is a return_call.
+(module
+ ;; CHECK: (type $none_=>_i32 (func (result i32)))
+
+ ;; CHECK: (type $ref|none_->_i32|_=>_i32 (func (param (ref $none_=>_i32)) (result i32)))
+ ;; CHECK: (elem declare func $return_a $return_b)
+
+ ;; CHECK: (func $return_call_a (type $none_=>_i32) (result i32)
+ ;; CHECK-NEXT: (call $byn$mgfn-shared$return_call_a
+ ;; CHECK-NEXT: (ref.func $return_a)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $return_call_a (result i32)
+ (nop) (nop) (nop) (nop) (nop) (nop)
+ (nop) (nop) (nop) (nop) (nop) (nop)
+ (nop) (nop) (nop) (nop) (nop) (nop)
+ (return_call $return_a)
+ )
+
+ ;; CHECK: (func $return_call_b (type $none_=>_i32) (result i32)
+ ;; CHECK-NEXT: (call $byn$mgfn-shared$return_call_a
+ ;; CHECK-NEXT: (ref.func $return_b)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $return_call_b (result i32)
+ (nop) (nop) (nop) (nop) (nop) (nop)
+ (nop) (nop) (nop) (nop) (nop) (nop)
+ (nop) (nop) (nop) (nop) (nop) (nop)
+ ;; As above, but now use a return_call.
+ (return_call $return_b)
+ )
+
+ ;; CHECK: (func $return_a (type $none_=>_i32) (result i32)
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: )
+ (func $return_a (result i32)
+ ;; Helper function.
+ (i32.const 0)
+ )
+
+ ;; CHECK: (func $return_b (type $none_=>_i32) (result i32)
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: )
+ (func $return_b (result i32)
+ ;; Helper function.
+ (i32.const 1)
+ )
)
+;; CHECK: (func $byn$mgfn-shared$return_call_a (type $ref|none_->_i32|_=>_i32) (param $0 (ref $none_=>_i32)) (result i32)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: (return_call_ref $none_=>_i32
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )