Reviewers: dcarney,

Message:
PTAL

Description:
[turbofan] Minor cleanups to lowering of typed array loads/stores.

TEST=unittests

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

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+21, -61 lines):
  M src/compiler/js-typed-lowering.cc
  M src/compiler/node-matchers.h
  M src/compiler/simplified-operator-reducer.cc
  M test/unittests/compiler/js-typed-lowering-unittest.cc
  M test/unittests/compiler/simplified-operator-reducer-unittest.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 fb510e07ce941efcc831a2e82de599d652e7abc4..3407840ae9f288951cc24957415ff4914097e0cd 100644
--- a/src/compiler/js-typed-lowering.cc
+++ b/src/compiler/js-typed-lowering.cc
@@ -565,15 +565,13 @@ Reduction JSTypedLowering::ReduceJSLoadProperty(Node* node) {
         Handle<JSTypedArray>::cast(base_type->AsConstant()->Value());
     if (IsExternalArrayElementsKind(array->map()->elements_kind())) {
       ExternalArrayType type = array->type();
-      uint32_t byte_length;
-      if (array->byte_length()->ToUint32(&byte_length) &&
-          byte_length <= static_cast<uint32_t>(kMaxInt)) {
+      double byte_length = array->byte_length()->Number();
+      if (byte_length <= kMaxInt) {
         Handle<ExternalArray> elements =
             Handle<ExternalArray>::cast(handle(array->elements()));
         Node* pointer = jsgraph()->IntPtrConstant(
             bit_cast<intptr_t>(elements->external_pointer()));
-        Node* length = jsgraph()->Uint32Constant(
-            static_cast<uint32_t>(byte_length / array->element_size()));
+ Node* length = jsgraph()->Constant(byte_length / array->element_size());
         Node* effect = NodeProperties::GetEffectInput(node);
         Node* control = NodeProperties::GetControlInput(node);
         Node* load = graph()->NewNode(
@@ -603,15 +601,13 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
         Handle<JSTypedArray>::cast(base_type->AsConstant()->Value());
     if (IsExternalArrayElementsKind(array->map()->elements_kind())) {
       ExternalArrayType type = array->type();
-      uint32_t byte_length;
-      if (array->byte_length()->ToUint32(&byte_length) &&
-          byte_length <= static_cast<uint32_t>(kMaxInt)) {
+      double byte_length = array->byte_length()->Number();
+      if (byte_length <= kMaxInt) {
         Handle<ExternalArray> elements =
             Handle<ExternalArray>::cast(handle(array->elements()));
         Node* pointer = jsgraph()->IntPtrConstant(
             bit_cast<intptr_t>(elements->external_pointer()));
-        Node* length = jsgraph()->Uint32Constant(
-            static_cast<uint32_t>(byte_length / array->element_size()));
+ Node* length = jsgraph()->Constant(byte_length / array->element_size());
         Node* effect = NodeProperties::GetEffectInput(node);
         Node* control = NodeProperties::GetControlInput(node);
         Node* store = graph()->NewNode(
Index: src/compiler/node-matchers.h
diff --git a/src/compiler/node-matchers.h b/src/compiler/node-matchers.h
index 4cc4ff723fd6a7ef932ab78a1ef8a099ff520f78..718803f314243bec661bccf0dbf99e495f16d724 100644
--- a/src/compiler/node-matchers.h
+++ b/src/compiler/node-matchers.h
@@ -96,42 +96,6 @@ typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher;
 typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher;


-// A pattern matcher for any numberic constant.
-struct NumericValueMatcher : public NodeMatcher {
-  explicit NumericValueMatcher(Node* const node) : NodeMatcher(node) {
-    switch (opcode()) {
-      case IrOpcode::kInt32Constant:
-        has_value_ = true;
-        value_ = OpParameter<int32_t>(node);
-        break;
-      case IrOpcode::kFloat32Constant:
-        has_value_ = true;
-        value_ = OpParameter<float>(node);
-        break;
-      case IrOpcode::kFloat64Constant:
-      case IrOpcode::kNumberConstant:
-        has_value_ = true;
-        value_ = OpParameter<double>(node);
-        break;
-      default:
-        has_value_ = false;
-        value_ = 0;  // Make the compiler happy.
-        break;
-    }
-  }
-
-  bool HasValue() const { return has_value_; }
-  double Value() const {
-    DCHECK(HasValue());
-    return value_;
-  }
-
- private:
-  double value_;
-  bool has_value_;
-};
-
-
 // A pattern matcher for heap object constants.
 template <typename T>
 struct HeapObjectMatcher FINAL
Index: src/compiler/simplified-operator-reducer.cc
diff --git a/src/compiler/simplified-operator-reducer.cc b/src/compiler/simplified-operator-reducer.cc index 21a18eacce27eac0b98492bb387fe20c6f8070ce..a1a6a02bc89381481d961f9e7c22047b6a86e5bb 100644
--- a/src/compiler/simplified-operator-reducer.cc
+++ b/src/compiler/simplified-operator-reducer.cc
@@ -102,8 +102,8 @@ Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
     case IrOpcode::kLoadElement: {
       ElementAccess access = ElementAccessOf(node->op());
       if (access.bounds_check == kTypedArrayBoundsCheck) {
-        NumericValueMatcher mkey(node->InputAt(1));
-        NumericValueMatcher mlength(node->InputAt(2));
+        NumberMatcher mkey(node->InputAt(1));
+        NumberMatcher mlength(node->InputAt(2));
         if (mkey.HasValue() && mlength.HasValue()) {
// Skip the typed array bounds check if key and length are constant.
           if (mkey.Value() >= 0 && mkey.Value() < mlength.Value()) {
@@ -118,8 +118,8 @@ Reduction SimplifiedOperatorReducer::Reduce(Node* node) {
     case IrOpcode::kStoreElement: {
       ElementAccess access = ElementAccessOf(node->op());
       if (access.bounds_check == kTypedArrayBoundsCheck) {
-        NumericValueMatcher mkey(node->InputAt(1));
-        NumericValueMatcher mlength(node->InputAt(2));
+        NumberMatcher mkey(node->InputAt(1));
+        NumberMatcher mlength(node->InputAt(2));
         if (mkey.HasValue() && mlength.HasValue()) {
// Skip the typed array bounds check if key and length are constant.
           if (mkey.Value() >= 0 && mkey.Value() < mlength.Value()) {
Index: test/unittests/compiler/js-typed-lowering-unittest.cc
diff --git a/test/unittests/compiler/js-typed-lowering-unittest.cc b/test/unittests/compiler/js-typed-lowering-unittest.cc index 3da4bc71683a75e82c19ee7dedeadfd066c5d3c5..8db40dc75e0eb9195811ebed532aec5da3c08468 100644
--- a/test/unittests/compiler/js-typed-lowering-unittest.cc
+++ b/test/unittests/compiler/js-typed-lowering-unittest.cc
@@ -102,8 +102,8 @@ TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) {
         r.replacement(),
         IsLoadElement(AccessBuilder::ForTypedArrayElement(type, true),
IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), - key, IsInt32Constant(static_cast<int>(kLength)), effect,
-                      control));
+                      key, IsNumberConstant(static_cast<double>(kLength)),
+                      effect, control));
   }
 }

@@ -142,8 +142,8 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) {
                   IsStoreElement(
                       AccessBuilder::ForTypedArrayElement(type, true),
IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), - key, IsInt32Constant(static_cast<int>(kLength)), value,
-                      effect, control));
+                      key, IsNumberConstant(static_cast<double>(kLength)),
+                      value, effect, control));
     }
   }
 }
Index: test/unittests/compiler/simplified-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/simplified-operator-reducer-unittest.cc b/test/unittests/compiler/simplified-operator-reducer-unittest.cc index f96f03c5f628e31ec5fff3eb8cef022a6ac15670..2b4097b3084bbd45169ac027ad17fb89c45b4195 100644
--- a/test/unittests/compiler/simplified-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/simplified-operator-reducer-unittest.cc
@@ -508,8 +508,8 @@ TEST_F(SimplifiedOperatorReducerTest, LoadElementWithConstantKeyAndLength) {
                                                length, effect, control));
   }
   {
-    Node* const key = Int32Constant(0);
-    Node* const length = Int32Constant(1);
+    Node* const key = NumberConstant(0);
+    Node* const length = NumberConstant(1);
Reduction r = Reduce(graph()->NewNode(simplified()->LoadElement(access), base, key, length, effect, control));
     ASSERT_TRUE(r.Changed());
@@ -518,7 +518,7 @@ TEST_F(SimplifiedOperatorReducerTest, LoadElementWithConstantKeyAndLength) {
   }
   {
     Node* const key = NumberConstant(42.2);
-    Node* const length = Int32Constant(128);
+    Node* const length = NumberConstant(128);
Reduction r = Reduce(graph()->NewNode(simplified()->LoadElement(access), base, key, length, effect, control));
     ASSERT_TRUE(r.Changed());
@@ -558,7 +558,7 @@ TEST_F(SimplifiedOperatorReducerTest, StoreElementWithConstantKeyAndLength) {
   }
   {
     Node* const key = NumberConstant(-0.0);
-    Node* const length = Int32Constant(999);
+    Node* const length = NumberConstant(999);
     Reduction r =
Reduce(graph()->NewNode(simplified()->StoreElement(access), base, key,
                                 length, value, effect, control));
@@ -568,8 +568,8 @@ TEST_F(SimplifiedOperatorReducerTest, StoreElementWithConstantKeyAndLength) {
                                control));
   }
   {
-    Node* const key = Int32Constant(0);
-    Node* const length = Int32Constant(1);
+    Node* const key = NumberConstant(0);
+    Node* const length = NumberConstant(1);
     Reduction r =
Reduce(graph()->NewNode(simplified()->StoreElement(access), base, key,
                                 length, value, effect, control));
@@ -580,7 +580,7 @@ TEST_F(SimplifiedOperatorReducerTest, StoreElementWithConstantKeyAndLength) {
   }
   {
     Node* const key = NumberConstant(42.2);
-    Node* const length = Int32Constant(128);
+    Node* const length = NumberConstant(128);
     Reduction r =
Reduce(graph()->NewNode(simplified()->StoreElement(access), base, key,
                                 length, value, effect, control));


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