[turbofan] Skip write barriers when storing smi.
authorBenedikt Meurer <bmeurer@chromium.org>
Mon, 2 Mar 2015 09:08:46 +0000 (10:08 +0100)
committerBenedikt Meurer <bmeurer@chromium.org>
Mon, 2 Mar 2015 09:09:08 +0000 (09:09 +0000)
On 64-bit targets, we can skip the write barrier for Store nodes if the
input is ChangeInt32ToTagged, because the value being stored is
definitely represented as a smi then.

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/968113002

Cr-Commit-Position: refs/heads/master@{#26934}

src/compiler/simplified-lowering.cc
src/compiler/simplified-lowering.h
test/cctest/compiler/test-simplified-lowering.cc

index b3050719883c0467bf97f8d0610e494a3142c014..69d1d1ac79a40cbd3f55f836c64742b68a8219b7 100644 (file)
@@ -1135,10 +1135,14 @@ Node* SimplifiedLowering::OffsetMinusTagConstant(int32_t offset) {
 }
 
 
-static WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged,
-                                                MachineType representation,
-                                                Type* type) {
+WriteBarrierKind SimplifiedLowering::ComputeWriteBarrierKind(
+    BaseTaggedness base_is_tagged, MachineType representation, Node* value) {
   // TODO(turbofan): skip write barriers for Smis, etc.
+  if (machine()->Is64() && value->opcode() == IrOpcode::kChangeInt32ToTagged) {
+    // TODO(bmeurer): Remove this hack once we have a way to represent "sminess"
+    // of values, either in types or representations.
+    return kNoWriteBarrier;
+  }
   if (base_is_tagged == kTaggedBase &&
       RepresentationOf(representation) == kRepTagged) {
     // Write barriers are only for writes into heap objects (i.e. tagged base).
@@ -1159,7 +1163,7 @@ void SimplifiedLowering::DoLoadField(Node* node) {
 void SimplifiedLowering::DoStoreField(Node* node) {
   const FieldAccess& access = FieldAccessOf(node->op());
   WriteBarrierKind kind = ComputeWriteBarrierKind(
-      access.base_is_tagged, access.machine_type, access.type);
+      access.base_is_tagged, access.machine_type, node->InputAt(1));
   node->set_op(
       machine()->Store(StoreRepresentation(access.machine_type, kind)));
   Node* offset = jsgraph()->IntPtrConstant(access.offset - access.tag());
@@ -1267,7 +1271,7 @@ void SimplifiedLowering::DoStoreElement(Node* node) {
   node->set_op(machine()->Store(StoreRepresentation(
       access.machine_type,
       ComputeWriteBarrierKind(access.base_is_tagged, access.machine_type,
-                              access.type))));
+                              node->InputAt(2)))));
   node->ReplaceInput(1, ComputeIndex(access, node->InputAt(1)));
 }
 
index 11506e9ac01e6867ccd023a88bd67861953c3552..d206254a57c482b60b2bf0bccc363f972cbd11bb 100644 (file)
@@ -57,6 +57,9 @@ class SimplifiedLowering FINAL {
   Node* IsTagged(Node* node);
   Node* Untag(Node* node);
   Node* OffsetMinusTagConstant(int32_t offset);
+  WriteBarrierKind ComputeWriteBarrierKind(BaseTaggedness base_is_tagged,
+                                           MachineType representation,
+                                           Node* value);
   Node* ComputeIndex(const ElementAccess& access, Node* const key);
   Node* StringComparison(Node* node, bool requires_ordering);
   Node* Int32Div(Node* const node);
index a72f8bb2bbd1f05495a2190352bf7f88a7334963..2bd3eec46345aac02699d52451fe287d1490e09d 100644 (file)
@@ -1463,6 +1463,20 @@ TEST(LowerStoreField_to_store) {
     }
     CHECK_EQ(kMachineReps[i], rep.machine_type());
   }
+
+  if (t.machine()->Is64()) {
+    FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
+                          Handle<Name>::null(), Type::Any(), kMachAnyTagged};
+    Node* val = t.graph()->NewNode(t.simplified()->ChangeInt32ToTagged(), t.p0);
+    Node* store = t.graph()->NewNode(t.simplified()->StoreField(access), t.p0,
+                                     val, t.start, t.start);
+    t.Effect(store);
+    t.Lower();
+    CHECK_EQ(IrOpcode::kStore, store->opcode());
+    CHECK_EQ(val, store->InputAt(2));
+    StoreRepresentation rep = OpParameter<StoreRepresentation>(store);
+    CHECK_EQ(kNoWriteBarrier, rep.write_barrier_kind());
+  }
 }