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

Side by Side Diff: tests/compiler/dart2js/gvn_test.dart

Issue 17056002: Do LICM on loop header instructions. Also first instructions that throw in a loop can be LICM'ed. (Closed) Base URL: http://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
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/optimize.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 4
5 import "package:expect/expect.dart";
5 import 'compiler_helper.dart'; 6 import 'compiler_helper.dart';
6 7
7 const String TEST_ONE = r""" 8 const String TEST_ONE = r"""
8 void foo(bar) { 9 void foo(bar) {
9 for (int i = 0; i < 1; i++) { 10 for (int i = 0; i < 1; i++) {
10 print(1 + bar); 11 print(1 + bar);
11 print(1 + bar); 12 print(1 + bar);
12 } 13 }
13 } 14 }
14 """; 15 """;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 var a = [new B(), new A()][0]; 54 var a = [new B(), new A()][0];
54 var b = a.foo; 55 var b = a.foo;
55 var c = a.foo; 56 var c = a.foo;
56 if (a is B) { 57 if (a is B) {
57 c = a.foo; 58 c = a.foo;
58 } 59 }
59 return b + c; 60 return b + c;
60 } 61 }
61 """; 62 """;
62 63
64 // Check that a gvn'able instruction in the loop header gets hoisted.
65 const String TEST_SIX = r"""
66 class A {
67 final field = 54;
68 }
69
70 main() {
71 var a = new A();
72 while (a.field == 54) { a.field = 42; }
73 }
74 """;
75
76 // Check that a gvn'able instruction that may throw in the loop header
77 // gets hoisted.
78 const String TEST_SEVEN = r"""
79 class A {
80 final field;
81 A() : field = null;
82 A.bar() : field = 42;
83 }
84
85 main() {
86 var a = new A();
87 var b = new A.bar();
88 while (a.field == 54) { a.field = 42; b.field = 42; }
89 }
90 """;
91
92 // Check that a check in a loop header gets hoisted.
93 const String TEST_EIGHT = r"""
94 class A {
95 final field;
96 A() : field = null;
97 A.bar() : field = 42;
98 }
99
100 main() {
101 var a = new A();
102 var b = new A.bar();
103 for (int i = 0; i < a.field; i++) { a.field = 42; b.field = 42; }
104 }
105 """;
106
63 main() { 107 main() {
64 String generated = compile(TEST_ONE, entry: 'foo'); 108 String generated = compile(TEST_ONE, entry: 'foo');
65 RegExp regexp = new RegExp(r"1 \+ [a-z]+"); 109 RegExp regexp = new RegExp(r"1 \+ [a-z]+");
66 checkNumberOfMatches(regexp.allMatches(generated).iterator, 1); 110 checkNumberOfMatches(regexp.allMatches(generated).iterator, 1);
67 111
68 generated = compile(TEST_TWO, entry: 'foo'); 112 generated = compile(TEST_TWO, entry: 'foo');
69 checkNumberOfMatches(new RegExp("length").allMatches(generated).iterator, 1); 113 checkNumberOfMatches(new RegExp("length").allMatches(generated).iterator, 1);
70 114
71 generated = compile(TEST_THREE, entry: 'foo'); 115 generated = compile(TEST_THREE, entry: 'foo');
72 checkNumberOfMatches(new RegExp("number").allMatches(generated).iterator, 1); 116 checkNumberOfMatches(new RegExp("number").allMatches(generated).iterator, 1);
73 117
74 generated = compile(TEST_FOUR, entry: 'foo'); 118 generated = compile(TEST_FOUR, entry: 'foo');
75 checkNumberOfMatches(new RegExp("shr").allMatches(generated).iterator, 1); 119 checkNumberOfMatches(new RegExp("shr").allMatches(generated).iterator, 1);
76 120
77 generated = compileAll(TEST_FIVE); 121 generated = compileAll(TEST_FIVE);
78 checkNumberOfMatches( 122 checkNumberOfMatches(
79 new RegExp("get\\\$foo").allMatches(generated).iterator, 1); 123 new RegExp("get\\\$foo").allMatches(generated).iterator, 1);
124
125 generated = compileAll(TEST_SIX);
126 Expect.isTrue(generated.contains('for (t1 = a.field === 54; t1;)'));
127
128 generated = compileAll(TEST_SEVEN);
129 Expect.isTrue(generated.contains('for (t1 = a.field === 54; t1;)'));
130
131 generated = compileAll(TEST_EIGHT);
132 Expect.isTrue(generated.contains('for (; i < t1; ++i)'));
80 } 133 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/optimize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698