Reviewers: Toon Verwaest,

Message:
PTAL

Description:
Fix for a smi stores optimization on x64 with a test case.

BUG=338425

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

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

Affected files (+17, -6 lines):
  M src/flag-definitions.h
  M src/hydrogen-instructions.h
  M src/hydrogen.cc
  M src/x64/lithium-codegen-x64.cc
  A + test/mjsunit/compiler/smi-stores-opt.js


Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index c0eaf16da2c22674c7e0d913cb2cffb40a98169d..6f226ac436622359b80debdb52e95cec1cdd09dc 100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -234,7 +234,6 @@ DEFINE_implication(track_double_fields, track_fields)
 DEFINE_implication(track_heap_object_fields, track_fields)
 DEFINE_implication(track_computed_fields, track_fields)
DEFINE_bool(smi_binop, true, "support smi representation in binary operations")
-DEFINE_bool(smi_x64_store_opt, false, "optimized stores of smi on x64")

 // Flags for optimization types.
 DEFINE_bool(optimize_for_size, false,
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index 9073ac36ca9983aa3e51550cb137b882370a511d..09ac767953b730b6abd4fb851aaa704ab5cb13b5 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -6534,7 +6534,6 @@ class HStoreNamedField V8_FINAL : public HTemplateInstruction<3> {
         write_barrier_mode_(UPDATE_WRITE_BARRIER),
         has_transition_(false),
         store_mode_(store_mode) {
-    if (!FLAG_smi_x64_store_opt) store_mode_ = INITIALIZING_STORE;
     // Stores to a non existing in-object property are allowed only to the
     // newly allocated objects (via HAllocate or HInnerAllocatedObject).
     ASSERT(!access.IsInobject() || access.existing_inobject_property() ||
@@ -6723,7 +6722,6 @@ class HStoreKeyed V8_FINAL
       is_uninitialized_(false),
       store_mode_(store_mode),
       new_space_dominator_(NULL) {
-    if (!FLAG_smi_x64_store_opt) store_mode_ = INITIALIZING_STORE;
     SetOperandAt(0, obj);
     SetOperandAt(1, key);
     SetOperandAt(2, val);
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index da415d463717bee4400ac088d80836f2cb672ecb..033a092c0d1580e963506d9114e6b60320069ebf 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -9853,6 +9853,8 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
         value_instruction = double_box;
       } else if (representation.IsSmi() && value->IsUninitialized()) {
         value_instruction = graph()->GetConstant0();
+        // Ensure that Constant0 is stored as smi.
+        access = access.WithRepresentation(representation);
       } else {
         value_instruction = Add<HConstant>(value);
       }
Index: src/x64/lithium-codegen-x64.cc
diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc
index ff9caa527c5649ba12481ad1bc132a342467376e..e006ba8492842606ec3901d6e1f8dfa271c4c276 100644
--- a/src/x64/lithium-codegen-x64.cc
+++ b/src/x64/lithium-codegen-x64.cc
@@ -3929,6 +3929,10 @@ void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) {
   if (representation.IsSmi() &&
       hinstr->value()->representation().IsInteger32()) {
     ASSERT(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY);
+#ifdef DEBUG
+    __ movq(kScratchRegister, FieldOperand(write_register, offset));
+    __ AssertSmi(kScratchRegister);
+#endif
     // Store int value directly to upper half of the smi.
     STATIC_ASSERT(kSmiTag == 0);
     STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 32);
Index: test/mjsunit/compiler/smi-stores-opt.js
diff --git a/test/mjsunit/recursive-store-opt.js b/test/mjsunit/compiler/smi-stores-opt.js
similarity index 90%
copy from test/mjsunit/recursive-store-opt.js
copy to test/mjsunit/compiler/smi-stores-opt.js
index fb2649248dbabc642f864f671d0ce2273ad44bd7..ca0923abc99501096d182bcdcd05f6f4020de9c9 100644
--- a/test/mjsunit/recursive-store-opt.js
+++ b/test/mjsunit/compiler/smi-stores-opt.js
@@ -27,15 +27,23 @@

 // Flags: --allow-natives-syntax

+var o = {a:1.5};
+o.a = 0;
+var a = o.a;
+
 function g() {
-  this.x = this;
+  return 1;
 }

+var o2 = {a:{}};
+
 function f() {
-  return new g();
+  var result = {a: a};
+  var literal = {x:g()};
+  return [result, literal];
 }

 f();
 f();
 %OptimizeFunctionOnNextCall(f);
-f();
+assertEquals(1, f()[1].x);


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