diff options
author | Alon Zakai <azakai@google.com> | 2022-07-08 16:16:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 16:16:15 -0700 |
commit | 44fa122bec913d66bc3ce1271bf4f63f6d5d31f2 (patch) | |
tree | 51afad3b7166a5acee0ee21a99818fd72a2657a2 /src | |
parent | 83f48ed96357cdde61d898ca05f201d38e6d4222 (diff) | |
download | binaryen-44fa122bec913d66bc3ce1271bf4f63f6d5d31f2.tar.gz binaryen-44fa122bec913d66bc3ce1271bf4f63f6d5d31f2.tar.bz2 binaryen-44fa122bec913d66bc3ce1271bf4f63f6d5d31f2.zip |
[Wasm GC] RefIs / RefEq / RefTest return a boolean (#4786)
This marks all reference operations that return 0/1 as doing so. This
allows various bitwise operations to be optimized on them.
This also marks StringEq as a boolean, though we can't test that fully yet
as Strings support is wip (no interpreter or other stuff yet).
As a driveby this moves emitsBoolean to its own file, and uses it
in getMaxBits to avoid redundancy (the redundant code paths now have
a WASM_UNREACHABLE).
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/bits.h | 10 | ||||
-rw-r--r-- | src/ir/boolean.h | 38 | ||||
-rw-r--r-- | src/ir/properties.h | 9 | ||||
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 1 |
4 files changed, 46 insertions, 12 deletions
diff --git a/src/ir/bits.h b/src/ir/bits.h index 21146b3d1..96b36a846 100644 --- a/src/ir/bits.h +++ b/src/ir/bits.h @@ -17,10 +17,11 @@ #ifndef wasm_ir_bits_h #define wasm_ir_bits_h +#include "ir/boolean.h" #include "ir/literal-utils.h" +#include "ir/load-utils.h" #include "support/bits.h" #include "wasm-builder.h" -#include <ir/load-utils.h> namespace wasm::Bits { @@ -125,6 +126,9 @@ struct DummyLocalInfoProvider { template<typename LocalInfoProvider = DummyLocalInfoProvider> Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider = nullptr) { + if (Properties::emitsBoolean(curr)) { + return 1; + } if (auto* c = curr->dynCast<Const>()) { switch (curr->type.getBasic()) { case Type::i32: @@ -363,7 +367,7 @@ Index getMaxBits(Expression* curr, case LeFloat64: case GtFloat64: case GeFloat64: - return 1; + WASM_UNREACHABLE("relationals handled before"); default: { } } @@ -379,7 +383,7 @@ Index getMaxBits(Expression* curr, return 7; case EqZInt32: case EqZInt64: - return 1; + WASM_UNREACHABLE("relationals handled before"); case WrapInt64: case ExtendUInt32: return std::min(Index(32), getMaxBits(unary->value, localInfoProvider)); diff --git a/src/ir/boolean.h b/src/ir/boolean.h new file mode 100644 index 000000000..58601c2ce --- /dev/null +++ b/src/ir/boolean.h @@ -0,0 +1,38 @@ +/* + * Copyright 2022 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef wasm_ir_boolean_h +#define wasm_ir_boolean_h + +#include "wasm.h" + +namespace wasm::Properties { + +inline bool emitsBoolean(Expression* curr) { + if (auto* unary = curr->dynCast<Unary>()) { + return unary->isRelational(); + } else if (auto* binary = curr->dynCast<Binary>()) { + return binary->isRelational(); + } else if (curr->is<RefIs>() || curr->is<RefEq>() || curr->is<RefTest>() || + curr->is<StringEq>()) { + return true; + } + return false; +} + +} // namespace wasm::Properties + +#endif // wasm_ir_boolean_h diff --git a/src/ir/properties.h b/src/ir/properties.h index 4f7fb96ca..3278d9e41 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -24,15 +24,6 @@ namespace wasm::Properties { -inline bool emitsBoolean(Expression* curr) { - if (auto* unary = curr->dynCast<Unary>()) { - return unary->isRelational(); - } else if (auto* binary = curr->dynCast<Binary>()) { - return binary->isRelational(); - } - return false; -} - inline bool isSymmetric(Binary* binary) { switch (binary->op) { case AddInt32: diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index a88e2a87f..5f18beb73 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -24,6 +24,7 @@ #include <ir/abstract.h> #include <ir/bits.h> +#include <ir/boolean.h> #include <ir/cost.h> #include <ir/drop.h> #include <ir/effects.h> |