Home | History | Annotate | Download | only in compiler
      1 // Copyright 2014 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: --use-osr
      6 // TODO(titzer): enable --turbo-osr when nested OSR works.
      7 
      8 function f1(a,b,c) {
      9   var x = 0;
     10   var y = 0;
     11   var z = 0;
     12   for (var i = 0; i < 2; i++) {
     13     for (var j = 0; j < 2; j++) {
     14       while (a > 0) { x += 19; a--; }
     15       while (b > 0) { y += 23; b--; }
     16       while (c > 0) { z += 29; c--; }
     17     }
     18   }
     19   return x + y + z;
     20 }
     21 
     22 function f2(a,b,c) {
     23   var x = 0;
     24   var y = 0;
     25   var z = 0;
     26   for (var i = 0; i < 2; i++) {
     27     for (var j = 0; j < 2; j++) {
     28       while (a > 0) { x += 19; a--; }
     29       while (b > 0) { y += 23; b--; }
     30       while (c > 0) { z += 29; c--; }
     31     }
     32   }
     33   return x + y + z;
     34 }
     35 
     36 
     37 function f3(a,b,c) {
     38   var x = 0;
     39   var y = 0;
     40   var z = 0;
     41   for (var i = 0; i < 2; i++) {
     42     for (var j = 0; j < 2; j++) {
     43       while (a > 0) { x += 19; a--; }
     44       while (b > 0) { y += 23; b--; }
     45       while (c > 0) { z += 29; c--; }
     46     }
     47   }
     48   return x + y + z;
     49 }
     50 
     51 function check(f,a,b,c) {
     52   assertEquals(a * 19 + b * 23 + c * 29, f(a,b,c));
     53 }
     54 
     55 check(f1, 50000,     5,     6);
     56 check(f2,     4, 50000,     6);
     57 check(f3,    11,    12, 50000);
     58