Commit 8798c410 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Turn various diamonds into selects.

TEST=cctest/test-changes-lowering,mjsunit/asm,unittests
R=jarin@chromium.org

Review URL: https://codereview.chromium.org/704463004

Cr-Commit-Position: refs/heads/master@{#25180}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25180 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent abb5fd1e
...@@ -102,11 +102,10 @@ Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) { ...@@ -102,11 +102,10 @@ Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) {
Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) { Reduction ChangeLowering::ChangeBitToBool(Node* val, Node* control) {
Diamond d(graph(), common(), val); MachineType const type = static_cast<MachineType>(kTypeBool | kRepTagged);
d.Chain(control); return Replace(graph()->NewNode(common()->Select(type), val,
MachineType machine_type = static_cast<MachineType>(kTypeBool | kRepTagged); jsgraph()->TrueConstant(),
return Replace(d.Phi(machine_type, jsgraph()->TrueConstant(), jsgraph()->FalseConstant()));
jsgraph()->FalseConstant()));
} }
......
...@@ -105,12 +105,12 @@ Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) { ...@@ -105,12 +105,12 @@ Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
} }
if (r.InputsMatchOne(Type::Number())) { if (r.InputsMatchOne(Type::Number())) {
// Math.abs(a:number) -> (a > 0 ? a : 0 - a) // Math.abs(a:number) -> (a > 0 ? a : 0 - a)
Node* value = r.left(); Node* const value = r.left();
Node* zero = jsgraph()->ZeroConstant(); Node* const zero = jsgraph()->ZeroConstant();
Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), zero, value); return Replace(graph()->NewNode(
Diamond d(graph(), common(), cmp); common()->Select(kMachNone),
Node* neg = graph()->NewNode(simplified()->NumberSubtract(), zero, value); graph()->NewNode(simplified()->NumberLessThan(), zero, value), value,
return Replace(d.Phi(kMachNone, value, neg)); graph()->NewNode(simplified()->NumberSubtract(), zero, value)));
} }
return NoChange(); return NoChange();
} }
...@@ -143,10 +143,11 @@ Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { ...@@ -143,10 +143,11 @@ Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
// Math.max(a:int32, b:int32, ...) // Math.max(a:int32, b:int32, ...)
Node* value = r.GetJSCallInput(0); Node* value = r.GetJSCallInput(0);
for (int i = 1; i < r.GetJSCallArity(); i++) { for (int i = 1; i < r.GetJSCallArity(); i++) {
Node* p = r.GetJSCallInput(i); Node* const input = r.GetJSCallInput(i);
Node* cmp = graph()->NewNode(simplified()->NumberLessThan(), value, p); value = graph()->NewNode(
Diamond d(graph(), common(), cmp); common()->Select(kMachNone),
value = d.Phi(kMachNone, p, value); graph()->NewNode(simplified()->NumberLessThan(), input, value), input,
value);
} }
return Replace(value); return Replace(value);
} }
......
...@@ -644,13 +644,12 @@ Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) { ...@@ -644,13 +644,12 @@ Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) {
if (base::bits::IsPowerOfTwo32(divisor)) { if (base::bits::IsPowerOfTwo32(divisor)) {
uint32_t const mask = divisor - 1; uint32_t const mask = divisor - 1;
Node* const zero = Int32Constant(0); Node* const zero = Int32Constant(0);
node->set_op(common()->Select(kMachInt32, BranchHint::kFalse));
Node* check = node->ReplaceInput(
graph()->NewNode(machine()->Int32LessThan(), dividend, zero); 0, graph()->NewNode(machine()->Int32LessThan(), dividend, zero));
Diamond d(graph(), common(), check, BranchHint::kFalse); node->ReplaceInput(
Node* neg = Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)); 1, Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)));
Node* pos = Word32And(dividend, mask); node->ReplaceInput(2, Word32And(dividend, mask));
d.OverwriteWithPhi(node, kMachInt32, neg, pos);
} else { } else {
Node* quotient = Int32Div(dividend, divisor); Node* quotient = Int32Div(dividend, divisor);
node->set_op(machine()->Int32Sub()); node->set_op(machine()->Int32Sub());
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/compiler/js-graph.h" #include "src/compiler/js-graph.h"
#include "src/compiler/node-properties-inl.h" #include "src/compiler/node-properties-inl.h"
#include "src/compiler/pipeline.h" #include "src/compiler/pipeline.h"
#include "src/compiler/select-lowering.h"
#include "src/compiler/simplified-lowering.h" #include "src/compiler/simplified-lowering.h"
#include "src/compiler/verifier.h" #include "src/compiler/verifier.h"
#include "src/execution.h" #include "src/execution.h"
...@@ -126,9 +127,11 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> { ...@@ -126,9 +127,11 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
// Run the graph reducer with changes lowering on a single node. // Run the graph reducer with changes lowering on a single node.
CompilationInfo info(this->isolate(), this->zone()); CompilationInfo info(this->isolate(), this->zone());
Linkage linkage(this->zone(), &info); 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()); GraphReducer reducer(this->graph());
reducer.AddReducer(&lowering); reducer.AddReducer(&change_lowering);
reducer.AddReducer(&select_lowering);
reducer.ReduceNode(change); reducer.ReduceNode(change);
Verifier::Run(this->graph(), Verifier::UNTYPED); Verifier::Run(this->graph(), Verifier::UNTYPED);
} }
......
...@@ -124,15 +124,9 @@ TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBitToBool) { ...@@ -124,15 +124,9 @@ TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBitToBool) {
Node* node = graph()->NewNode(simplified()->ChangeBitToBool(), val); Node* node = graph()->NewNode(simplified()->ChangeBitToBool(), val);
Reduction reduction = Reduce(node); Reduction reduction = Reduce(node);
ASSERT_TRUE(reduction.Changed()); ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(),
Node* phi = reduction.replacement(); IsSelect(static_cast<MachineType>(kTypeBool | kRepTagged), val,
Capture<Node*> branch; IsTrueConstant(), IsFalseConstant()));
EXPECT_THAT(phi,
IsPhi(static_cast<MachineType>(kTypeBool | kRepTagged),
IsTrueConstant(), IsFalseConstant(),
IsMerge(IsIfTrue(AllOf(CaptureEq(&branch),
IsBranch(val, graph()->start()))),
IsIfFalse(CaptureEq(&branch)))));
} }
......
...@@ -88,14 +88,9 @@ TEST_F(JSBuiltinReducerTest, MathAbs) { ...@@ -88,14 +88,9 @@ TEST_F(JSBuiltinReducerTest, MathAbs) {
} else { } else {
Capture<Node*> branch; Capture<Node*> branch;
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT( EXPECT_THAT(r.replacement(),
r.replacement(), IsSelect(kMachNone, IsNumberLessThan(IsNumberConstant(0), p0),
IsPhi(kMachNone, p0, IsNumberSubtract(IsNumberConstant(0), p0), p0, IsNumberSubtract(IsNumberConstant(0), p0)));
IsMerge(IsIfTrue(CaptureEq(&branch)),
IsIfFalse(AllOf(
CaptureEq(&branch),
IsBranch(IsNumberLessThan(IsNumberConstant(0), p0),
graph()->start()))))));
} }
} }
} }
...@@ -171,15 +166,9 @@ TEST_F(JSBuiltinReducerTest, MathMax2) { ...@@ -171,15 +166,9 @@ TEST_F(JSBuiltinReducerTest, MathMax2) {
Reduction r = Reduce(call); Reduction r = Reduce(call);
if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) { if (t0->Is(Type::Integral32()) && t1->Is(Type::Integral32())) {
Capture<Node*> branch;
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT( EXPECT_THAT(r.replacement(),
r.replacement(), IsSelect(kMachNone, IsNumberLessThan(p1, p0), p1, p0));
IsPhi(kMachNone, p1, p0,
IsMerge(IsIfTrue(CaptureEq(&branch)),
IsIfFalse(AllOf(CaptureEq(&branch),
IsBranch(IsNumberLessThan(p0, p1),
graph()->start()))))));
} else { } else {
ASSERT_FALSE(r.Changed()); ASSERT_FALSE(r.Changed());
EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode()); EXPECT_EQ(IrOpcode::kJSCallFunction, call->opcode());
......
...@@ -876,44 +876,30 @@ TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) { ...@@ -876,44 +876,30 @@ TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) {
Reduction const r = Reduction const r =
Reduce(graph()->NewNode(machine()->Int32Mod(), p0, Reduce(graph()->NewNode(machine()->Int32Mod(), p0,
Int32Constant(1 << shift), graph()->start())); Int32Constant(1 << shift), graph()->start()));
ASSERT_TRUE(r.Changed());
Capture<Node*> branch;
Node* const phi = r.replacement();
int32_t const mask = (1 << shift) - 1; int32_t const mask = (1 << shift) - 1;
ASSERT_TRUE(r.Changed());
EXPECT_THAT( EXPECT_THAT(
phi, IsPhi(kMachInt32, r.replacement(),
IsInt32Sub(IsInt32Constant(0), IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)),
IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), IsInt32Sub(IsInt32Constant(0),
IsInt32Constant(mask))), IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
IsWord32And(p0, IsInt32Constant(mask)), IsInt32Constant(mask))),
IsMerge(IsIfTrue(CaptureEq(&branch)), IsWord32And(p0, IsInt32Constant(mask))));
IsIfFalse(AllOf(
CaptureEq(&branch),
IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)),
graph()->start()))))));
} }
TRACED_FORRANGE(int32_t, shift, 1, 31) { TRACED_FORRANGE(int32_t, shift, 1, 31) {
Reduction const r = Reduce(graph()->NewNode( Reduction const r = Reduce(graph()->NewNode(
machine()->Int32Mod(), p0, machine()->Int32Mod(), p0,
Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift), Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift),
graph()->start())); 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); int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1);
ASSERT_TRUE(r.Changed());
EXPECT_THAT( EXPECT_THAT(
phi, IsPhi(kMachInt32, r.replacement(),
IsInt32Sub(IsInt32Constant(0), IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)),
IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), IsInt32Sub(IsInt32Constant(0),
IsInt32Constant(mask))), IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
IsWord32And(p0, IsInt32Constant(mask)), IsInt32Constant(mask))),
IsMerge(IsIfTrue(CaptureEq(&branch)), IsWord32And(p0, IsInt32Constant(mask))));
IsIfFalse(AllOf(
CaptureEq(&branch),
IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)),
graph()->start()))))));
} }
TRACED_FOREACH(int32_t, divisor, kInt32Values) { TRACED_FOREACH(int32_t, divisor, kInt32Values) {
if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue; if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment