Index: src/compiler/machine-operator-reducer.cc |
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc |
index 6f2e28ed7d479e7bbbe5be3dc880b02db23576d4..68e3f72fae4ca8d4262b848efc3b0c26c85c3977 100644 |
--- a/src/compiler/machine-operator-reducer.cc |
+++ b/src/compiler/machine-operator-reducer.cc |
@@ -39,6 +39,8 @@ Node* MachineOperatorReducer::Int64Constant(int64_t value) { |
// Perform constant folding and strength reduction on machine operators. |
Reduction MachineOperatorReducer::Reduce(Node* node) { |
switch (node->opcode()) { |
+ case IrOpcode::kProjection: |
+ return ReduceProjection(OpParameter<size_t>(node), node->InputAt(0)); |
case IrOpcode::kWord32And: { |
Int32BinopMatcher m(node); |
if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 |
@@ -433,6 +435,43 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
} |
+Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { |
+ switch (node->opcode()) { |
+ case IrOpcode::kInt32AddWithOverflow: { |
+ DCHECK(index == 0 || index == 1); |
+ Int32BinopMatcher m(node); |
+ if (m.IsFoldable()) { |
+ int32_t val; |
+ bool ovf = base::bits::SignedAddOverflow32(m.left().Value(), |
+ m.right().Value(), &val); |
+ return ReplaceInt32((index == 0) ? val : ovf); |
+ } |
+ if (m.right().Is(0)) { |
+ return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0); |
+ } |
+ break; |
+ } |
+ case IrOpcode::kInt32SubWithOverflow: { |
+ DCHECK(index == 0 || index == 1); |
+ Int32BinopMatcher m(node); |
+ if (m.IsFoldable()) { |
+ int32_t val; |
+ bool ovf = base::bits::SignedSubOverflow32(m.left().Value(), |
+ m.right().Value(), &val); |
+ return ReplaceInt32((index == 0) ? val : ovf); |
+ } |
+ if (m.right().Is(0)) { |
+ return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0); |
+ } |
+ break; |
+ } |
+ default: |
+ break; |
+ } |
+ return NoChange(); |
+} |
+ |
+ |
CommonOperatorBuilder* MachineOperatorReducer::common() const { |
return jsgraph()->common(); |
} |