blob: 0b980d0143928cb8d738a9de93a87f3a12c07ac9 [file] [log] [blame]
Nicolas Geoffray276d9da2015-02-02 18:24:11 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2014 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 */
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000016
17public class Main {
18
David Brazdila06d66a2015-05-28 11:14:54 +010019 /// CHECK-START: int Main.inlineIfThenElse() inliner (before)
20 /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect
21 /// CHECK-DAG: Return [<<Invoke>>]
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000022
David Brazdila06d66a2015-05-28 11:14:54 +010023 /// CHECK-START: int Main.inlineIfThenElse() inliner (after)
24 /// CHECK-NOT: InvokeStaticOrDirect
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000025
26 public static int inlineIfThenElse() {
27 return foo(true);
28 }
29
30 private static int foo(boolean value) {
31 if (value) {
32 return 1;
33 } else {
34 return 0;
35 }
36 }
37
David Brazdila06d66a2015-05-28 11:14:54 +010038 /// CHECK-START: int Main.inlineInLoop() inliner (before)
39 /// CHECK-DAG: InvokeStaticOrDirect
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000040
David Brazdila06d66a2015-05-28 11:14:54 +010041 /// CHECK-START: int Main.inlineInLoop() inliner (after)
42 /// CHECK-NOT: InvokeStaticOrDirect
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000043
44 public static int inlineInLoop() {
45 int result = 0;
46 for (int i = 0; i < 32; ++i) {
47 result += foo(i % 2 == 0);
48 }
49 return result;
50 }
51
David Brazdila06d66a2015-05-28 11:14:54 +010052 /// CHECK-START: int Main.inlineInLoopHeader() inliner (before)
53 /// CHECK-DAG: InvokeStaticOrDirect
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000054
David Brazdila06d66a2015-05-28 11:14:54 +010055 /// CHECK-START: int Main.inlineInLoopHeader() inliner (after)
56 /// CHECK-NOT: InvokeStaticOrDirect
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000057
58 public static int inlineInLoopHeader() {
59 int result = 0;
60 for (int i = 0; i < foo(i % 2 == 0); ++i) {
61 result += 42;
62 }
63 return result;
64 }
65
66 public static void main(String[] args) {
67 if (inlineIfThenElse() != 1) {
68 throw new Error("Expected 1");
69 }
70 if (inlineInLoop() != 16) {
71 throw new Error("Expected 16");
72 }
73 if (inlineInLoopHeader() != 42) {
74 throw new Error("Expected 16");
75 }
76 }
77}