Reviewers: ulan, jochen (OOO until March 10),

Description:
A64: Improve constraints on StoreKeyed instructions

BUG=

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

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

Affected files (+19, -16 lines):
  M src/a64/lithium-a64.cc
  M src/a64/lithium-codegen-a64.cc


Index: src/a64/lithium-a64.cc
diff --git a/src/a64/lithium-a64.cc b/src/a64/lithium-a64.cc
index cf89c09f5b2515d2dbc0b6cabe667b10245eb9ea..38f9c731041430afd0955a52e42194d4e695fb5b 100644
--- a/src/a64/lithium-a64.cc
+++ b/src/a64/lithium-a64.cc
@@ -2169,7 +2169,7 @@ LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
   LOperand* temp = NULL;
   LOperand* elements = NULL;
   LOperand* val = NULL;
-  LOperand* key = NULL;
+  LOperand* key = UseRegisterOrConstantAtStart(instr->key());

   if (!instr->is_typed_elements() &&
       instr->value()->representation().IsTagged() &&
@@ -2177,11 +2177,11 @@ LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
     // RecordWrite() will clobber all registers.
     elements = UseRegisterAndClobber(instr->elements());
     val = UseRegisterAndClobber(instr->value());
-    key = UseRegisterAndClobber(instr->key());
+    temp = TempRegister();
   } else {
     elements = UseRegister(instr->elements());
     val = UseRegister(instr->value());
-    key = UseRegisterOrConstantAtStart(instr->key());
+    temp = instr->key()->IsConstant() ? NULL : TempRegister();
   }

   if (instr->is_typed_elements()) {
@@ -2193,23 +2193,16 @@ LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) {
             instr->elements()->representation().IsTagged()) ||
            (instr->is_external() &&
             instr->elements()->representation().IsExternal()));
-    temp = instr->key()->IsConstant() ? NULL : TempRegister();
     return new(zone()) LStoreKeyedExternal(elements, key, val, temp);

   } else if (instr->value()->representation().IsDouble()) {
     ASSERT(instr->elements()->representation().IsTagged());
-
-    // The constraint used here is UseRegister, even though the StoreKeyed
- // instruction may canonicalize the value in the register if it is a NaN.
-    temp = TempRegister();
     return new(zone()) LStoreKeyedFixedDouble(elements, key, val, temp);

   } else {
     ASSERT(instr->elements()->representation().IsTagged());
     ASSERT(instr->value()->representation().IsSmiOrTagged() ||
            instr->value()->representation().IsInteger32());
-
-    temp = TempRegister();
     return new(zone()) LStoreKeyedFixed(elements, key, val, temp);
   }
 }
Index: src/a64/lithium-codegen-a64.cc
diff --git a/src/a64/lithium-codegen-a64.cc b/src/a64/lithium-codegen-a64.cc
index ad8d742abac2cc894d292e026d7005b67933e834..d7dd832a8593385765f39f2107deb17f77b3e94a 100644
--- a/src/a64/lithium-codegen-a64.cc
+++ b/src/a64/lithium-codegen-a64.cc
@@ -5059,7 +5059,7 @@ void LCodeGen::DoStoreKeyedExternal(LStoreKeyedExternal* instr) {
 void LCodeGen::DoStoreKeyedFixedDouble(LStoreKeyedFixedDouble* instr) {
   Register elements = ToRegister(instr->elements());
   DoubleRegister value = ToDoubleRegister(instr->value());
-  Register store_base = ToRegister(instr->temp());
+  Register store_base = no_reg;
   int offset = 0;

   if (instr->key()->IsConstantOperand()) {
@@ -5071,6 +5071,7 @@ void LCodeGen::DoStoreKeyedFixedDouble(LStoreKeyedFixedDouble* instr) { instr->additional_index());
     store_base = elements;
   } else {
+    store_base = ToRegister(instr->temp());
     Register key = ToRegister(instr->key());
bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi();
     CalcKeyedArrayBaseRegister(store_base, elements, key, key_is_tagged,
@@ -5093,17 +5094,23 @@ void LCodeGen::DoStoreKeyedFixedDouble(LStoreKeyedFixedDouble* instr) {
 void LCodeGen::DoStoreKeyedFixed(LStoreKeyedFixed* instr) {
   Register value = ToRegister(instr->value());
   Register elements = ToRegister(instr->elements());
-  Register store_base = ToRegister(instr->temp());
+  Register scratch = no_reg;
+  Register store_base = no_reg;
   Register key = no_reg;
   int offset = 0;

+  if (!instr->key()->IsConstantOperand() ||
+      instr->hydrogen()->NeedsWriteBarrier()) {
+    scratch = ToRegister(instr->temp());
+  }
+
   if (instr->key()->IsConstantOperand()) {
-    ASSERT(!instr->hydrogen()->NeedsWriteBarrier());
     LConstantOperand* const_operand = LConstantOperand::cast(instr->key());
     offset = FixedArray::OffsetOfElementAt(ToInteger32(const_operand) +
                                            instr->additional_index());
     store_base = elements;
   } else {
+    store_base = scratch;
     key = ToRegister(instr->key());
bool key_is_tagged = instr->hydrogen()->key()->representation().IsSmi();
     CalcKeyedArrayBaseRegister(store_base, elements, key, key_is_tagged,
@@ -5122,13 +5129,16 @@ void LCodeGen::DoStoreKeyedFixed(LStoreKeyedFixed* instr) {
   }

   if (instr->hydrogen()->NeedsWriteBarrier()) {
+    ASSERT(representation.IsTagged());
+    // This assignment may cause element_addr to alias store_base.
+    Register element_addr = scratch;
     SmiCheck check_needed =
         instr->hydrogen()->value()->IsHeapObject()
             ? OMIT_SMI_CHECK : INLINE_SMI_CHECK;
     // Compute address of modified element and store it into key register.
-    __ Add(key, store_base, offset - kHeapObjectTag);
- __ RecordWrite(elements, key, value, GetLinkRegisterState(), kSaveFPRegs,
-                   EMIT_REMEMBERED_SET, check_needed);
+    __ Add(element_addr, store_base, offset - kHeapObjectTag);
+    __ RecordWrite(elements, element_addr, value, GetLinkRegisterState(),
+                   kSaveFPRegs, EMIT_REMEMBERED_SET, check_needed);
   }
 }



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