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

Unified Diff: src/compiler/simplified-lowering.cc

Issue 620553008: Lower NumberMultiply, NumberDivide, and NumberModulus to Int32Mul, Int32[U]Div, and Int32[U]Mod whe… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 | « no previous file | test/cctest/compiler/test-simplified-lowering.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/simplified-lowering.cc
diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc
index 75fff31c7b58cc445827cad446bd689f9df0f727..95c1980ba892b35b444c0008b7a0dd6ca70fe1f1 100644
--- a/src/compiler/simplified-lowering.cc
+++ b/src/compiler/simplified-lowering.cc
@@ -8,6 +8,7 @@
#include "src/code-factory.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-inl.h"
+#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/representation-change.h"
#include "src/compiler/simplified-lowering.h"
@@ -351,6 +352,22 @@ class RepresentationSelector {
return changer_->Float64OperatorFor(node->opcode());
}
+ bool CanBeInt32Binop(Node* node, MachineTypeUnion use) {
Michael Starzinger 2014/10/01 21:11:32 I find the "CanBe" prefix confusing in this settin
Michael Starzinger 2014/10/01 21:15:57 Alternatively "CanBecome" would also work for me.
+ return BothInputsAre(node, Type::Signed32()) && !CanObserveNonInt32(use);
+ }
+
+ bool CanBeUint32Binop(Node* node, MachineTypeUnion use) {
Michael Starzinger 2014/10/01 21:11:32 Likewise.
+ return BothInputsAre(node, Type::Unsigned32()) && !CanObserveNonUint32(use);
+ }
+
+ bool CanObserveNonInt32(MachineTypeUnion use) {
+ return (use & (kTypeUint32 | kTypeNumber | kTypeAny)) != 0;
+ }
+
+ bool CanObserveNonUint32(MachineTypeUnion use) {
+ return (use & (kTypeInt32 | kTypeNumber | kTypeAny)) != 0;
+ }
+
// Dispatching routine for visiting the node {node} with the usage {use}.
// Depending on the operator, propagate new usage info to the inputs.
void VisitNode(Node* node, MachineTypeUnion use,
@@ -475,13 +492,11 @@ class RepresentationSelector {
case IrOpcode::kNumberSubtract: {
// Add and subtract reduce to Int32Add/Sub if the inputs
// are already integers and all uses are truncating.
- if (BothInputsAre(node, Type::Signed32()) &&
- (use & (kTypeUint32 | kTypeNumber | kTypeAny)) == 0) {
+ if (CanBeInt32Binop(node, use)) {
// => signed Int32Add/Sub
VisitInt32Binop(node);
if (lower()) node->set_op(Int32Op(node));
- } else if (BothInputsAre(node, Type::Unsigned32()) &&
- (use & (kTypeInt32 | kTypeNumber | kTypeAny)) == 0) {
+ } else if (CanBeUint32Binop(node, use)) {
// => unsigned Int32Add/Sub
VisitUint32Binop(node);
if (lower()) node->set_op(Uint32Op(node));
@@ -492,10 +507,57 @@ class RepresentationSelector {
}
break;
}
- case IrOpcode::kNumberMultiply:
- case IrOpcode::kNumberDivide:
+ case IrOpcode::kNumberMultiply: {
+ NumberMatcher right(node->InputAt(1));
+ if (right.IsInRange(-1048576, 1048576)) { // must fit double mantissa.
+ if (CanBeInt32Binop(node, use)) {
+ // => signed Int32Mul
+ VisitInt32Binop(node);
+ if (lower()) node->set_op(Int32Op(node));
+ break;
+ }
+ }
+ // => Float64Mul
+ VisitFloat64Binop(node);
+ if (lower()) node->set_op(Float64Op(node));
+ break;
+ }
+ case IrOpcode::kNumberDivide: {
+ NumberMatcher right(node->InputAt(1));
+ if (right.HasValue() && !right.Is(0) && !right.Is(-1)) {
+ if (CanBeInt32Binop(node, use)) {
+ // => signed Int32Div
+ VisitInt32Binop(node);
+ if (lower()) node->set_op(Int32Op(node));
+ break;
+ } else if (CanBeUint32Binop(node, use)) {
+ // => unsigned Uint32Div
+ VisitUint32Binop(node);
+ if (lower()) node->set_op(Uint32Op(node));
+ break;
+ }
+ }
+ // => Float64Div
+ VisitFloat64Binop(node);
+ if (lower()) node->set_op(Float64Op(node));
+ break;
+ }
case IrOpcode::kNumberModulus: {
- // Float64Mul/Div/Mod
+ NumberMatcher right(node->InputAt(1));
+ if (right.HasValue() && !right.Is(0) && !right.Is(-1)) {
+ if (BothInputsAre(node, Type::Signed32())) {
+ // => signed Int32Mod
+ VisitInt32Binop(node);
+ if (lower()) node->set_op(Int32Op(node));
+ break;
+ } else if (BothInputsAre(node, Type::Unsigned32())) {
+ // => unsigned Uint32Mod
+ VisitUint32Binop(node);
+ if (lower()) node->set_op(Uint32Op(node));
+ break;
+ }
+ }
+ // => Float64Mod
VisitFloat64Binop(node);
if (lower()) node->set_op(Float64Op(node));
break;
« no previous file with comments | « no previous file | test/cctest/compiler/test-simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698