Home | History | Annotate | Download | only in compiler
      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 --turbo-osr
      6 
      7 function foo() {
      8   var sum = 0;
      9   A: for (var i = 0; i < 5; i++) {
     10     B: for (var j = 0; j < 5; j++) {
     11       C: for (var k = 0; k < 10; k++) {
     12         if (k === 5) %OptimizeOsr();
     13         if (k === 6) break B;
     14         sum++;
     15       }
     16     }
     17   }
     18   return sum;
     19 }
     20 
     21 assertEquals(30, foo());
     22 assertEquals(30, foo());
     23 
     24 function bar(a) {
     25   var sum = 0;
     26   A: for (var i = 0; i < 5; i++) {
     27     B: for (var j = 0; j < 5; j++) {
     28       C: for (var k = 0; k < 10; k++) {
     29         sum++;
     30         %OptimizeOsr();
     31         if (a === 1) break A;
     32         if (a === 2) break B;
     33         if (a === 3) break C;
     34       }
     35     }
     36   }
     37   return sum;
     38 }
     39 
     40 assertEquals(1, bar(1));
     41 assertEquals(1, bar(1));
     42 
     43 assertEquals(5, bar(2));
     44 assertEquals(5, bar(2));
     45 
     46 assertEquals(25, bar(3));
     47 assertEquals(25, bar(3));
     48