Chromium Code Reviews| Index: test/mjsunit/compiler/load-elimination-global.js |
| diff --git a/test/mjsunit/compiler/load-elimination.js b/test/mjsunit/compiler/load-elimination-global.js |
| similarity index 70% |
| copy from test/mjsunit/compiler/load-elimination.js |
| copy to test/mjsunit/compiler/load-elimination-global.js |
| index e019508c65ebdc9eb08e03979f81b70633f55319..2f5d6b309bb572c63febd559e712817d50a5486b 100644 |
| --- a/test/mjsunit/compiler/load-elimination.js |
| +++ b/test/mjsunit/compiler/load-elimination-global.js |
| @@ -27,7 +27,12 @@ |
| // Flags: --allow-natives-syntax --load-elimination |
| -// Test local load elimination of redundant loads and stores. |
| +// Test global load elimination of redundant loads and stores. |
| + |
| +var X = true; // For forcing branches. |
| +X = false; |
| +X = true; |
| +X = false; |
| function B(x, y) { |
| this.x = x; |
| @@ -37,33 +42,65 @@ function B(x, y) { |
| function test_load() { |
| var a = new B(1, 2); |
| - return a.x + a.x + a.x + a.x; |
| + var f = a.x + a.x; |
| + if (false) ; |
| + return f + a.x + a.x; |
| +} |
| + |
| +function test_load2() { |
| + var a = new B(1, 2); |
| + var f = a.x + a.x; |
| + if (true) ; |
| + return f + a.x + a.x; |
| } |
| function test_store_load() { |
| var a = new B(1, 2); |
| a.x = 4; |
| - var f = a.x; |
| - a.x = 5; |
| - var g = a.x; |
| - a.x = 6; |
| - var h = a.x; |
| - a.x = 7; |
| - return f + g + h + a.x; |
| + var b = X ? a.x : a.x; |
| + return b + a.x; |
| +} |
| + |
| +function test_store_load2() { |
| + var a = new B(1, 2); |
| + var c = 6; |
| + if (X) a.x = c; |
| + else a.x = c; |
| + return a.x + a.x; |
| } |
| function test_nonaliasing_store1() { |
| var a = new B(2, 3), b = new B(3, 4); |
| + if (X) ; |
| b.x = 4; |
| + if (X) ; |
| var f = a.x; |
| + if (X) ; |
| b.x = 5; |
| + if (X) ; |
| var g = a.x; |
| + if (X) ; |
| b.x = 6; |
| + if (X) ; |
| var h = a.x; |
| + if (X) ; |
| b.x = 7; |
| + if (X) ; |
| return f + g + h + a.x; |
| } |
| +function test_loop(x) { |
|
mvstanton
2013/10/17 10:32:55
Could you have another test (or extend this one) t
|
| + var a = new B(2, 3); |
| + var v = a.x; |
| + var total = v; |
| + var i = 0; |
| + while (i++ < 10) { |
| + total = a.x; |
| + a.y = 4; |
| + } |
| + return total; |
| +} |
| + |
| function killall() { |
| try { } catch(e) { } |
| } |
| @@ -72,35 +109,60 @@ function killall() { |
| function test_store_load_kill() { |
| var a = new B(1, 2); |
| + if (X) ; |
| a.x = 4; |
| + if (X) ; |
| var f = a.x; |
| + if (X) ; |
| a.x = 5; |
| + if (X) ; |
| var g = a.x; |
| + if (X) ; |
| killall(); |
| + if (X) ; |
| a.x = 6; |
| + if (X) ; |
| var h = a.x; |
| + if (X) ; |
| a.x = 7; |
| + if (X) ; |
| return f + g + h + a.x; |
| } |
| function test_store_store() { |
| var a = new B(6, 7); |
| + if (X) ; |
| a.x = 7; |
| + if (X) ; |
| a.x = 7; |
| + if (X) ; |
| a.x = 7; |
| + if (X) ; |
| a.x = 7; |
| + if (X) ; |
| return a.x; |
| } |
| function test(x, f) { |
| + X = true; |
| assertEquals(x, f()); |
| assertEquals(x, f()); |
| + X = false; |
| + assertEquals(x, f()); |
| + assertEquals(x, f()); |
| + X = true; |
| %OptimizeFunctionOnNextCall(f); |
| assertEquals(x, f()); |
| + assertEquals(x, f()); |
| + X = false; |
| + assertEquals(x, f()); |
| + assertEquals(x, f()); |
| } |
| test(4, test_load); |
| -test(22, test_store_load); |
| +test(8, test_store_load); |
| +test(12, test_store_load2); |
| test(8, test_nonaliasing_store1); |
| test(22, test_store_load_kill); |
| test(7, test_store_store); |
| +test(2, test_loop); |