Index: src/compiler/machine-operator-reducer.cc |
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc |
index c06f06e68c8c8a0bf84b631d5b628ba4456aabdc..4aeeeeacfcf2670d7b19059eeceeaa40dae2616f 100644 |
--- a/src/compiler/machine-operator-reducer.cc |
+++ b/src/compiler/machine-operator-reducer.cc |
@@ -150,8 +150,21 @@ |
return ReduceWord32And(node); |
case IrOpcode::kWord32Or: |
return ReduceWord32Or(node); |
- case IrOpcode::kWord32Xor: |
- return ReduceWord32Xor(node); |
+ case IrOpcode::kWord32Xor: { |
+ Int32BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x ^ 0 => x |
+ if (m.IsFoldable()) { // K ^ K => K |
+ 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: |
return ReduceWord32Shl(node); |
case IrOpcode::kWord32Shr: |
@@ -1093,17 +1106,22 @@ |
return NoChange(); |
} |
-Reduction MachineOperatorReducer::TryMatchWord32Ror(Node* node) { |
- DCHECK(IrOpcode::kWord32Or == node->opcode() || |
- IrOpcode::kWord32Xor == node->opcode()); |
+ |
+Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) { |
+ DCHECK_EQ(IrOpcode::kWord32Or, node->opcode()); |
Int32BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x | 0 => x |
+ if (m.right().Is(-1)) return Replace(m.right().node()); // x | -1 => -1 |
+ if (m.IsFoldable()) { // K | K => K |
+ return ReplaceInt32(m.left().Value() | m.right().Value()); |
+ } |
+ if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x |
+ |
Node* shl = nullptr; |
Node* shr = nullptr; |
- // Recognize rotation, we are matching: |
+ // Recognize rotation, we are matching either: |
// * x << y | x >>> (32 - y) => x ror (32 - y), i.e x rol y |
// * x << (32 - y) | x >>> y => x ror y |
- // * x << y ^ x >>> (32 - y) => x ror (32 - y), i.e. x rol y |
- // * x << (32 - y) ^ x >>> y => x ror y |
// as well as their commuted form. |
if (m.left().IsWord32Shl() && m.right().IsWord32Shr()) { |
shl = m.left().node(); |
@@ -1145,36 +1163,6 @@ |
return Changed(node); |
} |
-Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) { |
- DCHECK_EQ(IrOpcode::kWord32Or, node->opcode()); |
- Int32BinopMatcher m(node); |
- if (m.right().Is(0)) return Replace(m.left().node()); // x | 0 => x |
- if (m.right().Is(-1)) return Replace(m.right().node()); // x | -1 => -1 |
- if (m.IsFoldable()) { // K | K => K |
- return ReplaceInt32(m.left().Value() | m.right().Value()); |
- } |
- if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x |
- |
- return TryMatchWord32Ror(node); |
-} |
- |
-Reduction MachineOperatorReducer::ReduceWord32Xor(Node* node) { |
- DCHECK_EQ(IrOpcode::kWord32Xor, node->opcode()); |
- Int32BinopMatcher m(node); |
- if (m.right().Is(0)) return Replace(m.left().node()); // x ^ 0 => x |
- if (m.IsFoldable()) { // K ^ K => K |
- 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()); |
- } |
- } |
- |
- return TryMatchWord32Ror(node); |
-} |
Reduction MachineOperatorReducer::ReduceFloat64InsertLowWord32(Node* node) { |
DCHECK_EQ(IrOpcode::kFloat64InsertLowWord32, node->opcode()); |