Reviewers: jarin,

Description:
[WIP] Typ aided removal of redundant modulus.

[email protected]
BUG=

Please review this at https://codereview.chromium.org/732173002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+22, -1 lines):
  M src/compiler/js-typed-lowering.h
  M src/compiler/js-typed-lowering.cc
  M src/compiler/typer.cc


Index: src/compiler/js-typed-lowering.cc
diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc index 4765bc2e5fc618a6ddbed3983f8c4c9a678beb90..680bb8b0a4426aa8ee9b38b7938905b13e1b38fa 100644
--- a/src/compiler/js-typed-lowering.cc
+++ b/src/compiler/js-typed-lowering.cc
@@ -267,6 +267,22 @@ Reduction JSTypedLowering::ReduceJSMultiply(Node* node) {
 }


+Reduction JSTypedLowering::ReduceJSModulus(Node* node) {
+  JSBinopReduction r(this, node);
+  if (r.left_type()->Is(NodeProperties::GetBounds(node).upper)) {
+    Node* const value = r.left();
+    NodeProperties::ReplaceWithValue(node, value);
+    return Changed(value);
+  }
+  if (r.BothInputsAre(Type::Primitive())) {
+    r.ConvertInputsToNumber();
+    return r.ChangeToPureOperator(simplified()->NumberModulus());
+  }
+ // TODO(turbofan): relax/remove the effects of this operator in other cases.
+  return NoChange();
+}
+
+
 Reduction JSTypedLowering::ReduceNumberBinop(Node* node,
                                              const Operator* numberOp) {
   JSBinopReduction r(this, node);
@@ -746,7 +762,7 @@ Reduction JSTypedLowering::Reduce(Node* node) {
     case IrOpcode::kJSDivide:
       return ReduceNumberBinop(node, simplified()->NumberDivide());
     case IrOpcode::kJSModulus:
-      return ReduceNumberBinop(node, simplified()->NumberModulus());
+      return ReduceJSModulus(node);
     case IrOpcode::kJSUnaryNot: {
       Reduction result = ReduceJSToBooleanInput(node->InputAt(0));
       Node* value;
Index: src/compiler/js-typed-lowering.h
diff --git a/src/compiler/js-typed-lowering.h b/src/compiler/js-typed-lowering.h index ba160c491faa9b9acb0391c896c716976dda996b..25d98ab2049707e5e5d31b08e4a8ef76ff8666b3 100644
--- a/src/compiler/js-typed-lowering.h
+++ b/src/compiler/js-typed-lowering.h
@@ -35,6 +35,7 @@ class JSTypedLowering FINAL : public Reducer {
   Reduction ReduceJSAdd(Node* node);
   Reduction ReduceJSBitwiseOr(Node* node);
   Reduction ReduceJSMultiply(Node* node);
+  Reduction ReduceJSModulus(Node* node);
   Reduction ReduceJSComparison(Node* node);
   Reduction ReduceJSLoadProperty(Node* node);
   Reduction ReduceJSStoreProperty(Node* node);
Index: src/compiler/typer.cc
diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc
index 996eecd361caacde8ae062304ac1180d68902e75..ce1ea188336830c0b15579ea8c4f62ac33e45d9d 100644
--- a/src/compiler/typer.cc
+++ b/src/compiler/typer.cc
@@ -467,6 +467,10 @@ Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) {
   // TODO(neis): DCHECK(type->Is(Type::Number()));
   if (type->Is(Type::Signed32())) return type;
   if (type->Is(t->zeroish)) return t->singleton_zero;
+ if (type->Is(Type::Union(Type::MinusZero(), Type::Signed32(), t->zone()))) {
+    return Type::Intersect(Type::Union(type, t->singleton_zero, t->zone()),
+                           Type::Signed32(), t->zone());
+  }
   return Type::Signed32();
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to