Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // Test that the GVN optimization pass works as expected. | |
| 6 | |
| 7 library basic_tests; | |
| 8 | |
| 9 import 'js_backend_cps_ir.dart'; | |
| 10 | |
| 11 const List<TestEntry> tests = const [ | |
| 12 const TestEntry.forMethod('function(foo)', r""" | |
| 13 foo(x, list) { | |
| 14 var sum = 0; | |
| 15 for (int i = 0; i < 10; i++) { | |
| 16 // Everything can be hoisted out, except the bounds check and sum += z. | |
|
sra1
2015/11/23 22:35:07
Nice
asgerf
2015/11/24 10:05:59
Acknowledged.
| |
| 17 var a = x.left.left; | |
| 18 var b = x.left.right; | |
|
sra1
2015/11/23 22:35:07
Indentation is inconsistent
asgerf
2015/11/24 10:05:59
Done.
| |
| 19 var c = x.right.left; | |
| 20 var d = x.right.right; | |
| 21 var i = a.value + c.value; | |
| 22 var j = b.value + d.value; | |
| 23 var z = list[i * j] + i; | |
| 24 sum += z; | |
| 25 } | |
| 26 return sum; | |
| 27 } | |
| 28 // Use a different class for each level in the tree, so type inference | |
| 29 // is not confused. | |
| 30 class Root { | |
| 31 Branch left, right; | |
| 32 Root(this.left, this.right); | |
| 33 } | |
| 34 class Branch { | |
| 35 Leaf left, right; | |
| 36 Branch(this.left, this.right); | |
| 37 } | |
| 38 class Leaf { | |
| 39 int value; | |
| 40 Leaf(this.value); | |
| 41 } | |
| 42 main() { | |
| 43 var x1 = new Leaf(1); | |
| 44 var x2 = new Leaf(10); | |
| 45 var x3 = new Leaf(20); | |
| 46 var x4 = new Leaf(-10); | |
| 47 var y1 = new Branch(x1, x2); | |
| 48 var y2 = new Branch(x3, x4); | |
| 49 var z = new Root(y1, y2); | |
| 50 print(foo(z, [1,2,3,4,5,6,7,8,9,10])); | |
| 51 } | |
| 52 """,r""" | |
| 53 function(x, list) { | |
| 54 var v0 = x.left, a = v0.left, b = v0.right, sum = 0, i = 0, c = (v0 = x.right) .left, d = v0.right, i1 = a.value + c.value, v1 = list[v0 = i1 * (b.value + d.va lue)]; | |
| 55 for (; i < 10; sum = sum + (v1 + i1), i = i + 1) | |
| 56 if (v0 < 0 || v0 >= 10) | |
| 57 H.ioore(list, v0); | |
| 58 return sum; | |
| 59 }"""), | |
| 60 ]; | |
| 61 | |
| 62 void main() { | |
| 63 runTests(tests); | |
| 64 } | |
| OLD | NEW |