Reviewers: Benedikt Meurer,

Message:
PTAL

Description:
Use CopyToRepresentation to elide HForceRepresentation of HConstant

BUG=

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

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

Affected files (+11, -32 lines):
  M src/hydrogen-instructions.cc
  M src/property-details.h
  M src/property-details-inl.h
  A + test/mjsunit/regress/regress-force-constant-representation.js


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index dbfe555c428c2fbb4c9f9748f79749fe4a98b696..15f4dabb4dba7b4366b1be9308c379e0510ef523 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -1512,17 +1512,8 @@ HInstruction* HForceRepresentation::New(Zone* zone, HValue* context,
        HValue* value, Representation representation) {
   if (FLAG_fold_constants && value->IsConstant()) {
     HConstant* c = HConstant::cast(value);
-    if (c->HasNumberValue()) {
-      double double_res = c->DoubleValue();
-      if (representation.IsDouble()) {
-        return HConstant::New(zone, context, double_res);
-
-      } else if (representation.CanContainDouble(double_res)) {
-        return HConstant::New(zone, context,
-                              static_cast<int32_t>(double_res),
-                              representation);
-      }
-    }
+    c = c->CopyToRepresentation(representation, zone);
+    if (c != NULL) return c;
   }
   return new(zone) HForceRepresentation(value, representation);
 }
Index: src/property-details-inl.h
diff --git a/src/property-details-inl.h b/src/property-details-inl.h
index eaa596f9daf903b64e0fbac27061dd86d47880a4..efb27b31914be23a8832484fd4b5f34cfa0182de 100644
--- a/src/property-details-inl.h
+++ b/src/property-details-inl.h
@@ -13,18 +13,6 @@
 namespace v8 {
 namespace internal {

-inline bool Representation::CanContainDouble(double value) {
-  if (IsDouble() || is_more_general_than(Representation::Double())) {
-    return true;
-  }
-  if (IsInt32Double(value)) {
-    if (IsInteger32()) return true;
-    if (IsSmi()) return Smi::IsValid(static_cast<int32_t>(value));
-  }
-  return false;
-}
-
-
 Representation Representation::FromType(Type* type) {
   DisallowHeapAllocation no_allocation;
   if (type->Is(Type::None())) return Representation::None();
Index: src/property-details.h
diff --git a/src/property-details.h b/src/property-details.h
index 3e54473350358ed37312a19e13a8313a449cdb3e..ee0dc02c09cb3ee40e97a7f18025d476a0aac77e 100644
--- a/src/property-details.h
+++ b/src/property-details.h
@@ -122,8 +122,6 @@ class Representation {
     return other.is_more_general_than(*this) || other.Equals(*this);
   }

-  bool CanContainDouble(double value);
-
   Representation generalize(Representation other) {
     if (other.fits_into(*this)) return *this;
     if (other.is_more_general_than(*this)) return other;
Index: test/mjsunit/regress/regress-force-constant-representation.js
diff --git a/test/mjsunit/regress/regress-alloc-smi-check.js b/test/mjsunit/regress/regress-force-constant-representation.js
similarity index 62%
copy from test/mjsunit/regress/regress-alloc-smi-check.js
copy to test/mjsunit/regress/regress-force-constant-representation.js
index 295048a13ef862ceb21939de104e7968dd7772da..4ec2a6a7998d2b9bda283ae594e97c23b0f75560 100644
--- a/test/mjsunit/regress/regress-alloc-smi-check.js
+++ b/test/mjsunit/regress/regress-force-constant-representation.js
@@ -1,16 +1,18 @@
 // Copyright 2014 the V8 project authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
-//
-// Flags: --allow-natives-syntax

-var x = {};
+// Flags: --allow-natives-syntax

+// Test push double as tagged.
+var a = [{}];
 function f(a) {
-  a[200000000] = x;
+  a.push(Infinity);
 }

-f(new Array(100000));
-f([]);
+f(a);
+f(a);
+f(a);
 %OptimizeFunctionOnNextCall(f);
-f([]);
+f(a);
+assertEquals([{}, Infinity, Infinity, Infinity, Infinity], a);


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