[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
This commit is contained in:
bmeurer@chromium.org 2014-11-06 09:09:50 +00:00
parent abb5fd1ee1
commit 8798c410e1
7 changed files with 48 additions and 77 deletions

View File

@ -102,11 +102,10 @@ Node* ChangeLowering::LoadHeapNumberValue(Node* value, Node* control) {
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()));
}

View File

@ -105,12 +105,12 @@ Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
}
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();
}
@ -143,10 +143,11 @@ Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
// 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);
}

View File

@ -644,13 +644,12 @@ Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) {
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());

View File

@ -10,6 +10,7 @@
#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"
@ -126,9 +127,11 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
// 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);
}

View File

@ -124,15 +124,9 @@ TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBitToBool) {
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()));
}

View File

@ -88,14 +88,9 @@ TEST_F(JSBuiltinReducerTest, MathAbs) {
} 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)));
}
}
}
@ -171,15 +166,9 @@ TEST_F(JSBuiltinReducerTest, MathMax2) {
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());

View File

@ -876,44 +876,30 @@ TEST_F(MachineOperatorReducerTest, Int32ModWithConstant) {
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;