From 994f0f6dda0390d58e2b56055b26d0381a85501d Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Tue, 11 Feb 2014 16:02:18 +0000 Subject: [PATCH] Fix for a smi stores optimization on x64 with a test case. BUG=338425 LOG=N R=verwaest@chromium.org Review URL: https://codereview.chromium.org/152923006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19288 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/flag-definitions.h | 1 - src/hydrogen-instructions.h | 2 -- src/hydrogen.cc | 2 ++ src/x64/lithium-codegen-x64.cc | 4 +++ test/mjsunit/compiler/smi-stores-opt.js | 49 +++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/mjsunit/compiler/smi-stores-opt.js diff --git a/src/flag-definitions.h b/src/flag-definitions.h index c71d9e0..d6ddaa5 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, diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index 0359250..63368ce 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -6516,7 +6516,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() || @@ -6705,7 +6704,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); diff --git a/src/hydrogen.cc b/src/hydrogen.cc index f2b2d55..cb918ca 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -9816,6 +9816,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(value); } diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 57e0ea0..ecc0522 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -3928,6 +3928,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); diff --git a/test/mjsunit/compiler/smi-stores-opt.js b/test/mjsunit/compiler/smi-stores-opt.js new file mode 100644 index 0000000..ca0923a --- /dev/null +++ b/test/mjsunit/compiler/smi-stores-opt.js @@ -0,0 +1,49 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Flags: --allow-natives-syntax + +var o = {a:1.5}; +o.a = 0; +var a = o.a; + +function g() { + return 1; +} + +var o2 = {a:{}}; + +function f() { + var result = {a: a}; + var literal = {x:g()}; + return [result, literal]; +} + +f(); +f(); +%OptimizeFunctionOnNextCall(f); +assertEquals(1, f()[1].x); -- 2.7.4