Commit 1efc572f authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Reduce ~~x to x.

TEST=unittests
R=dcarney@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24770 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4eddbaca
......@@ -173,6 +173,12 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceInt32(m.left().Value() ^ m.right().Value());
}
if (m.LeftEqualsRight()) return ReplaceInt32(0); // x ^ x => 0
if (m.left().IsWord32Xor() && m.right().Is(-1)) {
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().Is(-1)) { // (x ^ -1) ^ -1 => x
return Replace(mleft.left().node());
}
}
break;
}
case IrOpcode::kWord32Shl: {
......
......@@ -481,6 +481,45 @@ TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithConstant) {
}
// -----------------------------------------------------------------------------
// Word32Xor
TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) {
Node* const p0 = Parameter(0);
// (x ^ -1) ^ -1 => x
Reduction r1 = Reduce(graph()->NewNode(
machine()->Word32Xor(),
graph()->NewNode(machine()->Word32Xor(), p0, Int32Constant(-1)),
Int32Constant(-1)));
ASSERT_TRUE(r1.Changed());
EXPECT_EQ(r1.replacement(), p0);
// -1 ^ (x ^ -1) => x
Reduction r2 = Reduce(graph()->NewNode(
machine()->Word32Xor(), Int32Constant(-1),
graph()->NewNode(machine()->Word32Xor(), p0, Int32Constant(-1))));
ASSERT_TRUE(r2.Changed());
EXPECT_EQ(r2.replacement(), p0);
// (-1 ^ x) ^ -1 => x
Reduction r3 = Reduce(graph()->NewNode(
machine()->Word32Xor(),
graph()->NewNode(machine()->Word32Xor(), Int32Constant(-1), p0),
Int32Constant(-1)));
ASSERT_TRUE(r3.Changed());
EXPECT_EQ(r3.replacement(), p0);
// -1 ^ (-1 ^ x) => x
Reduction r4 = Reduce(graph()->NewNode(
machine()->Word32Xor(), Int32Constant(-1),
graph()->NewNode(machine()->Word32Xor(), Int32Constant(-1), p0)));
ASSERT_TRUE(r4.Changed());
EXPECT_EQ(r4.replacement(), p0);
}
// -----------------------------------------------------------------------------
// Word32Ror
......
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