|
1 /* |
|
2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * Copyright (c) 2019, Arm Limited. All rights reserved. |
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 * |
|
6 * This code is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU General Public License version 2 only, as |
|
8 * published by the Free Software Foundation. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 */ |
|
24 |
|
25 |
|
26 |
|
27 package org.graalvm.compiler.core.aarch64.test; |
|
28 |
|
29 import org.graalvm.compiler.lir.LIRInstruction; |
|
30 import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp.BinaryConstOp; |
|
31 import org.junit.Test; |
|
32 |
|
33 import java.util.function.Predicate; |
|
34 |
|
35 public class AArch64ElideL2ITest extends AArch64MatchRuleTest { |
|
36 private static final Predicate<LIRInstruction> predicate = op -> { |
|
37 if (op instanceof BinaryConstOp && op.name().toUpperCase().equals("AND")) { |
|
38 return true; |
|
39 } |
|
40 return false; |
|
41 }; |
|
42 |
|
43 public int addWithSingleL2I(long m) { |
|
44 return (int) m + 100; |
|
45 } |
|
46 |
|
47 @Test |
|
48 public void testAddWithSingleL2I() { |
|
49 test("addWithSingleL2I", 5L); |
|
50 checkLIR("addWithSingleL2I", predicate, 0); |
|
51 } |
|
52 |
|
53 public int addWithTwoL2I(long m, long n) { |
|
54 return (int) m + (int) n; |
|
55 } |
|
56 |
|
57 @Test |
|
58 public void testAddWithTwoL2I() { |
|
59 test("addWithTwoL2I", 5L, 0x1FFFFFFFFL); |
|
60 checkLIR("addWithTwoL2I", predicate, 0); |
|
61 } |
|
62 |
|
63 public int addWithTwoNarrow(long m, long n) { |
|
64 return (int) m + (short) n; |
|
65 } |
|
66 |
|
67 @Test |
|
68 public void testAddWithTwoNarrow() { |
|
69 test("addWithTwoNarrow", 0x80000000L, 6L); |
|
70 checkLIR("addWithTwoNarrow", predicate, 1); |
|
71 } |
|
72 |
|
73 public int subSingleL2I(int m, long n) { |
|
74 return m - (int) n; |
|
75 } |
|
76 |
|
77 @Test |
|
78 public void testSubSingleL2I() { |
|
79 test("subSingleL2I", 13, 40L); |
|
80 checkLIR("subSingleL2I", predicate, 0); |
|
81 } |
|
82 |
|
83 public int shiftWithSingleL2I(long m) { |
|
84 return ((int) m) >> 5; |
|
85 } |
|
86 |
|
87 @Test |
|
88 public void testShiftWithSingleL2I() { |
|
89 test("shiftWithSingleL2I", 234L); |
|
90 checkLIR("shiftWithSingleL2I", predicate, 0); |
|
91 } |
|
92 |
|
93 public int shiftWithTwoL2I(long m, long n) { |
|
94 return (int) m << (int) n; |
|
95 } |
|
96 |
|
97 @Test |
|
98 public void testShiftWithTwoL2I() { |
|
99 test("shiftWithTwoL2I", 234L, 3L); |
|
100 checkLIR("shiftWithTwoL2I", predicate, 0); |
|
101 } |
|
102 |
|
103 public long shiftLongWithL2I(long a, int m) { |
|
104 return a + ((m & 0xFFFFFFFFL) << (int) a); |
|
105 } |
|
106 |
|
107 @Test |
|
108 public void testShiftLongWithL2I() { |
|
109 test("shiftLongWithL2I", 0xFFFFFFFFL, 123); |
|
110 checkLIR("shiftLongWithL2I", predicate, 1); |
|
111 } |
|
112 |
|
113 public int logicWithTwoL2I(long m, long n) { |
|
114 return (int) m | (int) n; |
|
115 } |
|
116 |
|
117 @Test |
|
118 public void testLogicWithTwoL2I() { |
|
119 test("logicWithTwoL2I", 234L, 3L); |
|
120 checkLIR("logicWithTwoL2I", predicate, 0); |
|
121 } |
|
122 |
|
123 public int negateL2I(long m) { |
|
124 return -((int) m); |
|
125 } |
|
126 |
|
127 @Test |
|
128 public void testNegateL2I() { |
|
129 test("negateL2I", 0xFFFFFFFFL); |
|
130 checkLIR("negateL2I", predicate, 0); |
|
131 } |
|
132 |
|
133 public int notL2I(long m) { |
|
134 return ~((int) m); |
|
135 } |
|
136 |
|
137 @Test |
|
138 public void testNotL2I() { |
|
139 test("notL2I", 0xFFFFFFFFL); |
|
140 checkLIR("notL2I", predicate, 0); |
|
141 } |
|
142 } |