1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Flags: --allow-natives-syntax --use-osr 6 7 function bar() { 8 var sum = 11; 9 var i = 35; 10 while (i-- > 31) { 11 LOOP1(); 12 j = 9; 13 while (j-- > 7) { 14 LOOP2(); 15 sum = sum + j * 5; 16 var k = 7; 17 while (k-- > 5) { 18 LOOP3(); 19 sum = sum + j * 5; 20 } 21 } 22 } 23 while (i-- > 29) { 24 LOOP4(); 25 while (j-- > 3) { 26 LOOP5(); 27 var k = 10; 28 while (k-- > 8) { 29 LOOP6(); 30 sum = sum + k * 11; 31 } 32 } 33 while (j-- > 1) { 34 LOOP7(); 35 var k = 8; 36 while (k-- > 6) { 37 LOOP8(); 38 var m = 9; 39 while (m-- > 6) { 40 LOOP9(); 41 sum = sum + k * 13; 42 } 43 } 44 } 45 } 46 return sum; 47 } 48 49 function gen(i) { 50 var body = bar.toString(); 51 body = body.replace(new RegExp("bar"), "bar" + i); 52 for (var j = 1; j < 10; j++) { 53 var r = new RegExp("LOOP" + j + "\\(\\);"); 54 if (i == j) body = body.replace(r, "%OptimizeOsr();"); 55 else body = body.replace(r, ""); 56 } 57 return eval("(" + body + ")"); 58 } 59 60 for (var i = 1; i < 10; i++) { 61 var f = gen(i); 62 assertEquals(1979, f()); 63 } 64