Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Unified Diff: test/mjsunit/compiler/dead-loops-neg.js

Issue 98323004: Add some test cases with dead loops. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/compiler/dead-loops.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/compiler/dead-loops-neg.js
diff --git a/test/mjsunit/compiler/property-static.js b/test/mjsunit/compiler/dead-loops-neg.js
similarity index 51%
copy from test/mjsunit/compiler/property-static.js
copy to test/mjsunit/compiler/dead-loops-neg.js
index 07021340cd7aa94440638f925eeed921ee78c9c7..dbf500b48e773740068aa2318278b66f46ebdaeb 100644
--- a/test/mjsunit/compiler/property-static.js
+++ b/test/mjsunit/compiler/dead-loops-neg.js
@@ -27,43 +27,74 @@
// Flags: --allow-natives-syntax
-// Test usage of static type information for loads that would otherwise
-// turn into polymorphic or generic loads.
+// Presents negative opportunities for dead loop removal.
-// Prepare a highly polymorphic load to be used by all tests.
-Object.prototype.load = function() { return this.property; };
-Object.prototype.load.call({ A:0, property:10 });
-Object.prototype.load.call({ A:0, B:0, property:11 });
-Object.prototype.load.call({ A:0, B:0, C:0, property:12 });
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, property:13 });
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, property:14 });
-Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, F:0, property:15 });
+function loop1() {
+ while (true) return;
+}
-// Test for object literals.
-(function() {
- function f(x) {
- var object = { property:x };
- return object.load();
- }
+function loop2() {
+ var i = 0;
+ while (i++ < 10) ;
+ return i; // value of {i} escapes.
+ // can only remove the loop with induction variable analysis.
+}
- assertSame(1, f(1));
- assertSame(2, f(2));
- %OptimizeFunctionOnNextCall(f);
- assertSame(3, f(3));
-})();
+function loop3() {
+ var i = 0;
+ for (; i < 10; i++) ;
+ return i; // value of {i} escapes.
+ // can only remove the loop with induction variable analysis.
+}
-// Test for inlined constructors.
-(function() {
- function c(x) {
- this.property = x;
- }
- function f(x) {
- var object = new c(x);
- return object.load();
+function loop4() {
+ var a = 0;
+ for (var i = 0; i < 10; i++) a++;
+ return a; // value of {a} escapes.
+ // can only remove the loop with induction variable analysis.
+}
+
+function loop5() {
+ var a = new Int32Array(4), sum = 0;
+ for (var i = 0; i < a.length; i++) {
+ sum += a[i];
}
+ return sum; // {sum} escapes.
+ // can only remove the loop by figuring out that all elements of {a} are 0.
+}
+
+function loop6(a) {
+ for (var i = 0; i < a; i++) ; // implicit a.valueOf().
+ // can only remove the loop by guarding on the type of a.
+}
+
+function loop7(a) {
+ for (var i = 0; i < 10; i++) a.toString(); // unknown side-effect on a.
+ // can only remove the loop by guarding on the type of a.
+}
+
+function loop8(a) {
+ for (var i = 0; i < 10; i++) a.valueOf(); // unknown side-effect on a.
+ // can only remove the loop by guarding on the type of a.
+}
+
+var no_params_loops = [loop1, loop2, loop3, loop4, loop5, loop6];
+var params_loops = [loop6, loop7, loop8];
+
+for (var i = 0; i < no_params_loops.length; i++) {
+ var f = no_params_loops[i];
+ f();
+ f();
+ f();
+ %OptimizeFunctionOnNextCall(f);
+ f();
+}
- assertSame(1, f(1));
- assertSame(2, f(2));
+for (var i = 0; i < params_loops.length; i++) {
+ var f = params_loops[i];
+ f(3);
+ f(7);
+ f(11);
%OptimizeFunctionOnNextCall(f);
- assertSame(3, f(3));
-})();
+ f(9);
+}
« no previous file with comments | « test/mjsunit/compiler/dead-loops.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698