| Index: src/compiler/simplified-operator-reducer.cc
|
| diff --git a/src/compiler/simplified-operator-reducer.cc b/src/compiler/simplified-operator-reducer.cc
|
| index 0868cab3fc7e57d11a75b92a3e515ee927f4864b..9d45e5b19261c39f5492687aa828588b3a63054c 100644
|
| --- a/src/compiler/simplified-operator-reducer.cc
|
| +++ b/src/compiler/simplified-operator-reducer.cc
|
| @@ -2,10 +2,13 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "src/compiler/simplified-operator-reducer.h"
|
| +
|
| +#include "src/compiler/access-builder.h"
|
| #include "src/compiler/js-graph.h"
|
| #include "src/compiler/machine-operator.h"
|
| #include "src/compiler/node-matchers.h"
|
| -#include "src/compiler/simplified-operator-reducer.h"
|
| +#include "src/compiler/node-properties-inl.h"
|
|
|
| namespace v8 {
|
| namespace internal {
|
| @@ -20,6 +23,8 @@ SimplifiedOperatorReducer::~SimplifiedOperatorReducer() {}
|
|
|
| Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
|
| switch (node->opcode()) {
|
| + case IrOpcode::kAnyToBoolean:
|
| + return ReduceAnyToBoolean(node);
|
| case IrOpcode::kBooleanNot: {
|
| HeapObjectMatcher<HeapObject> m(node->InputAt(0));
|
| if (m.Is(Unique<HeapObject>::CreateImmovable(factory()->false_value()))) {
|
| @@ -105,8 +110,36 @@ Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
|
| }
|
|
|
|
|
| +Reduction SimplifiedOperatorReducer::ReduceAnyToBoolean(Node* node) {
|
| + Node* const input = NodeProperties::GetValueInput(node, 0);
|
| + Type* const input_type = NodeProperties::GetBounds(input).upper;
|
| + if (input_type->Is(Type::Boolean())) {
|
| + // AnyToBoolean(x:boolean) => x
|
| + return Replace(input);
|
| + }
|
| + if (input_type->Is(Type::OrderedNumber())) {
|
| + // AnyToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x, #0))
|
| + Node* compare = graph()->NewNode(simplified()->NumberEqual(), input,
|
| + jsgraph()->ZeroConstant());
|
| + return Change(node, simplified()->BooleanNot(), compare);
|
| + }
|
| + if (input_type->Is(Type::String())) {
|
| + // AnyToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0))
|
| + FieldAccess const access = AccessBuilder::ForStringLength();
|
| + Node* length = graph()->NewNode(simplified()->LoadField(access), input,
|
| + graph()->start(), graph()->start());
|
| + Node* compare = graph()->NewNode(simplified()->NumberEqual(), length,
|
| + jsgraph()->ZeroConstant());
|
| + return Change(node, simplified()->BooleanNot(), compare);
|
| + }
|
| + return NoChange();
|
| +}
|
| +
|
| +
|
| Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op,
|
| Node* a) {
|
| + DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op));
|
| + DCHECK_LE(1, node->InputCount());
|
| node->set_op(op);
|
| node->ReplaceInput(0, a);
|
| return Changed(node);
|
| @@ -141,6 +174,11 @@ Factory* SimplifiedOperatorReducer::factory() const {
|
| }
|
|
|
|
|
| +CommonOperatorBuilder* SimplifiedOperatorReducer::common() const {
|
| + return jsgraph()->common();
|
| +}
|
| +
|
| +
|
| MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const {
|
| return jsgraph()->machine();
|
| }
|
|
|