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

Side by Side Diff: tests/language/load_to_load_forwarding_vm_test.dart

Issue 17101028: Refactor load forwarding pass to use a Place abstraction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // Test correctness of side effects tracking used by load to load forwarding. 4 // Test correctness of side effects tracking used by load to load forwarding.
5 5
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "dart:typed_data"; 7 import "dart:typed_data";
8 8
9 class A { 9 class A {
10 var x, y; 10 var x, y;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 return arr.length; // Immutable length load. 44 return arr.length; // Immutable length load.
45 } 45 }
46 46
47 if (arr.length < 2) { // Mutable length load, should not be forwarded. 47 if (arr.length < 2) { // Mutable length load, should not be forwarded.
48 arr.add(null); 48 arr.add(null);
49 } 49 }
50 50
51 return arr.length; 51 return arr.length;
52 } 52 }
53 53
54
55 testPhiRepresentation(f, arr) { 54 testPhiRepresentation(f, arr) {
56 if (f) { 55 if (f) {
57 arr[0] = arr[0] + arr[1]; 56 arr[0] = arr[0] + arr[1];
58 } else { 57 } else {
59 arr[0] = arr[0] - arr[1]; 58 arr[0] = arr[0] - arr[1];
60 } 59 }
61 return arr[0]; 60 return arr[0];
62 } 61 }
63 62
64
65 testPhiConvertions(f, arr) { 63 testPhiConvertions(f, arr) {
66 if (f) { 64 if (f) {
67 arr[0] = arr[1]; 65 arr[0] = arr[1];
68 } else { 66 } else {
69 arr[0] = arr[2]; 67 arr[0] = arr[2];
70 } 68 }
71 return arr[0]; 69 return arr[0];
72 } 70 }
73 71
72 class X {
73 var next;
74 X(this.next);
75 }
76
77 testPhiForwarding(obj) {
78 if (obj.next == null) {
79 return 1;
80 }
81
82 var len = 0;
83 while (obj != null) {
84 len++;
85 obj = obj.next; // This load should not be forwarded.
86 }
87
88 return len;
89 }
90
91 testPhiForwarding2(obj) {
92 if (obj.next == null) {
93 return 1;
94 }
95
96 var len = 0, next = null;
97 while ((obj != null) && len < 2) {
98 len++;
99 obj = obj.next; // This load should be forwarded.
100 next = obj.next;
101 }
102
103 return len;
104 }
105
106 class V {
107 final f;
108 V(this.f);
109 }
110
111 testPhiForwarding3() {
112 var a = new V(-0.1);
113 var c = new V(0.0);
114 var b = new V(0.1);
115
116 for (var i = 0; i < 3; i++) {
117 var af = a.f;
118 var bf = b.f;
119 var cf = c.f;
120 a = new V(cf);
121 b = new V(af);
122 c = new V(bf);
123 }
124
125 Expect.equals(-0.1, a.f);
126 Expect.equals(0.1, b.f);
127 Expect.equals(0.0, c.f);
128 }
129
130 testPhiForwarding4() {
131 var a = new V(-0.1);
132 var b = new V(0.1);
133 var c = new V(0.0);
134
135 var result = new List(9);
136 for (var i = 0, j = 0; i < 3; i++) {
137 result[j++] = a.f;
138 result[j++] = b.f;
139 result[j++] = c.f;
140 var xa = a;
141 var xb = b;
142 a = c;
143 b = xa;
144 c = xb;
145 }
146
147 Expect.listEquals([-0.1, 0.1, 0.0,
148 0.0, -0.1, 0.1,
149 0.1, 0.0, -0.1], result);
150 }
151
152 class U {
153 var x, y;
154 U() : x = 0, y = 0;
155 }
156
157 testEqualPhisElimination() {
158 var u = new U();
159 var v = new U();
160 var sum = 0;
161 for (var i = 0; i < 3; i++) {
162 u.x = i;
163 u.y = i;
164 if ((i & 1) == 1) {
165 v.x = i + 1;
166 v.y = i + 1;
167 } else {
168 v.x = i - 1;
169 v.y = i - 1;
170 }
171 sum += v.x + v.y;
172 }
173 Expect.equals(4, sum);
174 Expect.equals(2, u.x);
175 Expect.equals(2, u.y);
176 }
177
74 main() { 178 main() {
75 final fixed = new List(10); 179 final fixed = new List(10);
76 final growable = []; 180 final growable = [];
77 testImmutableVMFields(fixed, true); 181 testImmutableVMFields(fixed, true);
78 testImmutableVMFields(growable, false); 182 testImmutableVMFields(growable, false);
79 testImmutableVMFields(growable, false); 183 testImmutableVMFields(growable, false);
80 184
81 final f64List = new Float64List(2); 185 final f64List = new Float64List(2);
82 testPhiRepresentation(true, f64List); 186 testPhiRepresentation(true, f64List);
83 testPhiRepresentation(false, f64List); 187 testPhiRepresentation(false, f64List);
84 188
189 final obj = new X(new X(new X(null)));
190
85 for (var i = 0; i < 2000; i++) { 191 for (var i = 0; i < 2000; i++) {
86 Expect.listEquals([0x02010000, 0x03020100], foo(new A(0, 0))); 192 Expect.listEquals([0x02010000, 0x03020100], foo(new A(0, 0)));
87 Expect.listEquals([0x02010000, 0x03020100], bar(new A(0, 0), false)); 193 Expect.listEquals([0x02010000, 0x03020100], bar(new A(0, 0), false));
88 Expect.listEquals([0x04020000, 0x03020100], bar(new A(0, 0), true)); 194 Expect.listEquals([0x04020000, 0x03020100], bar(new A(0, 0), true));
89 testImmutableVMFields(fixed, true); 195 testImmutableVMFields(fixed, true);
90 testPhiRepresentation(true, f64List); 196 testPhiRepresentation(true, f64List);
197 testPhiForwarding(obj);
198 testPhiForwarding2(obj);
199 testPhiForwarding3();
200 testPhiForwarding4();
201 testEqualPhisElimination();
91 } 202 }
92 203
93 Expect.equals(1, testImmutableVMFields([], false)); 204 Expect.equals(1, testImmutableVMFields([], false));
94 Expect.equals(2, testImmutableVMFields([1], false)); 205 Expect.equals(2, testImmutableVMFields([1], false));
95 Expect.equals(2, testImmutableVMFields([1, 2], false)); 206 Expect.equals(2, testImmutableVMFields([1, 2], false));
96 Expect.equals(3, testImmutableVMFields([1, 2, 3], false)); 207 Expect.equals(3, testImmutableVMFields([1, 2, 3], false));
97 208
98 final u32List = new Uint32List(3); 209 final u32List = new Uint32List(3);
99 u32List[0] = 0; 210 u32List[0] = 0;
100 u32List[1] = 0x3FFFFFFF; 211 u32List[1] = 0x3FFFFFFF;
101 u32List[2] = 0x7FFFFFFF; 212 u32List[2] = 0x7FFFFFFF;
102 213
103 for (var i = 0; i < 4000; i++) { 214 for (var i = 0; i < 4000; i++) {
104 testPhiConvertions(true, u32List); 215 testPhiConvertions(true, u32List);
105 testPhiConvertions(false, u32List); 216 testPhiConvertions(false, u32List);
106 } 217 }
107 } 218 }
OLDNEW
« runtime/vm/intermediate_language.cc ('K') | « runtime/vm/intermediate_language.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698