summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-reduce.cpp13
-rw-r--r--src/wasm-builder.h18
2 files changed, 26 insertions, 5 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index ac00ce045..6ba5c5b83 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -566,14 +566,14 @@ struct Reducer
}
}
}
- // If that didn't work, try to replace with a child + a unary conversion
- if (curr->type.isConcrete() &&
- !curr->is<Unary>()) { // but not if it's already unary
+ // If that didn't work, try to replace with a child + a unary conversion,
+ // but not if it's already unary
+ if (curr->type.isSingle() && !curr->is<Unary>()) {
for (auto* child : ChildIterator(curr)) {
if (child->type == curr->type) {
continue; // already tried
}
- if (!child->type.isConcrete()) {
+ if (!child->type.isSingle()) {
continue; // no conversion
}
Expression* fixed = nullptr;
@@ -1013,6 +1013,11 @@ struct Reducer
RefNull* n = builder->makeRefNull();
return tryToReplaceCurrent(n);
}
+ if (curr->type.isMulti()) {
+ Expression* n =
+ builder->makeConstExpression(Literal::makeZero(curr->type));
+ return tryToReplaceCurrent(n);
+ }
Const* c = builder->makeConst(Literal(int32_t(0)));
if (tryToReplaceCurrent(c)) {
return true;
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 1acdc40c8..f77b0577c 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -601,7 +601,7 @@ public:
ret->finalize();
return ret;
}
- TupleMake* makeTupleMake(std::vector<Expression*>&& operands) {
+ template<typename ListType> TupleMake* makeTupleMake(ListType&& operands) {
auto* ret = allocator.alloc<TupleMake>();
ret->operands.set(operands);
ret->finalize();
@@ -639,6 +639,19 @@ public:
}
}
+ Expression* makeConstExpression(Literals values) {
+ assert(values.size() > 0);
+ if (values.size() == 1) {
+ return makeConstExpression(values[0]);
+ } else {
+ std::vector<Expression*> consts;
+ for (auto value : values) {
+ consts.push_back(makeConstExpression(value));
+ }
+ return makeTupleMake(consts);
+ }
+ }
+
// Additional utility functions for building on top of nodes
// Convenient to have these on Builder, as it has allocation built in
@@ -784,6 +797,9 @@ public:
// minimal contents. as a replacement, this may reuse the
// input node
template<typename T> Expression* replaceWithIdenticalType(T* curr) {
+ if (curr->type.isMulti()) {
+ return makeConstExpression(Literal::makeZero(curr->type));
+ }
Literal value;
// TODO: reuse node conditionally when possible for literals
switch (curr->type.getSingle()) {