From 44fa122bec913d66bc3ce1271bf4f63f6d5d31f2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 8 Jul 2022 16:16:15 -0700 Subject: [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). --- src/ir/bits.h | 10 +++++++--- src/ir/boolean.h | 38 +++++++++++++++++++++++++++++++++++++ src/ir/properties.h | 9 --------- src/passes/OptimizeInstructions.cpp | 1 + 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 src/ir/boolean.h (limited to 'src') 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 namespace wasm::Bits { @@ -125,6 +126,9 @@ struct DummyLocalInfoProvider { template Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider = nullptr) { + if (Properties::emitsBoolean(curr)) { + return 1; + } if (auto* c = curr->dynCast()) { 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()) { + return unary->isRelational(); + } else if (auto* binary = curr->dynCast()) { + return binary->isRelational(); + } else if (curr->is() || curr->is() || curr->is() || + curr->is()) { + 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()) { - return unary->isRelational(); - } else if (auto* binary = curr->dynCast()) { - 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 #include +#include #include #include #include -- cgit v1.2.3