| 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 gvn_tests; | |
| 8 | |
| 9 import 'js_backend_cps_ir.dart'; | |
| 10 | |
| 11 const List<TestEntry> tests = const [ | |
| 12 const TestEntry(r""" | |
| 13 foo(x, list) { | |
| 14 var sum = 0; | |
| 15 for (int k = 0; k < 10; k++) { | |
| 16 // Everything can be hoisted out up to the index access which is | |
| 17 // blocked by the bounds check. | |
| 18 var a = x.left.left; | |
| 19 var b = x.left.right; | |
| 20 var c = x.right.left; | |
| 21 var d = x.right.right; | |
| 22 var i = a.value + c.value; | |
| 23 var j = b.value + d.value; | |
| 24 var z = list[i * j] + i; | |
| 25 sum += z; | |
| 26 } | |
| 27 return sum; | |
| 28 } | |
| 29 // Use a different class for each level in the tree, so type inference | |
| 30 // is not confused. | |
| 31 class Root { | |
| 32 Branch left, right; | |
| 33 Root(this.left, this.right); | |
| 34 } | |
| 35 class Branch { | |
| 36 Leaf left, right; | |
| 37 Branch(this.left, this.right); | |
| 38 } | |
| 39 class Leaf { | |
| 40 int value; | |
| 41 Leaf(this.value); | |
| 42 } | |
| 43 main() { | |
| 44 var x1 = new Leaf(1); | |
| 45 var x2 = new Leaf(10); | |
| 46 var x3 = new Leaf(20); | |
| 47 var x4 = new Leaf(-10); | |
| 48 var y1 = new Branch(x1, x2); | |
| 49 var y2 = new Branch(x3, x4); | |
| 50 var z = new Root(y1, y2); | |
| 51 print(foo(z, [1,2,3,4,5,6,7,8,9,10])); | |
| 52 } | |
| 53 """,r""" | |
| 54 function() { | |
| 55 var v0 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], sum = 0, k = 0, i, v1; | |
| 56 for (; k < 10; sum += i + v0[v1], ++k) { | |
| 57 i = 1 + 20; | |
| 58 v1 = i * (10 + -10); | |
| 59 if (v1 < 0 || v1 >= 10) | |
| 60 return H.ioore(v0, v1); | |
| 61 } | |
| 62 v0 = H.S(sum); | |
| 63 if (typeof dartPrint == "function") | |
| 64 dartPrint(v0); | |
| 65 else if (typeof console == "object" && typeof console.log != "undefined") | |
| 66 console.log(v0); | |
| 67 else if (!(typeof window == "object")) { | |
| 68 if (!(typeof print == "function")) | |
| 69 throw "Unable to print message: " + String(v0); | |
| 70 print(v0); | |
| 71 } | |
| 72 }"""), | |
| 73 ]; | |
| 74 | |
| 75 void main() { | |
| 76 runTests(tests); | |
| 77 } | |
| OLD | NEW |