Index: test/mjsunit/induction-variable-turbofan.js |
diff --git a/test/mjsunit/induction-variable-turbofan.js b/test/mjsunit/induction-variable-turbofan.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e467d4745278b4f3cb923968304df831ca42bb9d |
--- /dev/null |
+++ b/test/mjsunit/induction-variable-turbofan.js |
@@ -0,0 +1,125 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Redistribution and use in source and binary forms, with or without |
+// modification, are permitted provided that the following conditions are |
+// met: |
+// |
+// * Redistributions of source code must retain the above copyright |
+// notice, this list of conditions and the following disclaimer. |
+// * Redistributions in binary form must reproduce the above |
+// copyright notice, this list of conditions and the following |
+// disclaimer in the documentation and/or other materials provided |
+// with the distribution. |
+// * Neither the name of Google Inc. nor the names of its |
+// contributors may be used to endorse or promote products derived |
+// from this software without specific prior written permission. |
+// |
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Jarin
2016/08/22 07:27:20
Nit: you can use a shorter copyright. E.g., see te
Franzi
2016/08/22 09:06:30
Done.
|
+ |
+// Flags: --allow-natives-syntax --turbo |
+ |
+// TurboFan optimizes integer loops. These tests check that we compute |
+// the corret upper and lower bounds. |
Jarin
2016/08/22 07:27:20
Nit: corret -> correct.
Franzi
2016/08/22 09:06:30
Done.
|
+function positive_increment() { |
+ for (var i = 5; i < 10; i++) { |
+ if (i < 0) break; |
+ if (i > 20) break; |
+ if (i === 7) return true; |
+ } |
+ return false; |
+} |
+ |
+function positive_increment_strict() { |
+ for (var i = 5; i < 10; i++) { |
+ if (i < 0) break; |
Jarin
2016/08/22 07:27:20
Could we change the i < 0 branches to return false
Franzi
2016/08/22 09:06:30
Done.
|
+ if (i === 10) return false; |
+ } |
+ return true; |
+} |
+ |
+function positive_increment_non_strict() { |
+ for (var i = 5; i <= 10; i++) { |
+ if (i < 0) break; |
+ if (i === 10) return true; |
+ } |
+ return false; |
+} |
+ |
+function negative_increment() { |
+ for (var i = 10; i > 5;) { |
+ if (i < 0) break; |
+ if (i > 20) break; |
+ if (i === 7) return true; |
+ i -= 1; |
+ } |
+ return false; |
+} |
+ |
+function positive_decrement() { |
+ for (var i = 10; i > 5; i--) { |
+ if (i < 0) break; |
+ if (i === 7) return true; |
+ } |
+ return false; |
+} |
+ |
+function positive_decrement_strict() { |
+ for (var i = 10; i > 5; i--) { |
+ if (i < 0) break; |
+ if (i === 5) return false; |
+ } |
+ return true; |
+} |
+function positive_decrement_non_strict() { |
+ for (var i = 10; i >= 5; i--) { |
+ if (i < 0) break; |
+ if (i === 5) return true; |
+ } |
+ return false; |
+} |
+ |
+function negative_decrement() { |
+ for (var i = 5; i < 10;) { |
+ if (i < 0) break; |
+ if (i === 7) return true; |
+ i -= -1; |
+ } |
+ return false; |
+} |
+ |
+function variable_bound() { |
+ for (var i = 5; i < 10; i++) { |
+ for (var j = 5; j < i; j++) { |
+ if (j < 0) break; |
+ if (j === 7) return true; |
+ } |
+ } |
+ return false; |
+ |
+} |
+ |
+function test(f) { |
+ f(); |
+ assertTrue(f()); |
+ %OptimizeFunctionOnNextCall(f); |
+ assertTrue(f()); |
+} |
+ |
+test(positive_increment); |
+test(positive_increment_strict); |
+test(positive_increment_non_strict); |
+test(negative_increment); |
+test(positive_decrement); |
+test(positive_decrement_strict); |
+test(positive_decrement_non_strict); |
+test(negative_decrement); |
+test(variable_bound); |