Reviewers: Jakob,

Message:
PTAL

Description:
Load elimination fix: load should not be replaced with another load if the
former is not dominated by the latter.

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

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

Affected files (+32, -1 lines):
  M src/hydrogen-load-elimination.cc
  M src/hydrogen.h
  M src/hydrogen.cc
  M test/mjsunit/compiler/load-elimination.js


Index: src/hydrogen-load-elimination.cc
diff --git a/src/hydrogen-load-elimination.cc b/src/hydrogen-load-elimination.cc index ea12df865d7b0d91a43eb6f7162374e538509afb..634d75d8620f5ec866048f9794b8e2ff87a5a0a2 100644
--- a/src/hydrogen-load-elimination.cc
+++ b/src/hydrogen-load-elimination.cc
@@ -203,9 +203,12 @@ class HLoadEliminationTable : public ZoneObject {
       // Load is not redundant. Fill out a new entry.
       approx->last_value_ = instr;
       return instr;
-    } else {
+    } else if (approx->last_value_->block()->EqualToOrDominates(
+        instr->block())) {
// Eliminate the load. Reuse previously stored value or load instruction.
       return approx->last_value_;
+    } else {
+      return instr;
     }
   }

Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 3c7bf5064b1683c2c8609a52ff6057d5eadda29d..9b511992489705367a04cf2372321c40bd8fb6fe 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -302,6 +302,12 @@ bool HBasicBlock::Dominates(HBasicBlock* other) const {
 }


+bool HBasicBlock::EqualToOrDominates(HBasicBlock* other) const {
+  if (this == other) return true;
+  return Dominates(other);
+}
+
+
 int HBasicBlock::LoopNestingDepth() const {
   const HBasicBlock* current = this;
   int result  = (current->IsLoopHeader()) ? 1 : 0;
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index a9c0d3204aff09ce3005e2006b61337e29366742..d863e3d11643d892874e9dd261f36c6589b44957 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -112,6 +112,7 @@ class HBasicBlock V8_FINAL : public ZoneObject {
   void RemovePhi(HPhi* phi);
   void AddInstruction(HInstruction* instr, int position);
   bool Dominates(HBasicBlock* other) const;
+  bool EqualToOrDominates(HBasicBlock* other) const;
   int LoopNestingDepth() const;

   void SetInitialEnvironment(HEnvironment* env);
Index: test/mjsunit/compiler/load-elimination.js
diff --git a/test/mjsunit/compiler/load-elimination.js b/test/mjsunit/compiler/load-elimination.js index e6a82451821288e5a4665764e6e8b88b7387f72f..9bf8564308218e05973accbe1015a00eb46eae5d 100644
--- a/test/mjsunit/compiler/load-elimination.js
+++ b/test/mjsunit/compiler/load-elimination.js
@@ -43,6 +43,26 @@ function test_load() {
   return a.x + a.x + a.x + a.x;
 }

+
+function test_load_from_different_contexts() {
+  var r = 1;
+  this.f = function() {
+    var fr = r;
+    this.g = function(flag) {
+      var gr;
+      if (flag) {
+        gr = r;
+      } else {
+        gr = r;
+      }
+      return gr + r + fr;
+    };
+  };
+  this.f();
+  return this.g(true);
+}
+
+
 function test_store_load() {
   var a = new B(1, 2);
   a.x = 4;
@@ -128,6 +148,7 @@ function test(x, f) {
 }

 test(4, test_load);
+test(3, new test_load_from_different_contexts().g);
 test(22, test_store_load);
 test(8, test_nonaliasing_store1);
 test(5, test_transitioning_store1);


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