Debian Codegraph @

test/593-checker-shift-and-simplifier/src/Main.java

raw
1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import java.lang.reflect.Method;
18
19 public class Main {
20
21 static int[] a = { 10 };
22
23 // A very particular set of operations that caused a double removal by the
24 // ARM64 simplifier doing "forward" removals (b/27851582).
25
26 /// CHECK-START-ARM: int Main.operations() instruction_simplifier_arm (after)
27 /// CHECK-DAG: <<Get:i\d+>> ArrayGet
28 /// CHECK-DAG: <<Not:i\d+>> Not [<<Get>>]
29 /// CHECK-DAG: DataProcWithShifterOp [<<Not>>,<<Get>>] kind:And+LSL shift:2
30
31 /// CHECK-START-ARM64: int Main.operations() instruction_simplifier_arm64 (after)
32 /// CHECK-DAG: <<Get:i\d+>> ArrayGet
33 /// CHECK-DAG: <<Not:i\d+>> Not [<<Get>>]
34 /// CHECK-DAG: DataProcWithShifterOp [<<Not>>,<<Get>>] kind:And+LSL shift:2
35 private static int operations() {
36 int r = a[0];
37 int n = ~r;
38 int s = r << 2;
39 int a = s & n;
40 return a;
41 }
42
43 public static void main(String[] args) {
44 if (operations() != 32) {
45 System.out.println("failed");
46 } else {
47 System.out.println("passed");
48 }
49
50 if ($noinline$runSmaliTest("operations") != 32) {
51 System.out.println("failed");
52 } else {
53 System.out.println("passed");
54 }
55 }
56
57 public static int $noinline$runSmaliTest(String name) {
58 try {
59 Class<?> c = Class.forName("SmaliTests");
60 Method m = c.getMethod(name);
61 return (Integer) m.invoke(null);
62 } catch (Exception ex) {
63 throw new Error(ex);
64 }
65 }
66 }