Reviewers: Jakob,

Message:
ArrayLiteral is always initialized with FAST_SMI element kind. If the
ArrayLiteral is dead code, it will affect its element variable representation
through use chain.
An example is the builtin StringSplit function as below

function StringSplit(separator, limit) {
  if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
    throw MakeTypeError("called_on_null_or_undefined",
                        ["String.prototype.split"]);
  }
  var subject = TO_STRING_INLINE(this);
  limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);

  // ECMA-262 says that if separator is undefined, the result should
  // be an array of size 1 containing the entire string.
  if (IS_UNDEFINED(separator)) {
    return [subject];
  }
  ...
}
"return [subject]" is mostly dead code because separator is rarely undefined.
But its side effect is to require subject used here to be SMI. A smi check
instruction will be inserted but always fail because subject mostly is a String object. You will see split function is optimized and deoptimized many time with
poor performance.

On my X86 PC, this commit improves the StringSplit performance by ~9%. And there
is also small improvement for V8 benchmark (more than 1%)

Thanks for review

Description:
Not consider the use representation in unintiliazed ArrayLiteral which always
requires SMI

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

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

Affected files:
  M     src/hydrogen-instructions.h
  M     src/hydrogen.cc


Index: src/hydrogen-instructions.h
===================================================================
--- src/hydrogen-instructions.h (revision 15397)
+++ src/hydrogen-instructions.h (working copy)
@@ -5877,6 +5877,7 @@
       : elements_kind_(elements_kind),
       index_offset_(0),
       is_dehoisted_(false),
+      is_uninitialized_(false),
       new_space_dominator_(NULL) {
     SetOperandAt(0, obj);
     SetOperandAt(1, key);
@@ -5937,6 +5938,9 @@

   virtual Representation observed_input_representation(int index) {
     if (index < 2) return RequiredInputRepresentation(index);
+    if (IsUninitialized()) {
+      return Representation::None();
+    }
     if (IsFastSmiElementsKind(elements_kind())) {
       return Representation::Smi();
     }
@@ -5963,6 +5967,10 @@
   void SetKey(HValue* key) { SetOperandAt(1, key); }
   bool IsDehoisted() { return is_dehoisted_; }
   void SetDehoisted(bool is_dehoisted) { is_dehoisted_ = is_dehoisted; }
+  bool IsUninitialized() { return is_uninitialized_; }
+  void SetUninitialized(bool is_uninitialized) {
+    is_uninitialized_ = is_uninitialized;
+  }

   bool IsConstantHoleStore() {
     return value()->IsConstant() && HConstant::cast(value())->IsTheHole();
@@ -5993,7 +6001,8 @@
  private:
   ElementsKind elements_kind_;
   uint32_t index_offset_;
-  bool is_dehoisted_;
+  bool is_dehoisted_ : 1;
+  bool is_uninitialized_ : 1;
   HValue* new_space_dominator_;
 };

Index: src/hydrogen.cc
===================================================================
--- src/hydrogen.cc     (revision 15397)
+++ src/hydrogen.cc     (working copy)
@@ -5768,7 +5768,9 @@
   Handle<Object> raw_boilerplate(literals->get(expr->literal_index()),
                                  isolate());

+  bool uninitialized= false;
   if (raw_boilerplate->IsUndefined()) {
+    uninitialized = true;
     raw_boilerplate = Runtime::CreateArrayLiteralBoilerplate(
         isolate(), literals, expr->constant_elements());
     if (raw_boilerplate.is_null()) {
@@ -5865,9 +5867,12 @@
       case FAST_HOLEY_ELEMENTS:
       case FAST_DOUBLE_ELEMENTS:
       case FAST_HOLEY_DOUBLE_ELEMENTS:
-        Add<HStoreKeyed>(elements, key, value,
-                         boilerplate_elements_kind);
-        break;
+        {
+          HStoreKeyed* instr = Add<HStoreKeyed>(elements, key, value,
+                                                boilerplate_elements_kind);
+          instr->SetUninitialized(uninitialized);
+          break;
+        }
       default:
         UNREACHABLE();
         break;


--
--
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/groups/opt_out.


Reply via email to