Commit 3a089bf9 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Reduce (x & K) & K to x & K.

TEST=unittests
R=dcarney@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#24931}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24931 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d02f7210
...@@ -109,6 +109,15 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -109,6 +109,15 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceInt32(m.left().Value() & m.right().Value()); return ReplaceInt32(m.left().Value() & m.right().Value());
} }
if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x
if (m.left().IsWord32And() && m.right().HasValue()) {
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().HasValue()) { // (x & K) & K => x & K
node->ReplaceInput(0, mleft.left().node());
node->ReplaceInput(
1, Int32Constant(m.right().Value() & mleft.right().Value()));
return Changed(node);
}
}
break; break;
} }
case IrOpcode::kWord32Or: { case IrOpcode::kWord32Or: {
......
...@@ -481,6 +481,37 @@ TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithConstant) { ...@@ -481,6 +481,37 @@ TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithConstant) {
} }
// -----------------------------------------------------------------------------
// Word32And
TEST_F(MachineOperatorReducerTest, Word32AndWithWord32AndWithConstant) {
Node* const p0 = Parameter(0);
TRACED_FOREACH(int32_t, k, kInt32Values) {
TRACED_FOREACH(int32_t, l, kInt32Values) {
if (k == 0 || k == -1 || l == 0 || l == -1) continue;
// (x & K) & L => x & (K & L)
Reduction const r1 = Reduce(graph()->NewNode(
machine()->Word32And(),
graph()->NewNode(machine()->Word32And(), p0, Int32Constant(k)),
Int32Constant(l)));
ASSERT_TRUE(r1.Changed());
EXPECT_THAT(r1.replacement(), IsWord32And(p0, IsInt32Constant(k & l)));
// (K & x) & L => x & (K & L)
Reduction const r2 = Reduce(graph()->NewNode(
machine()->Word32And(),
graph()->NewNode(machine()->Word32And(), Int32Constant(k), p0),
Int32Constant(l)));
ASSERT_TRUE(r2.Changed());
EXPECT_THAT(r2.replacement(), IsWord32And(p0, IsInt32Constant(k & l)));
}
}
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Word32Xor // Word32Xor
......
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