[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
This commit is contained in:
parent
5c30bc8585
commit
5d54e89ad6
@ -600,6 +600,7 @@ Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {
|
||||
return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
|
||||
}
|
||||
if (m.right().IsPowerOf2()) { // x / 2^n => x >> n
|
||||
node->TrimInputCount(2);
|
||||
node->set_op(machine()->Word32Shr());
|
||||
node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value())));
|
||||
return Changed(node);
|
||||
@ -665,6 +666,7 @@ Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
|
||||
base::bits::UnsignedMod32(m.left().Value(), m.right().Value()));
|
||||
}
|
||||
if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1
|
||||
node->TrimInputCount(2);
|
||||
node->set_op(machine()->Word32And());
|
||||
node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1));
|
||||
return Changed(node);
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "src/compiler/graph-inl.h"
|
||||
#include "src/compiler/js-graph.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 "test/cctest/compiler/value-helper.h"
|
||||
|
||||
@ -97,7 +99,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
template <typename T>
|
||||
void CheckFoldBinop(volatile T expect, Node* a, Node* b) {
|
||||
CHECK_NE(NULL, binop);
|
||||
Node* n = graph.NewNode(binop, a, b);
|
||||
Node* n = CreateBinopNode(a, b);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction reduction = reducer.Reduce(n);
|
||||
CHECK(reduction.Changed());
|
||||
@ -109,7 +111,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
// the {expect} node.
|
||||
void CheckBinop(Node* expect, Node* a, Node* b) {
|
||||
CHECK_NE(NULL, binop);
|
||||
Node* n = graph.NewNode(binop, a, b);
|
||||
Node* n = CreateBinopNode(a, b);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction reduction = reducer.Reduce(n);
|
||||
CHECK(reduction.Changed());
|
||||
@ -121,7 +123,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
void CheckFoldBinop(Node* left_expect, Node* right_expect, Node* left,
|
||||
Node* right) {
|
||||
CHECK_NE(NULL, binop);
|
||||
Node* n = graph.NewNode(binop, left, right);
|
||||
Node* n = CreateBinopNode(left, right);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction reduction = reducer.Reduce(n);
|
||||
CHECK(reduction.Changed());
|
||||
@ -136,7 +138,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
void CheckFoldBinop(volatile T left_expect, const Operator* op_expect,
|
||||
Node* right_expect, Node* left, Node* right) {
|
||||
CHECK_NE(NULL, binop);
|
||||
Node* n = graph.NewNode(binop, left, right);
|
||||
Node* n = CreateBinopNode(left, right);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction r = reducer.Reduce(n);
|
||||
CHECK(r.Changed());
|
||||
@ -151,11 +153,13 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
void CheckFoldBinop(Node* left_expect, const Operator* op_expect,
|
||||
volatile T right_expect, Node* left, Node* right) {
|
||||
CHECK_NE(NULL, binop);
|
||||
Node* n = graph.NewNode(binop, left, right);
|
||||
Node* n = CreateBinopNode(left, right);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction r = reducer.Reduce(n);
|
||||
CHECK(r.Changed());
|
||||
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(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op()));
|
||||
}
|
||||
@ -168,7 +172,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
Node* p = Parameter();
|
||||
Node* k = Constant<T>(constant);
|
||||
{
|
||||
Node* n = graph.NewNode(binop, k, p);
|
||||
Node* n = CreateBinopNode(k, p);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction reduction = reducer.Reduce(n);
|
||||
CHECK(!reduction.Changed() || reduction.replacement() == n);
|
||||
@ -176,7 +180,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
CHECK_EQ(k, n->InputAt(1));
|
||||
}
|
||||
{
|
||||
Node* n = graph.NewNode(binop, p, k);
|
||||
Node* n = CreateBinopNode(p, k);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction reduction = reducer.Reduce(n);
|
||||
CHECK(!reduction.Changed());
|
||||
@ -192,7 +196,7 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
CHECK(!binop->HasProperty(Operator::kCommutative));
|
||||
Node* p = Parameter();
|
||||
Node* k = Constant<T>(constant);
|
||||
Node* n = graph.NewNode(binop, k, p);
|
||||
Node* n = CreateBinopNode(k, p);
|
||||
MachineOperatorReducer reducer(&jsgraph);
|
||||
Reduction reduction = reducer.Reduce(n);
|
||||
CHECK(!reduction.Changed());
|
||||
@ -203,6 +207,15 @@ class ReducerTester : public HandleAndZoneScope {
|
||||
Node* Parameter(int32_t index = 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user