Revision: 25198
Author:   [email protected]
Date:     Thu Nov  6 13:55:30 2014 UTC
Log:      [turbofan] Lower asm.js truncations to JSToNumber.

- JSBitwiseOr(x, 0) => Word32Or(NumberToInt32(JSToNumber(x)), 0)
- JSMultiply(x, 1) => NumberMultiply(JSToNumber(x), 1)

[email protected]

Review URL: https://codereview.chromium.org/706863003
https://code.google.com/p/v8/source/detail?r=25198

Modified:
 /branches/bleeding_edge/src/compiler/js-typed-lowering.cc
 /branches/bleeding_edge/src/compiler/js-typed-lowering.h

=======================================
--- /branches/bleeding_edge/src/compiler/js-typed-lowering.cc Wed Oct 29 18:46:44 2014 UTC +++ /branches/bleeding_edge/src/compiler/js-typed-lowering.cc Thu Nov 6 13:55:30 2014 UTC
@@ -27,6 +27,16 @@
 static void RelaxEffects(Node* node) {
   NodeProperties::ReplaceWithValue(node, node, NULL);
 }
+
+
+JSTypedLowering::JSTypedLowering(JSGraph* jsgraph)
+    : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {
+  Factory* factory = zone()->isolate()->factory();
+  Handle<Object> zero = factory->NewNumber(0.0);
+  Handle<Object> one = factory->NewNumber(1.0);
+  zero_range_ = Type::Range(zero, zero, zone());
+  one_range_ = Type::Range(one, one, zone());
+}


 JSTypedLowering::~JSTypedLowering() {}
@@ -257,6 +267,36 @@
 #endif
   return NoChange();
 }
+
+
+Reduction JSTypedLowering::ReduceJSBitwiseOr(Node* node) {
+  JSBinopReduction r(this, node);
+  if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(zero_range_)) {
+ // TODO(jarin): Propagate frame state input from non-primitive input node to
+    // JSToNumber node.
+    // TODO(titzer): some Smi bitwise operations don't really require going
+    // all the way to int32, which can save tagging/untagging for some
+    // operations
+    // on some platforms.
+    // TODO(turbofan): make this heuristic configurable for code size.
+    r.ConvertInputsToInt32(true, true);
+    return r.ChangeToPureOperator(machine()->Word32Or());
+  }
+  return NoChange();
+}
+
+
+Reduction JSTypedLowering::ReduceJSMultiply(Node* node) {
+  JSBinopReduction r(this, node);
+  if (r.BothInputsAre(Type::Primitive()) || r.OneInputIs(one_range_)) {
+ // TODO(jarin): Propagate frame state input from non-primitive input node to
+    // JSToNumber node.
+    r.ConvertInputsToNumber();
+    return r.ChangeToPureOperator(simplified()->NumberMultiply());
+  }
+ // TODO(turbofan): relax/remove the effects of this operator in other cases.
+  return NoChange();
+}


 Reduction JSTypedLowering::ReduceNumberBinop(Node* node,
@@ -697,7 +737,7 @@
     case IrOpcode::kJSGreaterThanOrEqual:
       return ReduceJSComparison(node);
     case IrOpcode::kJSBitwiseOr:
-      return ReduceI32Binop(node, true, true, machine()->Word32Or());
+      return ReduceJSBitwiseOr(node);
     case IrOpcode::kJSBitwiseXor:
       return ReduceI32Binop(node, true, true, machine()->Word32Xor());
     case IrOpcode::kJSBitwiseAnd:
@@ -713,7 +753,7 @@
     case IrOpcode::kJSSubtract:
       return ReduceNumberBinop(node, simplified()->NumberSubtract());
     case IrOpcode::kJSMultiply:
-      return ReduceNumberBinop(node, simplified()->NumberMultiply());
+      return ReduceJSMultiply(node);
     case IrOpcode::kJSDivide:
       return ReduceNumberBinop(node, simplified()->NumberDivide());
     case IrOpcode::kJSModulus:
=======================================
--- /branches/bleeding_edge/src/compiler/js-typed-lowering.h Fri Sep 19 15:02:58 2014 UTC +++ /branches/bleeding_edge/src/compiler/js-typed-lowering.h Thu Nov 6 13:55:30 2014 UTC
@@ -18,8 +18,7 @@
 // Lowers JS-level operators to simplified operators based on types.
 class JSTypedLowering FINAL : public Reducer {
  public:
-  explicit JSTypedLowering(JSGraph* jsgraph)
-      : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
+  explicit JSTypedLowering(JSGraph* jsgraph);
   virtual ~JSTypedLowering();

   virtual Reduction Reduce(Node* node) OVERRIDE;
@@ -34,6 +33,8 @@
   Reduction ReplaceEagerly(Node* old, Node* node);
   Reduction ReplaceWith(Node* node) { return Reducer::Replace(node); }
   Reduction ReduceJSAdd(Node* node);
+  Reduction ReduceJSBitwiseOr(Node* node);
+  Reduction ReduceJSMultiply(Node* node);
   Reduction ReduceJSComparison(Node* node);
   Reduction ReduceJSLoadProperty(Node* node);
   Reduction ReduceJSStoreProperty(Node* node);
@@ -55,6 +56,8 @@

   JSGraph* jsgraph_;
   SimplifiedOperatorBuilder simplified_;
+  Type* zero_range_;
+  Type* one_range_;
 };

 }  // namespace compiler

--
--
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