blob: 86c119f3d025770108a159f8157ee8666a55c2d4 [file] [log] [blame]
David Brazdil7d275372015-04-21 16:36:35 +01001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2015 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 */
David Brazdil7d275372015-04-21 16:36:35 +010016
17
18public class Main {
19
20 public static void assertIntEquals(int expected, int result) {
21 if (expected != result) {
22 throw new Error("Expected: " + expected + ", found: " + result);
23 }
24 }
25
26 public static int Inline(int x, int y) {
27 int result;
28 if (x <= y) {
29 result = x * y;
30 } else {
31 result = 0;
32 }
33 return result;
34 }
35
David Brazdila06d66a2015-05-28 11:14:54 +010036 /// CHECK-START: int Main.NestedLoop(int, int) inliner (before)
37 /// CHECK-NOT: Mul
David Brazdil7d275372015-04-21 16:36:35 +010038
David Brazdila06d66a2015-05-28 11:14:54 +010039 /// CHECK-START: int Main.NestedLoop(int, int) inliner (after)
40 /// CHECK: Mul
41 /// CHECK-NOT: Mul
David Brazdil7d275372015-04-21 16:36:35 +010042
43 public static int NestedLoop(int max_x, int max_y) {
44 int total = 0;
45 for (int x = 0; x < max_x; ++x) {
46 for (int y = 0; y < max_y; ++y) {
47 total += Inline(x, y);
48 }
49 }
50 return total;
51 }
52
53 public static void main(String[] args) {
54 assertIntEquals(0, NestedLoop(1, 1));
55 assertIntEquals(3, NestedLoop(2, 3));
56 }
57}