Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) {
- Diamond d(graph(), common(), val);
- d.Chain(control);
- MachineType machine_type = static_cast<MachineType>(kTypeBool | kRepTagged);
- return Replace(d.Phi(machine_type, jsgraph()->TrueConstant(),
- jsgraph()->FalseConstant()));
+ MachineType const type = static_cast<MachineType>(kTypeBool | kRepTagged);
+ return Replace(graph()->NewNode(common()->Select(type), val,
+ jsgraph()->TrueConstant(),
+ jsgraph()->FalseConstant()));
}
}
if (r.InputsMatchOne(Type::Number())) {
// Math.abs(a:number) -> (a > 0 ? a : 0 - a)
- Node* value = r.left();
- Node* zero = jsgraph()->ZeroConstant();
- Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), zero, value);
- Diamond d(graph(), common(), cmp);
- Node* neg = graph()->NewNode(simplified()->NumberSubtract(), zero, value);
- return Replace(d.Phi(kMachNone, value, neg));
+ Node* const value = r.left();
+ Node* const zero = jsgraph()->ZeroConstant();
+ return Replace(graph()->NewNode(
+ common()->Select(kMachNone),
+ graph()->NewNode(simplified()->NumberLessThan(), zero, value), value,
+ graph()->NewNode(simplified()->NumberSubtract(), zero, value)));
}
return NoChange();
}
// Math.max(a:int32, b:int32, ...)
Node* value = r.GetJSCallInput(0);
for (int i = 1; i < r.GetJSCallArity(); i++) {
- Node* p = r.GetJSCallInput(i);
- Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), value, p);
- Diamond d(graph(), common(), cmp);
- value = d.Phi(kMachNone, p, value);
+ Node* const input = r.GetJSCallInput(i);
+ value = graph()->NewNode(
+ common()->Select(kMachNone),
+ graph()->NewNode(simplified()->NumberLessThan(), input, value), input,
+ value);
}
return Replace(value);
}
if (base::bits::IsPowerOfTwo32(divisor)) {
uint32_t const mask = divisor - 1;
Node* const zero = Int32Constant(0);
-
- Node* check =
- graph()->NewNode(machine()->Int32LessThan(), dividend, zero);
- Diamond d(graph(), common(), check, BranchHint::kFalse);
- Node* neg = Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask));
- Node* pos = Word32And(dividend, mask);
- d.OverwriteWithPhi(node, kMachInt32, neg, pos);
+ node->set_op(common()->Select(kMachInt32, BranchHint::kFalse));
+ node->ReplaceInput(
+ 0, graph()->NewNode(machine()->Int32LessThan(), dividend, zero));
+ node->ReplaceInput(
+ 1, Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)));
+ node->ReplaceInput(2, Word32And(dividend, mask));
} else {
Node* quotient = Int32Div(dividend, divisor);
node->set_op(machine()->Int32Sub());
#include "src/compiler/js-graph.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/pipeline.h"
+#include "src/compiler/select-lowering.h"
#include "src/compiler/simplified-lowering.h"
#include "src/compiler/verifier.h"
#include "src/execution.h"
// Run the graph reducer with changes lowering on a single node.
CompilationInfo info(this->isolate(), this->zone());
Linkage linkage(this->zone(), &info);
- ChangeLowering lowering(&jsgraph, &linkage);
+ ChangeLowering change_lowering(&jsgraph, &linkage);
+ SelectLowering select_lowering(this->graph(), this->common());
GraphReducer reducer(this->graph());
- reducer.AddReducer(&lowering);
+ reducer.AddReducer(&change_lowering);
+ reducer.AddReducer(&select_lowering);
reducer.ReduceNode(change);
Verifier::Run(this->graph(), Verifier::UNTYPED);
}
Node* node = graph()->NewNode(simplified()->ChangeBitToBool(), val);
Reduction reduction = Reduce(node);
ASSERT_TRUE(reduction.Changed());
-
- Node* phi = reduction.replacement();
- Capture<Node*> branch;
- EXPECT_THAT(phi,
- IsPhi(static_cast<MachineType>(kTypeBool | kRepTagged),
- IsTrueConstant(), IsFalseConstant(),
- IsMerge(IsIfTrue(AllOf(CaptureEq(&branch),
- IsBranch(val, graph()->start()))),
- IsIfFalse(CaptureEq(&branch)))));
+ EXPECT_THAT(reduction.replacement(),
+ IsSelect(static_cast<MachineType>(kTypeBool | kRepTagged), val,
+ IsTrueConstant(), IsFalseConstant()));
}
} else {
Capture<Node*> branch;
ASSERT_TRUE(r.Changed());
- EXPECT_THAT(
- r.replacement(),
- IsPhi(kMachNone, p0, IsNumberSubtract(IsNumberConstant(0), p0),
- IsMerge(IsIfTrue(CaptureEq(&branch)),
- IsIfFalse(AllOf(
- CaptureEq(&branch),
- IsBranch(IsNumberLessThan(IsNumberConstant(0), p0),
- graph()->start()))))));
+ EXPECT_THAT(r.replacement(),
+ IsSelect(kMachNone, IsNumberLessThan(IsNumberConstant(0), p0),
+ p0, IsNumberSubtract(IsNumberConstant(0), p0)));
}
}
}
Reduction r = Reduce(call);
if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
- Capture<Node*> branch;
ASSERT_TRUE(r.Changed());
- EXPECT_THAT(
- r.replacement(),
- IsPhi(kMachNone, p1, p0,
- IsMerge(IsIfTrue(CaptureEq(&branch)),
- IsIfFalse(AllOf(CaptureEq(&branch),
- IsBranch(IsNumberLessThan(p0, p1),
- graph()->start()))))));
+ EXPECT_THAT(r.replacement(),
+ IsSelect(kMachNone, IsNumberLessThan(p1, p0), p1, p0));
} else {
ASSERT_FALSE(r.Changed());
EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
Reduction const r =
Reduce(graph()->NewNode(machine()->Int32Mod(), p0,
Int32Constant(1 << shift), graph()->start()));
- ASSERT_TRUE(r.Changed());
-
- Capture<Node*> branch;
- Node* const phi = r.replacement();
int32_t const mask = (1 << shift) - 1;
+ ASSERT_TRUE(r.Changed());
EXPECT_THAT(
- phi, IsPhi(kMachInt32,
- IsInt32Sub(IsInt32Constant(0),
- IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
- IsInt32Constant(mask))),
- IsWord32And(p0, IsInt32Constant(mask)),
- IsMerge(IsIfTrue(CaptureEq(&branch)),
- IsIfFalse(AllOf(
- CaptureEq(&branch),
- IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)),
- graph()->start()))))));
+ r.replacement(),
+ IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)),
+ IsInt32Sub(IsInt32Constant(0),
+ IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
+ IsInt32Constant(mask))),
+ IsWord32And(p0, IsInt32Constant(mask))));
}
TRACED_FORRANGE(int32_t, shift, 1, 31) {
Reduction const r = Reduce(graph()->NewNode(
machine()->Int32Mod(), p0,
Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift),
graph()->start()));
- ASSERT_TRUE(r.Changed());
-
- Capture<Node*> branch;
- Node* const phi = r.replacement();
int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1);
+ ASSERT_TRUE(r.Changed());
EXPECT_THAT(
- phi, IsPhi(kMachInt32,
- IsInt32Sub(IsInt32Constant(0),
- IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
- IsInt32Constant(mask))),
- IsWord32And(p0, IsInt32Constant(mask)),
- IsMerge(IsIfTrue(CaptureEq(&branch)),
- IsIfFalse(AllOf(
- CaptureEq(&branch),
- IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)),
- graph()->start()))))));
+ r.replacement(),
+ IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)),
+ IsInt32Sub(IsInt32Constant(0),
+ IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
+ IsInt32Constant(mask))),
+ IsWord32And(p0, IsInt32Constant(mask))));
}
TRACED_FOREACH(int32_t, divisor, kInt32Values) {
if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue;