Commit 2aa17c6e authored by ishell@chromium.org's avatar ishell@chromium.org

Load elimination fix: load should not be replaced with another load if the...

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

R=jkummerow@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18985 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fd6996ff
...@@ -203,9 +203,12 @@ class HLoadEliminationTable : public ZoneObject { ...@@ -203,9 +203,12 @@ class HLoadEliminationTable : public ZoneObject {
// Load is not redundant. Fill out a new entry. // Load is not redundant. Fill out a new entry.
approx->last_value_ = instr; approx->last_value_ = instr;
return instr; return instr;
} else { } else if (approx->last_value_->block()->EqualToOrDominates(
instr->block())) {
// Eliminate the load. Reuse previously stored value or load instruction. // Eliminate the load. Reuse previously stored value or load instruction.
return approx->last_value_; return approx->last_value_;
} else {
return instr;
} }
} }
......
...@@ -302,6 +302,12 @@ bool HBasicBlock::Dominates(HBasicBlock* other) const { ...@@ -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 { int HBasicBlock::LoopNestingDepth() const {
const HBasicBlock* current = this; const HBasicBlock* current = this;
int result = (current->IsLoopHeader()) ? 1 : 0; int result = (current->IsLoopHeader()) ? 1 : 0;
......
...@@ -112,6 +112,7 @@ class HBasicBlock V8_FINAL : public ZoneObject { ...@@ -112,6 +112,7 @@ class HBasicBlock V8_FINAL : public ZoneObject {
void RemovePhi(HPhi* phi); void RemovePhi(HPhi* phi);
void AddInstruction(HInstruction* instr, int position); void AddInstruction(HInstruction* instr, int position);
bool Dominates(HBasicBlock* other) const; bool Dominates(HBasicBlock* other) const;
bool EqualToOrDominates(HBasicBlock* other) const;
int LoopNestingDepth() const; int LoopNestingDepth() const;
void SetInitialEnvironment(HEnvironment* env); void SetInitialEnvironment(HEnvironment* env);
......
...@@ -43,6 +43,26 @@ function test_load() { ...@@ -43,6 +43,26 @@ function test_load() {
return a.x + a.x + a.x + a.x; 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() { function test_store_load() {
var a = new B(1, 2); var a = new B(1, 2);
a.x = 4; a.x = 4;
...@@ -128,6 +148,7 @@ function test(x, f) { ...@@ -128,6 +148,7 @@ function test(x, f) {
} }
test(4, test_load); test(4, test_load);
test(3, new test_load_from_different_contexts().g);
test(22, test_store_load); test(22, test_store_load);
test(8, test_nonaliasing_store1); test(8, test_nonaliasing_store1);
test(5, test_transitioning_store1); test(5, test_transitioning_store1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment