Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: src/compiler/machine-operator-reducer.cc

Issue 555833002: [turbofan] Add support for overflow add/sub to the MachineOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/machine-operator-reducer.h ('k') | src/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « src/compiler/machine-operator-reducer.h ('k') | src/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698