Revision: 25180
Author: [email protected]
Date: Thu Nov 6 09:09:50 2014 UTC
Log: [turbofan] Turn various diamonds into selects.
TEST=cctest/test-changes-lowering,mjsunit/asm,unittests
[email protected]
Review URL: https://codereview.chromium.org/704463004
https://code.google.com/p/v8/source/detail?r=25180
Modified:
/branches/bleeding_edge/src/compiler/change-lowering.cc
/branches/bleeding_edge/src/compiler/js-builtin-reducer.cc
/branches/bleeding_edge/src/compiler/machine-operator-reducer.cc
/branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
/branches/bleeding_edge/test/unittests/compiler/change-lowering-unittest.cc
/branches/bleeding_edge/test/unittests/compiler/js-builtin-reducer-unittest.cc
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
=======================================
--- /branches/bleeding_edge/src/compiler/change-lowering.cc Tue Nov 4
14:37:22 2014 UTC
+++ /branches/bleeding_edge/src/compiler/change-lowering.cc Thu Nov 6
09:09:50 2014 UTC
@@ -102,11 +102,10 @@
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()));
}
=======================================
--- /branches/bleeding_edge/src/compiler/js-builtin-reducer.cc Tue Nov 4
14:37:22 2014 UTC
+++ /branches/bleeding_edge/src/compiler/js-builtin-reducer.cc Thu Nov 6
09:09:50 2014 UTC
@@ -105,12 +105,12 @@
}
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 @@
// 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);
}
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Thu
Nov 6 06:13:10 2014 UTC
+++ /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Thu
Nov 6 09:09:50 2014 UTC
@@ -644,13 +644,12 @@
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());
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
Mon Oct 27 22:33:52 2014 UTC
+++ /branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
Thu Nov 6 09:09:50 2014 UTC
@@ -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 @@
// 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);
}
=======================================
---
/branches/bleeding_edge/test/unittests/compiler/change-lowering-unittest.cc
Tue Nov 4 12:58:17 2014 UTC
+++
/branches/bleeding_edge/test/unittests/compiler/change-lowering-unittest.cc
Thu Nov 6 09:09:50 2014 UTC
@@ -124,15 +124,9 @@
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()));
}
=======================================
---
/branches/bleeding_edge/test/unittests/compiler/js-builtin-reducer-unittest.cc
Thu Oct 30 14:15:20 2014 UTC
+++
/branches/bleeding_edge/test/unittests/compiler/js-builtin-reducer-unittest.cc
Thu Nov 6 09:09:50 2014 UTC
@@ -88,14 +88,9 @@
} 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 @@
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());
=======================================
---
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
Thu Nov 6 06:13:10 2014 UTC
+++
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
Thu Nov 6 09:09:50 2014 UTC
@@ -876,44 +876,30 @@
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;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.