| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Test that the GVN optimization pass works as expected. | 5 // Test that the GVN optimization pass works as expected. |
| 6 | 6 |
| 7 library basic_tests; | 7 library basic_tests; |
| 8 | 8 |
| 9 import 'js_backend_cps_ir.dart'; | 9 import 'js_backend_cps_ir.dart'; |
| 10 | 10 |
| 11 const List<TestEntry> tests = const [ | 11 const List<TestEntry> tests = const [ |
| 12 const TestEntry.forMethod('function(foo)', r""" | 12 const TestEntry.forMethod('function(foo)', r""" |
| 13 foo(x, list) { | 13 foo(x, list) { |
| 14 var sum = 0; | 14 var sum = 0; |
| 15 for (int k = 0; k < 10; k++) { | 15 for (int k = 0; k < 10; k++) { |
| 16 // Everything can be hoisted out, except the bounds check and sum += z. | 16 // Everything can be hoisted out up to the index access which is |
| 17 // blocked by the bounds check. |
| 17 var a = x.left.left; | 18 var a = x.left.left; |
| 18 var b = x.left.right; | 19 var b = x.left.right; |
| 19 var c = x.right.left; | 20 var c = x.right.left; |
| 20 var d = x.right.right; | 21 var d = x.right.right; |
| 21 var i = a.value + c.value; | 22 var i = a.value + c.value; |
| 22 var j = b.value + d.value; | 23 var j = b.value + d.value; |
| 23 var z = list[i * j] + i; | 24 var z = list[i * j] + i; |
| 24 sum += z; | 25 sum += z; |
| 25 } | 26 } |
| 26 return sum; | 27 return sum; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 var x2 = new Leaf(10); | 45 var x2 = new Leaf(10); |
| 45 var x3 = new Leaf(20); | 46 var x3 = new Leaf(20); |
| 46 var x4 = new Leaf(-10); | 47 var x4 = new Leaf(-10); |
| 47 var y1 = new Branch(x1, x2); | 48 var y1 = new Branch(x1, x2); |
| 48 var y2 = new Branch(x3, x4); | 49 var y2 = new Branch(x3, x4); |
| 49 var z = new Root(y1, y2); | 50 var z = new Root(y1, y2); |
| 50 print(foo(z, [1,2,3,4,5,6,7,8,9,10])); | 51 print(foo(z, [1,2,3,4,5,6,7,8,9,10])); |
| 51 } | 52 } |
| 52 """,r""" | 53 """,r""" |
| 53 function(x, list) { | 54 function(x, list) { |
| 54 var v0 = x.left, a = v0.left, b = v0.right, sum = 0, k = 0, c = (v0 = x.right)
.left, d = v0.right, i = a.value + c.value, v1 = list[v0 = i * (b.value + d.valu
e)]; | 55 var v0 = x.left, a = v0.left, b = v0.right, sum = 0, k = 0, c = (v0 = x.right)
.left, d = v0.right, v1, v2, v3, i, v4; |
| 55 for (; k < 10; sum = sum + (v1 + i), k = k + 1) | 56 v0 = a.value; |
| 56 if (v0 < 0 || v0 >= 10) | 57 v1 = c.value; |
| 57 return H.ioore(list, v0); | 58 v2 = b.value; |
| 59 for (v3 = d.value; k < 10; sum = sum + (i + list[v4]), k = k + 1) { |
| 60 i = v0 + v1; |
| 61 v4 = i * (v2 + v3); |
| 62 if (v4 < 0 || v4 >= 10) |
| 63 return H.ioore(list, v4); |
| 64 } |
| 58 return sum; | 65 return sum; |
| 59 }"""), | 66 }"""), |
| 60 ]; | 67 ]; |
| 61 | 68 |
| 62 void main() { | 69 void main() { |
| 63 runTests(tests); | 70 runTests(tests); |
| 64 } | 71 } |
| OLD | NEW |