From fa8a182208fe4068e8d897ee1cc7165ad5ce3326 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Mon, 2 Sep 2013 16:51:44 +0000 Subject: [PATCH] Fix OSR to ignore phis without merge index in loop entry. This fixes a corner case introduced by escape analysis where phis are introduced in OSR loop entry blocks that don't have a merge index and hence cannot contain OSR values. R=titzer@chromium.org TEST=mjsunit/compiler/escape-analysis Review URL: https://codereview.chromium.org/23503025 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16484 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen-osr.cc | 5 ++-- test/mjsunit/compiler/escape-analysis.js | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/hydrogen-osr.cc b/src/hydrogen-osr.cc index 73fa40a..bf6233b 100644 --- a/src/hydrogen-osr.cc +++ b/src/hydrogen-osr.cc @@ -117,8 +117,9 @@ void HOsrBuilder::FinishOsrValues() { const ZoneList* phis = osr_loop_entry_->phis(); for (int j = 0; j < phis->length(); j++) { HPhi* phi = phis->at(j); - ASSERT(phi->HasMergedIndex()); - osr_values_->at(phi->merged_index())->set_incoming_value(phi); + if (phi->HasMergedIndex()) { + osr_values_->at(phi->merged_index())->set_incoming_value(phi); + } } } diff --git a/test/mjsunit/compiler/escape-analysis.js b/test/mjsunit/compiler/escape-analysis.js index f32069c..7452e3b 100644 --- a/test/mjsunit/compiler/escape-analysis.js +++ b/test/mjsunit/compiler/escape-analysis.js @@ -200,3 +200,44 @@ check(27, 27); check(27, 27); assertEquals(130, sum); })(); + + +// Test OSR into a loop with captured objects. +(function testOSR() { + function constructor() { + this.a = 23; + } + function osr1(length) { + assertEquals(23, (new constructor()).a); + var result = 0; + for (var i = 0; i < length; i++) { + result = (result + i) % 99; + } + return result; + } + function osr2(length) { + var result = 0; + for (var i = 0; i < length; i++) { + result = (result + i) % 99; + } + assertEquals(23, (new constructor()).a); + return result; + } + function osr3(length) { + var result = 0; + var o = new constructor(); + for (var i = 0; i < length; i++) { + result = (result + i) % 99; + } + assertEquals(23, o.a); + return result; + } + function test(closure) { + assertEquals(45, closure(10)); + assertEquals(45, closure(10)); + assertEquals(10, closure(50000)); + } + test(osr1); + test(osr2); + test(osr3); +})(); -- 2.7.4