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..55c93c2c13d826876be71fa9c60b36e14a9f8156 100644 |
--- a/src/compiler/machine-operator-reducer.cc |
+++ b/src/compiler/machine-operator-reducer.cc |
@@ -154,10 +154,16 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
return ReduceWord32Xor(node); |
case IrOpcode::kWord32Shl: |
return ReduceWord32Shl(node); |
+ case IrOpcode::kWord64Shl: |
+ return ReduceWord64Shl(node); |
case IrOpcode::kWord32Shr: |
return ReduceWord32Shr(node); |
+ case IrOpcode::kWord64Shr: |
+ return ReduceWord64Shr(node); |
case IrOpcode::kWord32Sar: |
return ReduceWord32Sar(node); |
+ case IrOpcode::kWord64Sar: |
+ return ReduceWord64Sar(node); |
case IrOpcode::kWord32Ror: { |
Int32BinopMatcher m(node); |
if (m.right().Is(0)) return Replace(m.left().node()); // x ror 0 => x |
@@ -199,8 +205,12 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
} |
case IrOpcode::kInt32Add: |
return ReduceInt32Add(node); |
+ case IrOpcode::kInt64Add: |
+ return ReduceInt64Add(node); |
case IrOpcode::kInt32Sub: |
return ReduceInt32Sub(node); |
+ case IrOpcode::kInt64Sub: |
+ return ReduceInt64Sub(node); |
case IrOpcode::kInt32Mul: { |
Int32BinopMatcher m(node); |
if (m.right().Is(0)) return Replace(m.right().node()); // x * 0 => 0 |
@@ -621,6 +631,16 @@ Reduction MachineOperatorReducer::ReduceInt32Add(Node* node) { |
return NoChange(); |
} |
+Reduction MachineOperatorReducer::ReduceInt64Add(Node* node) { |
+ DCHECK_EQ(IrOpcode::kInt64Add, node->opcode()); |
+ Int64BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x + 0 => 0 |
+ if (m.IsFoldable()) { |
+ return Replace(Uint64Constant(bit_cast<uint64_t>(m.left().Value()) + |
+ bit_cast<uint64_t>(m.right().Value()))); |
+ } |
+ return NoChange(); |
+} |
Reduction MachineOperatorReducer::ReduceInt32Sub(Node* node) { |
DCHECK_EQ(IrOpcode::kInt32Sub, node->opcode()); |
@@ -640,6 +660,23 @@ Reduction MachineOperatorReducer::ReduceInt32Sub(Node* node) { |
return NoChange(); |
} |
+Reduction MachineOperatorReducer::ReduceInt64Sub(Node* node) { |
+ DCHECK_EQ(IrOpcode::kInt64Sub, node->opcode()); |
+ Int64BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x - 0 => x |
+ if (m.IsFoldable()) { // K - K => K |
+ return Replace(Uint64Constant(bit_cast<uint64_t>(m.left().Value()) - |
+ bit_cast<uint64_t>(m.right().Value()))); |
+ } |
+ if (m.LeftEqualsRight()) return Replace(Int64Constant(0)); // x - x => 0 |
+ if (m.right().HasValue()) { // x - K => x + -K |
+ node->ReplaceInput(1, Int64Constant(-m.right().Value())); |
+ NodeProperties::ChangeOp(node, machine()->Int64Add()); |
+ Reduction const reduction = ReduceInt64Add(node); |
+ return reduction.Changed() ? reduction : Changed(node); |
+ } |
+ return NoChange(); |
+} |
Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) { |
Int32BinopMatcher m(node); |
@@ -936,6 +973,16 @@ Reduction MachineOperatorReducer::ReduceWord32Shl(Node* node) { |
return ReduceWord32Shifts(node); |
} |
+Reduction MachineOperatorReducer::ReduceWord64Shl(Node* node) { |
+ DCHECK_EQ(IrOpcode::kWord64Shl, node->opcode()); |
+ Int64BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x << 0 => x |
+ if (m.IsFoldable()) { // K << K => K |
+ return ReplaceInt64(m.left().Value() << m.right().Value()); |
+ } |
+ return NoChange(); |
+} |
+ |
Reduction MachineOperatorReducer::ReduceWord32Shr(Node* node) { |
Uint32BinopMatcher m(node); |
if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x |
@@ -956,6 +1003,16 @@ Reduction MachineOperatorReducer::ReduceWord32Shr(Node* node) { |
return ReduceWord32Shifts(node); |
} |
+Reduction MachineOperatorReducer::ReduceWord64Shr(Node* node) { |
+ DCHECK_EQ(IrOpcode::kWord64Shr, node->opcode()); |
+ Uint64BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x |
+ if (m.IsFoldable()) { // K >> K => K |
+ return ReplaceInt64(m.left().Value() >> m.right().Value()); |
+ } |
+ return NoChange(); |
+} |
+ |
Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) { |
Int32BinopMatcher m(node); |
if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x |
@@ -991,6 +1048,14 @@ Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) { |
return ReduceWord32Shifts(node); |
} |
+Reduction MachineOperatorReducer::ReduceWord64Sar(Node* node) { |
+ Int64BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x |
+ if (m.IsFoldable()) { |
+ return ReplaceInt64(m.left().Value() >> m.right().Value()); |
+ } |
+ return NoChange(); |
+} |
Reduction MachineOperatorReducer::ReduceWord32And(Node* node) { |
DCHECK_EQ(IrOpcode::kWord32And, node->opcode()); |