summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-validator.h14
-rw-r--r--src/wasm.h2
-rw-r--r--src/wasm/wasm.cpp29
-rw-r--r--test/passes/dce.txt20
4 files changed, 40 insertions, 25 deletions
diff --git a/src/wasm-validator.h b/src/wasm-validator.h
index 29787a510..b657b67a6 100644
--- a/src/wasm-validator.h
+++ b/src/wasm-validator.h
@@ -390,15 +390,7 @@ public:
}
void visitUnary(Unary *curr) {
shouldBeUnequal(curr->value->type, none, curr, "unaries must not receive a none as their input");
- switch (curr->op) {
- case EqZInt32:
- case EqZInt64: {
- shouldBeEqual(curr->type, i32, curr, "eqz must return i32");
- break;
- }
- default: {}
- }
- if (curr->value->type == unreachable) return;
+ if (curr->value->type == unreachable) return; // nothing to check
switch (curr->op) {
case ClzInt32:
case CtzInt32:
@@ -420,9 +412,7 @@ public:
case TruncFloat64:
case NearestFloat64:
case SqrtFloat64: {
- if (curr->value->type != unreachable) {
- shouldBeEqual(curr->value->type, curr->type, curr, "non-conversion unaries must return the same type");
- }
+ shouldBeEqual(curr->value->type, curr->type, curr, "non-conversion unaries must return the same type");
break;
}
case EqZInt32: {
diff --git a/src/wasm.h b/src/wasm.h
index 4804322b6..b23dab918 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -299,6 +299,8 @@ public:
Name default_;
Expression* condition;
Expression* value;
+
+ void finalize();
};
class Call : public SpecificExpression<Expression::CallId> {
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 36eff681f..96ca8fbc8 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -248,7 +248,9 @@ void Loop::finalize() {
void Break::finalize() {
if (condition) {
- if (value) {
+ if (condition->type == unreachable) {
+ type = unreachable;
+ } else if (value) {
type = value->type;
} else {
type = none;
@@ -258,6 +260,10 @@ void Break::finalize() {
}
}
+void Switch::finalize() {
+ type = unreachable;
+}
+
bool FunctionType::structuralComparison(FunctionType& b) {
if (result != b.result) return false;
if (params.size() != b.params.size()) return false;
@@ -286,6 +292,11 @@ void SetLocal::setTee(bool is) {
void Store::finalize() {
assert(valueType != none); // must be set
+ if (ptr->type == unreachable || value->type == unreachable) {
+ type = unreachable;
+ } else {
+ type = none;
+ }
}
Const* Const::set(Literal value_) {
@@ -299,6 +310,10 @@ bool Unary::isRelational() {
}
void Unary::finalize() {
+ if (value->type == unreachable) {
+ type = unreachable;
+ return;
+ }
switch (op) {
case ClzInt32:
case CtzInt32:
@@ -390,16 +405,22 @@ bool Binary::isRelational() {
void Binary::finalize() {
assert(left && right);
- if (isRelational()) {
+ if (left->type == unreachable || right->type == unreachable) {
+ type = unreachable;
+ } else if (isRelational()) {
type = i32;
} else {
- type = getReachableWasmType(left->type, right->type);
+ type = left->type;
}
}
void Select::finalize() {
assert(ifTrue && ifFalse);
- type = getReachableWasmType(ifTrue->type, ifFalse->type);
+ if (ifTrue->type == unreachable || ifFalse->type == unreachable || condition->type == unreachable) {
+ type = unreachable;
+ } else {
+ type = ifTrue->type;
+ }
}
void Host::finalize() {
diff --git a/test/passes/dce.txt b/test/passes/dce.txt
index 6aaad92b5..98f0ea177 100644
--- a/test/passes/dce.txt
+++ b/test/passes/dce.txt
@@ -235,7 +235,7 @@
(if
(i32.const 88)
(drop
- (block i32
+ (block
(drop
(i32.const 0)
)
@@ -250,7 +250,7 @@
(if
(i32.const 100)
(drop
- (block i32
+ (block
(drop
(i32.const 123)
)
@@ -264,7 +264,7 @@
(if
(i32.const 101)
(drop
- (block i32
+ (block
(drop
(i32.const 123)
)
@@ -367,7 +367,7 @@
(br $label$0
(block $label$1 i32
(drop
- (block i32
+ (block
(drop
(i32.const 4104)
)
@@ -390,12 +390,14 @@
(get_local $var$1)
)
(block $label$1 i64
- (call $call-unreach
- (i64.sub
- (get_local $var$0)
- (i64.const 1)
+ (block i64
+ (drop
+ (i64.sub
+ (get_local $var$0)
+ (i64.const 1)
+ )
)
- (block i64
+ (block
(drop
(block $block i64
(set_local $2