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

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

Issue 2211633003: [turbofan] Basic reductions of 64-bit machine operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Forgot the tests for Word64 shifts. Created 4 years, 4 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') | test/cctest/compiler/test-machine-operator-reducer.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 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());
« no previous file with comments | « src/compiler/machine-operator-reducer.h ('k') | test/cctest/compiler/test-machine-operator-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698