Reviewers: jarin,

Description:
[turbofan] Skip write barriers when storing smi.

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.

[email protected]

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+33, -3 lines):
  M src/compiler/machine-operator-reducer.cc
  M test/unittests/compiler/machine-operator-reducer-unittest.cc


Index: src/compiler/machine-operator-reducer.cc
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc index a609a8095eb715d52fc7ceaa0a4624c492f5fb2d..8040f767f33ccd993b5199695af5ff7844c52456 100644
--- a/src/compiler/machine-operator-reducer.cc
+++ b/src/compiler/machine-operator-reducer.cc
@@ -665,10 +665,20 @@ Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {


 Reduction MachineOperatorReducer::ReduceStore(Node* node) {
-  MachineType const rep =
-      RepresentationOf(StoreRepresentationOf(node->op()).machine_type());
+  StoreRepresentation const store_rep = StoreRepresentationOf(node->op());
+  MachineType const rep = RepresentationOf(store_rep.machine_type());
   Node* const value = node->InputAt(2);
   switch (value->opcode()) {
+    case IrOpcode::kChangeInt32ToTagged: {
+      // We don't need a write barrier if we know that we're storing a smi.
+      if (machine()->Is64() &&
+          store_rep.write_barrier_kind() != kNoWriteBarrier) {
+        node->set_op(machine()->Store(
+ StoreRepresentation(store_rep.machine_type(), kNoWriteBarrier)));
+        return Changed(node);
+      }
+      break;
+    }
     case IrOpcode::kWord32And: {
       Uint32BinopMatcher m(value);
       if (m.right().HasValue() &&
Index: test/unittests/compiler/machine-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc b/test/unittests/compiler/machine-operator-reducer-unittest.cc index 9656f57090524ad8bf3600ba57046bc3c6fce1c5..85461800dfd6baca3d722b29421d41c4d537b186 100644
--- a/test/unittests/compiler/machine-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc
@@ -6,6 +6,7 @@
 #include "src/base/division-by-constant.h"
 #include "src/compiler/js-graph.h"
 #include "src/compiler/machine-operator-reducer.h"
+#include "src/compiler/simplified-operator.h"
 #include "src/compiler/typer.h"
 #include "test/unittests/compiler/graph-unittest.h"
 #include "test/unittests/compiler/node-test-utils.h"
@@ -23,7 +24,7 @@ namespace compiler {
 class MachineOperatorReducerTest : public TypedGraphTest {
  public:
   explicit MachineOperatorReducerTest(int num_parameters = 2)
-      : TypedGraphTest(num_parameters), machine_(zone()) {}
+ : TypedGraphTest(num_parameters), machine_(zone()), simplified_(zone()) {}

  protected:
   Reduction Reduce(Node* node) {
@@ -54,9 +55,11 @@ class MachineOperatorReducerTest : public TypedGraphTest {
   }

   MachineOperatorBuilder* machine() { return &machine_; }
+  SimplifiedOperatorBuilder* simplified() { return &simplified_; }

  private:
   MachineOperatorBuilder machine_;
+  SimplifiedOperatorBuilder simplified_;
 };


@@ -1503,6 +1506,23 @@ TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32SarAndWord32Shl) {
   }
 }

+
+TEST_F(MachineOperatorReducerTest, StoreWithChangeInt32ToTagged) {
+  Node* const base = Parameter(0);
+  Node* const index = Parameter(1);
+  Node* const value =
+      graph()->NewNode(simplified()->ChangeInt32ToTagged(), Parameter(2));
+  Node* const effect = graph()->start();
+  Node* const control = graph()->start();
+  Reduction const r = Reduce(graph()->NewNode(
+      machine()->Store(StoreRepresentation(kRepTagged, kFullWriteBarrier)),
+      base, index, value, effect, control));
+  ASSERT_TRUE(r.Changed());
+  EXPECT_THAT(r.replacement(),
+ IsStore(StoreRepresentation(kRepTagged, kNoWriteBarrier), base,
+                      index, value, effect, control));
+}
+
 }  // namespace compiler
 }  // namespace internal
 }  // namespace v8


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