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

Side by Side Diff: test/mjsunit/compiler/store-elimination.js

Issue 100253004: First implementation of store elimination. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --allow-natives-syntax --load-elimination 28 // Flags: --allow-natives-syntax --store-elimination
29 29
30 // Test local load elimination of redundant loads and stores. 30 // Test local elimination of unobservable stores.
31 31
32 function B(x, y) { 32 function B(x, y) {
33 this.x = x; 33 this.x = x;
34 this.y = y; 34 this.y = y;
35 return this; 35 return this;
36 } 36 }
37 37
38 function test_load() { 38 function test_store_store() {
39 var a = new B(1, 2); 39 var a = new B(1, 2);
40 return a.x + a.x + a.x + a.x; 40 a.x = 3; // eliminatable.
41 a.x = 4;
42 return a.x;
41 } 43 }
42 44
43 function test_store_load() { 45 function test_store_load_store1() {
44 var a = new B(1, 2); 46 var a = new B(6, 7);
47 a.x = 3; // eliminatable.
48 var r = a.y;
45 a.x = 4; 49 a.x = 4;
46 var f = a.x; 50 return r;
47 a.x = 5;
48 var g = a.x;
49 a.x = 6;
50 var h = a.x;
51 a.x = 7;
52 return f + g + h + a.x;
53 } 51 }
54 52
55 function test_nonaliasing_store1() { 53 function test_store_load_store2() {
56 var a = new B(2, 3), b = new B(3, 4); 54 var a = new B(6, 8);
57 b.x = 4; 55 a.x = 3; // not eliminatable, unless next load is eliminated.
58 var f = a.x; 56 var r = a.x;
59 b.x = 5; 57 a.x = 4;
60 var g = a.x; 58 return r;
61 b.x = 6; 59 }
62 var h = a.x; 60
63 b.x = 7; 61 function test_store_call_store() {
64 return f + g + h + a.x; 62 var a = new B(2, 9);
63 a.x = 3; // not eliminatable.
64 killall();
65 a.x = 4;
66 return a.y;
67 }
68
69 function test_store_deopt_store() {
70 var a = new B(2, 1);
71 a.x = 3; // not eliminatable (implicit ValueOf following)
72 var c = a + 2;
73 a.x = 4;
74 return a.y;
65 } 75 }
66 76
67 function killall() { 77 function killall() {
68 try { } catch(e) { } 78 try { } catch(e) { }
69 } 79 }
70 80
71 %NeverOptimizeFunction(killall); 81 %NeverOptimizeFunction(killall);
72 82
73 function test_store_load_kill() {
74 var a = new B(1, 2);
75 a.x = 4;
76 var f = a.x;
77 a.x = 5;
78 var g = a.x;
79 killall();
80 a.x = 6;
81 var h = a.x;
82 a.x = 7;
83 return f + g + h + a.x;
84 }
85
86 function test_store_store() {
87 var a = new B(6, 7);
88 a.x = 7;
89 a.x = 7;
90 a.x = 7;
91 a.x = 7;
92 return a.x;
93 }
94
95 function test(x, f) { 83 function test(x, f) {
96 assertEquals(x, f()); 84 assertEquals(x, f());
97 assertEquals(x, f()); 85 assertEquals(x, f());
98 %OptimizeFunctionOnNextCall(f); 86 %OptimizeFunctionOnNextCall(f);
99 assertEquals(x, f()); 87 assertEquals(x, f());
100 } 88 }
101 89
102 test(4, test_load); 90 test(4, test_store_store);
103 test(22, test_store_load); 91 test(7, test_store_load_store1);
104 test(8, test_nonaliasing_store1); 92 test(3, test_store_load_store2);
105 test(22, test_store_load_kill); 93 test(9, test_store_call_store);
106 test(7, test_store_store); 94 test(1, test_store_deopt_store);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698