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

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

Issue 2139733003: [turbofan] Strength reduction for Int32MulWithOverflow. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2101123005
Patch Set: Created 4 years, 5 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 | « no previous file | test/unittests/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 a93713824dc2bf387aefc22f1eaaebffeff1b080..fd402ee1c7fecbea37ff222c6d57d9d188eb343a 100644
--- a/src/compiler/machine-operator-reducer.cc
+++ b/src/compiler/machine-operator-reducer.cc
@@ -235,6 +235,21 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
break;
}
+ case IrOpcode::kInt32MulWithOverflow: {
+ Int32BinopMatcher m(node);
+ if (m.right().Is(2)) {
+ node->ReplaceInput(1, m.left().node());
+ NodeProperties::ChangeOp(node, machine()->Int32AddWithOverflow());
+ return Changed(node);
+ }
+ if (m.right().Is(-1)) {
+ node->ReplaceInput(0, Int32Constant(0));
+ node->ReplaceInput(1, m.left().node());
+ NodeProperties::ChangeOp(node, machine()->Int32SubWithOverflow());
+ return Changed(node);
+ }
+ break;
+ }
case IrOpcode::kInt32Div:
return ReduceInt32Div(node);
case IrOpcode::kUint32Div:
@@ -831,10 +846,10 @@ Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) {
int32_t val;
bool ovf = base::bits::SignedAddOverflow32(m.left().Value(),
m.right().Value(), &val);
- return ReplaceInt32((index == 0) ? val : ovf);
+ return ReplaceInt32(index == 0 ? val : ovf);
}
if (m.right().Is(0)) {
- return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0);
+ return Replace(index == 0 ? m.left().node() : m.right().node());
}
break;
}
@@ -845,10 +860,27 @@ Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) {
int32_t val;
bool ovf = base::bits::SignedSubOverflow32(m.left().Value(),
m.right().Value(), &val);
- return ReplaceInt32((index == 0) ? val : ovf);
+ return ReplaceInt32(index == 0 ? val : ovf);
+ }
+ if (m.right().Is(0)) {
+ return Replace(index == 0 ? m.left().node() : m.right().node());
+ }
+ break;
+ }
+ case IrOpcode::kInt32MulWithOverflow: {
+ DCHECK(index == 0 || index == 1);
+ Int32BinopMatcher m(node);
+ if (m.IsFoldable()) {
+ int32_t val;
+ bool ovf = base::bits::SignedMulOverflow32(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);
+ return Replace(m.right().node());
+ }
+ if (m.right().Is(1)) {
+ return index == 0 ? Replace(m.left().node()) : ReplaceInt32(0);
}
break;
}
« no previous file with comments | « no previous file | test/unittests/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698