summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/SignaturePruning.cpp13
-rw-r--r--test/lit/passes/signature-pruning.wast38
2 files changed, 51 insertions, 0 deletions
diff --git a/src/passes/SignaturePruning.cpp b/src/passes/SignaturePruning.cpp
index ecf6d7e21..ca7bd0548 100644
--- a/src/passes/SignaturePruning.cpp
+++ b/src/passes/SignaturePruning.cpp
@@ -28,6 +28,7 @@
//
#include "ir/find_all.h"
+#include "ir/intrinsics.h"
#include "ir/lubs.h"
#include "ir/module-utils.h"
#include "ir/type-updating.h"
@@ -103,6 +104,18 @@ struct SignaturePruning : public Pass {
// called.
for (auto* call : info.calls) {
allInfo[module->getFunction(call->target)->type].calls.push_back(call);
+
+ // Intrinsics limit our ability to optimize in some cases. We will avoid
+ // modifying any type that is used by call.without.effects, to avoid
+ // the complexity of handling that. After intrinsics are lowered,
+ // this optimization will be able to run at full power anyhow.
+ if (Intrinsics(*module).isCallWithoutEffects(call)) {
+ // The last operand is the actual call target.
+ auto* target = call->operands.back();
+ if (target->type != Type::unreachable) {
+ allInfo[target->type.getHeapType()].optimizable = false;
+ }
+ }
}
// For indirect calls, add each call_ref to the type the call_ref uses.
diff --git a/test/lit/passes/signature-pruning.wast b/test/lit/passes/signature-pruning.wast
index 3c4500eaf..79f658007 100644
--- a/test/lit/passes/signature-pruning.wast
+++ b/test/lit/passes/signature-pruning.wast
@@ -810,3 +810,41 @@
)
)
)
+
+;; Do not prune signatures used in the call.without.effects intrinsic.
+(module
+ ;; CHECK: (type $i32_funcref_=>_i32 (func_subtype (param i32 funcref) (result i32) func))
+
+ ;; CHECK: (type $i32_=>_i32 (func_subtype (param i32) (result i32) func))
+
+ ;; CHECK: (type $none_=>_i32 (func_subtype (result i32) func))
+
+ ;; CHECK: (import "binaryen-intrinsics" "call.without.effects" (func $cwe (param i32 funcref) (result i32)))
+ (import "binaryen-intrinsics" "call.without.effects" (func $cwe (param i32 funcref) (result i32)))
+
+ ;; CHECK: (elem declare func $func)
+
+ ;; CHECK: (func $func (type $i32_=>_i32) (param $0 i32) (result i32)
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: )
+ (func $func (param i32) (result i32)
+ ;; The parameter is unused, so we want to prune it. We won't because of the
+ ;; situation in the calling function, below.
+ (i32.const 1)
+ )
+
+ ;; CHECK: (func $caller (type $none_=>_i32) (result i32)
+ ;; CHECK-NEXT: (call $cwe
+ ;; CHECK-NEXT: (i32.const 41)
+ ;; CHECK-NEXT: (ref.func $func)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $caller (result i32)
+ ;; We call $func using call.without.effects. This causes us to not optimize
+ ;; in this case.
+ (call $cwe
+ (i32.const 41)
+ (ref.func $func)
+ )
+ )
+)