Commit 5d54e89a authored by jarin@chromium.org's avatar jarin@chromium.org

[turbofan] Fix input count in Uint32Mod/Div reduction.

BUG=
R=bmeurer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#24997}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24997 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5c30bc85
...@@ -600,6 +600,7 @@ Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) { ...@@ -600,6 +600,7 @@ Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {
return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero)); return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
} }
if (m.right().IsPowerOf2()) { // x / 2^n => x >> n if (m.right().IsPowerOf2()) { // x / 2^n => x >> n
node->TrimInputCount(2);
node->set_op(machine()->Word32Shr()); node->set_op(machine()->Word32Shr());
node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value()))); node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value())));
return Changed(node); return Changed(node);
...@@ -665,6 +666,7 @@ Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) { ...@@ -665,6 +666,7 @@ Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
base::bits::UnsignedMod32(m.left().Value(), m.right().Value())); base::bits::UnsignedMod32(m.left().Value(), m.right().Value()));
} }
if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1 if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1
node->TrimInputCount(2);
node->set_op(machine()->Word32And()); node->set_op(machine()->Word32And());
node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1)); node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1));
return Changed(node); return Changed(node);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "src/compiler/graph-inl.h" #include "src/compiler/graph-inl.h"
#include "src/compiler/js-graph.h" #include "src/compiler/js-graph.h"
#include "src/compiler/machine-operator-reducer.h" #include "src/compiler/machine-operator-reducer.h"
#include "src/compiler/operator-properties.h"
#include "src/compiler/operator-properties-inl.h"
#include "src/compiler/typer.h" #include "src/compiler/typer.h"
#include "test/cctest/compiler/value-helper.h" #include "test/cctest/compiler/value-helper.h"
...@@ -97,7 +99,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -97,7 +99,7 @@ class ReducerTester : public HandleAndZoneScope {
template <typename T> template <typename T>
void CheckFoldBinop(volatile T expect, Node* a, Node* b) { void CheckFoldBinop(volatile T expect, Node* a, Node* b) {
CHECK_NE(NULL, binop); CHECK_NE(NULL, binop);
Node* n = graph.NewNode(binop, a, b); Node* n = CreateBinopNode(a, b);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction reduction = reducer.Reduce(n); Reduction reduction = reducer.Reduce(n);
CHECK(reduction.Changed()); CHECK(reduction.Changed());
...@@ -109,7 +111,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -109,7 +111,7 @@ class ReducerTester : public HandleAndZoneScope {
// the {expect} node. // the {expect} node.
void CheckBinop(Node* expect, Node* a, Node* b) { void CheckBinop(Node* expect, Node* a, Node* b) {
CHECK_NE(NULL, binop); CHECK_NE(NULL, binop);
Node* n = graph.NewNode(binop, a, b); Node* n = CreateBinopNode(a, b);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction reduction = reducer.Reduce(n); Reduction reduction = reducer.Reduce(n);
CHECK(reduction.Changed()); CHECK(reduction.Changed());
...@@ -121,7 +123,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -121,7 +123,7 @@ class ReducerTester : public HandleAndZoneScope {
void CheckFoldBinop(Node* left_expect, Node* right_expect, Node* left, void CheckFoldBinop(Node* left_expect, Node* right_expect, Node* left,
Node* right) { Node* right) {
CHECK_NE(NULL, binop); CHECK_NE(NULL, binop);
Node* n = graph.NewNode(binop, left, right); Node* n = CreateBinopNode(left, right);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction reduction = reducer.Reduce(n); Reduction reduction = reducer.Reduce(n);
CHECK(reduction.Changed()); CHECK(reduction.Changed());
...@@ -136,7 +138,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -136,7 +138,7 @@ class ReducerTester : public HandleAndZoneScope {
void CheckFoldBinop(volatile T left_expect, const Operator* op_expect, void CheckFoldBinop(volatile T left_expect, const Operator* op_expect,
Node* right_expect, Node* left, Node* right) { Node* right_expect, Node* left, Node* right) {
CHECK_NE(NULL, binop); CHECK_NE(NULL, binop);
Node* n = graph.NewNode(binop, left, right); Node* n = CreateBinopNode(left, right);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction r = reducer.Reduce(n); Reduction r = reducer.Reduce(n);
CHECK(r.Changed()); CHECK(r.Changed());
...@@ -151,11 +153,13 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -151,11 +153,13 @@ class ReducerTester : public HandleAndZoneScope {
void CheckFoldBinop(Node* left_expect, const Operator* op_expect, void CheckFoldBinop(Node* left_expect, const Operator* op_expect,
volatile T right_expect, Node* left, Node* right) { volatile T right_expect, Node* left, Node* right) {
CHECK_NE(NULL, binop); CHECK_NE(NULL, binop);
Node* n = graph.NewNode(binop, left, right); Node* n = CreateBinopNode(left, right);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction r = reducer.Reduce(n); Reduction r = reducer.Reduce(n);
CHECK(r.Changed()); CHECK(r.Changed());
CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode()); CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
CHECK_EQ(OperatorProperties::GetTotalInputCount(op_expect),
r.replacement()->InputCount());
CHECK_EQ(left_expect, r.replacement()->InputAt(0)); CHECK_EQ(left_expect, r.replacement()->InputAt(0));
CHECK_EQ(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op())); CHECK_EQ(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op()));
} }
...@@ -168,7 +172,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -168,7 +172,7 @@ class ReducerTester : public HandleAndZoneScope {
Node* p = Parameter(); Node* p = Parameter();
Node* k = Constant<T>(constant); Node* k = Constant<T>(constant);
{ {
Node* n = graph.NewNode(binop, k, p); Node* n = CreateBinopNode(k, p);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction reduction = reducer.Reduce(n); Reduction reduction = reducer.Reduce(n);
CHECK(!reduction.Changed() || reduction.replacement() == n); CHECK(!reduction.Changed() || reduction.replacement() == n);
...@@ -176,7 +180,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -176,7 +180,7 @@ class ReducerTester : public HandleAndZoneScope {
CHECK_EQ(k, n->InputAt(1)); CHECK_EQ(k, n->InputAt(1));
} }
{ {
Node* n = graph.NewNode(binop, p, k); Node* n = CreateBinopNode(p, k);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction reduction = reducer.Reduce(n); Reduction reduction = reducer.Reduce(n);
CHECK(!reduction.Changed()); CHECK(!reduction.Changed());
...@@ -192,7 +196,7 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -192,7 +196,7 @@ class ReducerTester : public HandleAndZoneScope {
CHECK(!binop->HasProperty(Operator::kCommutative)); CHECK(!binop->HasProperty(Operator::kCommutative));
Node* p = Parameter(); Node* p = Parameter();
Node* k = Constant<T>(constant); Node* k = Constant<T>(constant);
Node* n = graph.NewNode(binop, k, p); Node* n = CreateBinopNode(k, p);
MachineOperatorReducer reducer(&jsgraph); MachineOperatorReducer reducer(&jsgraph);
Reduction reduction = reducer.Reduce(n); Reduction reduction = reducer.Reduce(n);
CHECK(!reduction.Changed()); CHECK(!reduction.Changed());
...@@ -203,6 +207,15 @@ class ReducerTester : public HandleAndZoneScope { ...@@ -203,6 +207,15 @@ class ReducerTester : public HandleAndZoneScope {
Node* Parameter(int32_t index = 0) { Node* Parameter(int32_t index = 0) {
return graph.NewNode(common.Parameter(index), graph.start()); return graph.NewNode(common.Parameter(index), graph.start());
} }
private:
Node* CreateBinopNode(Node* left, Node* right) {
if (binop->ControlInputCount() > 0) {
return graph.NewNode(binop, left, right, graph.start());
} else {
return graph.NewNode(binop, left, right);
}
}
}; };
......
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