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

Side by Side Diff: tests/standalone/left_shift_bit_and_op_test.dart

Issue 12218181: Recognize pattern (a << b) & c with c being a positive Smi and allow left shift to truncate the res… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 // Tests optimizing (a << b) & c if c is a Smi constant.
6
7 main() {
8 checkshiftAnd32();
9 checkShiftAnd64();
10 // Optimize shiftAnd32.
11 for (int i = 0; i < 10000; i++) {
12 A.shiftAnd32(12, 17);
13 A.shiftAnd64(12, 17);
14 Expect.equals(72, A.multipleConstantUses(3, 4));
15 Expect.equals(34493956096, A.multipleShiftUse(134742016, 8));
16 }
17 checkshiftAnd32();
18 checkShiftAnd64();
19
20 Expect.throws(() => A.shiftAnd32(12, -5));
21
22 // Check environment dependency.
23 final a = new A(), b = new B();
24 for (var i = 0; i < 10000; i++) {
25 Expect.equals(0, bar(a));
26 }
27 Expect.equals(4294967296, bar(b));
28 }
29
30
31 checkshiftAnd32() {
32 Expect.equals(1572864, A.shiftAnd32(12, 17));
33 Expect.equals(12, A.shiftAnd32(12, 0));
34 Expect.equals(285212672, A.shiftAnd32(16779392, 17));
35 }
36
37
38 checkShiftAnd64() {
39 Expect.equals(1125936481173504, A.shiftAnd64(4611694814806147072, 7));
40 }
41
42
43 class A {
44 static const int MASK_32 = (1 << 30) - 1;
45 static const int MASK_64 = (1 << 62) - 1;
46
47 static shiftAnd32(a, c) {
48 return (a << c) & MASK_32;
49 }
50
51 static shiftAnd64(a, c) {
52 return (a << c) & MASK_64;
53 }
54
55 static multipleConstantUses(a, c) {
56 var j = (a << c) & 0xFF;
57 var k = (a << 3) & 0xFF;
58 return j + k;
59 }
60
61 // Make sure that left shift is nor marked as truncating.
62 static multipleShiftUse(a, c) {
63 var y = (a << c);
64 var x = y & 0x7F;
65 return y + x;
66 }
67
68 foo(x) { return x & 0xf; }
69 }
70
71 class B { foo(x) { return x; } }
72
73 bar (o) {
74 return o.foo(1 << 32);
75 }
OLDNEW
« runtime/vm/intermediate_language.h ('K') | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698