1/*
2* 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*/
16
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
36  // CHECK-START: int Main.NestedLoop(int, int) inliner (before)
37  // CHECK-NOT:     Mul
38
39  // CHECK-START: int Main.NestedLoop(int, int) inliner (after)
40  // CHECK:         Mul
41  // CHECK-NOT:     Mul
42
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}
58