Commit 9b55ebaa authored by vegorov@chromium.org's avatar vegorov@chromium.org

When compiling for-in pass correct context value to the increment instruction.

Additionally force increment instruction to use int32 representation.

R=fschneider@google.com
BUG=http://crbug.com/115646
TEST=test/mjsunit/compiler/optimized-for-in.js

Review URL: https://chromiumcodereview.appspot.com/9463052

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10844 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d5e252b1
...@@ -169,7 +169,7 @@ DEFINE_int(stress_runs, 0, "number of stress runs") ...@@ -169,7 +169,7 @@ DEFINE_int(stress_runs, 0, "number of stress runs")
DEFINE_bool(optimize_closures, true, "optimize closures") DEFINE_bool(optimize_closures, true, "optimize closures")
DEFINE_int(loop_weight, 1, "loop weight for representation inference") DEFINE_int(loop_weight, 1, "loop weight for representation inference")
DEFINE_bool(optimize_for_in, false, DEFINE_bool(optimize_for_in, true,
"optimize functions containing for-in loops") "optimize functions containing for-in loops")
// Experimental profiler changes. // Experimental profiler changes.
......
...@@ -3075,7 +3075,6 @@ void HGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) { ...@@ -3075,7 +3075,6 @@ void HGraphBuilder::PreProcessOsrEntry(IterationStatement* statement) {
} }
} }
AddSimulate(osr_entry_id); AddSimulate(osr_entry_id);
AddInstruction(new(zone()) HOsrEntry(osr_entry_id)); AddInstruction(new(zone()) HOsrEntry(osr_entry_id));
HContext* context = new(zone()) HContext; HContext* context = new(zone()) HContext;
...@@ -3256,10 +3255,8 @@ void HGraphBuilder::VisitForInStatement(ForInStatement* stmt) { ...@@ -3256,10 +3255,8 @@ void HGraphBuilder::VisitForInStatement(ForInStatement* stmt) {
CHECK_ALIVE(VisitForValue(stmt->enumerable())); CHECK_ALIVE(VisitForValue(stmt->enumerable()));
HValue* enumerable = Top(); // Leave enumerable at the top. HValue* enumerable = Top(); // Leave enumerable at the top.
HValue* context = environment()->LookupContext();
HInstruction* map = AddInstruction(new(zone()) HForInPrepareMap( HInstruction* map = AddInstruction(new(zone()) HForInPrepareMap(
context, enumerable)); environment()->LookupContext(), enumerable));
AddSimulate(stmt->PrepareId()); AddSimulate(stmt->PrepareId());
HInstruction* array = AddInstruction( HInstruction* array = AddInstruction(
...@@ -3336,9 +3333,11 @@ void HGraphBuilder::VisitForInStatement(ForInStatement* stmt) { ...@@ -3336,9 +3333,11 @@ void HGraphBuilder::VisitForInStatement(ForInStatement* stmt) {
set_current_block(body_exit); set_current_block(body_exit);
HValue* current_index = Pop(); HValue* current_index = Pop();
PushAndAdd( HInstruction* new_index = new(zone()) HAdd(environment()->LookupContext(),
new(zone()) HAdd(context, current_index, graph()->GetConstant1())); current_index,
graph()->GetConstant1());
new_index->AssumeRepresentation(Representation::Integer32());
PushAndAdd(new_index);
body_exit = current_block(); body_exit = current_block();
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax // Flags: --optimize-for-in --allow-natives-syntax
// Test for-in support in Crankshaft. For simplicity this tests assumes certain // Test for-in support in Crankshaft. For simplicity this tests assumes certain
// fixed iteration order for properties and will have to be adjusted if V8 // fixed iteration order for properties and will have to be adjusted if V8
...@@ -247,13 +247,15 @@ tryFunction("a1b2c3d4e5f6", function () { ...@@ -247,13 +247,15 @@ tryFunction("a1b2c3d4e5f6", function () {
function osr_inner(t, limit) { function osr_inner(t, limit) {
var r = 1; var r = 1;
for (var x in t) { for (var x in t) {
for (var i = 0; i < t[x].length; i++) { if (t.hasOwnProperty(x)) {
r += t[x][i]; for (var i = 0; i < t[x].length; i++) {
if (i === limit) { r += t[x][i];
%OptimizeFunctionOnNextCall(osr_inner, "osr"); if (i === limit) {
%OptimizeFunctionOnNextCall(osr_inner, "osr");
}
} }
r += x;
} }
r += x;
} }
return r; return r;
} }
...@@ -290,7 +292,7 @@ function test_osr() { ...@@ -290,7 +292,7 @@ function test_osr() {
arr[i] = i + 1; arr[i] = i + 1;
} }
arr.push(":"); // Force deopt at the end of the loop. arr.push(":"); // Force deopt at the end of the loop.
assertEquals("211:x", osr_inner({x: arr}, (arr.length / 2) | 0)); assertEquals("211:x1234567891011121314151617181920:y", osr_inner({x: arr, y: arr}, (arr.length / 2) | 0));
assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x")); assertEquals("7x456y", osr_outer({x: [1,2,3], y: [4,5,6]}, "x"));
assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5")); assertEquals("101234567", osr_outer_and_deopt([1,2,3,4,5,6,7,8], "5"));
} }
......
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