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

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

Issue 2561533002: dart2js: Constant folding and specialization for remainder (Closed)
Patch Set: improve range analysis of remainder Created 3 years, 11 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
« no previous file with comments | « pkg/compiler/lib/src/ssa/value_range_analyzer.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
(Empty)
1 // Copyright (c) 2016, 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 import 'dart:async';
6 import 'package:expect/expect.dart';
7 import 'package:async_helper/async_helper.dart';
8 import 'compiler_helper.dart';
9
10 const String MOD1 = r"""
11 foo(param) {
12 var a = param ? 0xFFFFFFFF : 1;
13 return a % 2;
14 // present: ' % 2'
15 // absent: '$mod'
16 }
17 """;
18
19 const String MOD2 = r"""
20 foo(param) {
21 var a = param ? 0xFFFFFFFF : -0.0;
22 return a % 2;
23 // Cannot optimize due to potential -0.
24 // present: '$mod'
25 // absent: ' % 2'
26 }
27 """;
28
29 const String MOD3 = r"""
30 foo(param) {
31 var a = param ? 0xFFFFFFFF : -0.0;
32 return (a + 1) % 2;
33 // 'a + 1' cannot be -0.0, so we can optimize.
34 // present: ' % 2'
35 // absent: '$mod'
36 }
37 """;
38
39 const String REM1 = r"""
40 foo(param) {
41 var a = param ? 0xFFFFFFFF : 1;
42 return a.remainder(2);
43 // Above can be compiled to '%'.
44 // present: ' % 2'
45 // absent: 'remainder'
46 }
47 """;
48
49 const String REM2 = r"""
50 foo(param) {
51 var a = param ? 123.4 : -1;
52 return a.remainder(3);
53 // Above can be compiled to '%'.
54 // present: ' % 3'
55 // absent: 'remainder'
56 }
57 """;
58
59 const String REM3 = r"""
60 foo(param) {
61 var a = param ? 123 : null;
62 return 100.remainder(a);
63 // No specialization for possibly null inputs.
64 // present: 'remainder'
65 // absent: '%'
66 }
67 """;
68
69 main() {
70 RegExp directivePattern = new RegExp(
71 // \1 \2 \3
72 r'''// *(present|absent): (?:"([^"]*)"|'([^'']*)')''',
73 multiLine: true);
74
75 Future check(String test) {
76 return compile(test, entry: 'foo', check: (String generated) {
77 for (Match match in directivePattern.allMatches(test)) {
78 String directive = match.group(1);
79 String pattern = match.groups([2, 3]).where((s) => s != null).single;
80 if (directive == 'present') {
81 Expect.isTrue(generated.contains(pattern),
82 "Cannot find '$pattern' in:\n$generated");
83 } else {
84 assert(directive == 'absent');
85 Expect.isFalse(generated.contains(pattern),
86 "Must not find '$pattern' in:\n$generated");
87 }
88 }
89 });
90 }
91
92 asyncTest(() => Future.wait([
93 check(MOD1),
94 check(MOD2),
95 check(MOD3),
96 check(REM1),
97 check(REM2),
98 check(REM3),
99 ]));
100 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/value_range_analyzer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698