1ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain/*
2ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * Copyright (C) 2016 The Android Open Source Project
3ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain *
4ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * Licensed under the Apache License, Version 2.0 (the "License");
5ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * you may not use this file except in compliance with the License.
6ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * You may obtain a copy of the License at
7ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain *
8ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain *      http://www.apache.org/licenses/LICENSE-2.0
9ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain *
10ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * Unless required by applicable law or agreed to in writing, software
11ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * distributed under the License is distributed on an "AS IS" BASIS,
12ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * See the License for the specific language governing permissions and
14ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain * limitations under the License.
15ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain */
16ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
17ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillainpublic class Main {
18ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
19ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  public static void main(String[] args) {
20ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    System.out.println(test().intValue());
21ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  }
22ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
238e73ac34f4fac4aee96ccef82e08fab0474a4c98David Brazdil  /// CHECK-START: java.lang.Integer Main.test() builder (after)
24821e66b4f6c608968399d1b133d5b6652a9126edRoland Levillain  /// CHECK-DAG:     <<Method:[ij]\d+>>    CurrentMethod
253e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain  /// CHECK-DAG:     <<Const2P19:i\d+>>    IntConstant 524288
26ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  /// CHECK-DAG:     <<ConstM1:i\d+>>      IntConstant -1
273e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain  /// CHECK-DAG:     <<Array:l\d+>>        NewArray [<<Const2P19>>,<<Method>>]
2806a2b0157ac0d57636ace812c0f8bfee404a3316David Brazdil  /// CHECK-DAG:     <<Length1:i\d+>>      ArrayLength [<<Array>>]
29ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  /// CHECK-DAG:     <<Index:i\d+>>        Add [<<Length1>>,<<ConstM1>>]
3006a2b0157ac0d57636ace812c0f8bfee404a3316David Brazdil  /// CHECK-DAG:     <<Length2:i\d+>>      ArrayLength [<<Array>>]
31ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  /// CHECK-DAG:     <<BoundsCheck:i\d+>>  BoundsCheck [<<Index>>,<<Length2>>]
3206a2b0157ac0d57636ace812c0f8bfee404a3316David Brazdil  /// CHECK-DAG:     <<LastElement:l\d+>>  ArrayGet [<<Array>>,<<BoundsCheck>>]
33ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  /// CHECK-DAG:                           Return [<<LastElement>>]
34ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
353e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain
36ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  /// CHECK-START: java.lang.Integer Main.test() register (before)
37821e66b4f6c608968399d1b133d5b6652a9126edRoland Levillain  /// CHECK-DAG:     <<Method:[ij]\d+>>    CurrentMethod
383e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain  /// CHECK-DAG:     <<Const2P19:i\d+>>    IntConstant 524288
393e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain  /// CHECK-DAG:     <<Const2P19M1:i\d+>>  IntConstant 524287
403e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain  /// CHECK-DAG:     <<Array:l\d+>>        NewArray [<<Const2P19>>,<<Method>>]
413e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain  /// CHECK-DAG:     <<LastElement:l\d+>>  ArrayGet [<<Array>>,<<Const2P19M1>>]
42ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  /// CHECK-DAG:                           Return [<<LastElement>>]
43ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
44ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  public static Integer test() {
453e6232ec4574feeef11f61e6a08ce7bc1db8c08fRoland Levillain    Integer[] integers = new Integer[1 << 19];
46ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    initIntegerArray(integers);
47ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    // Array load with a large constant index (after constant folding
48ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    // and bounds check elimination).
49ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    Integer last_integer = integers[integers.length - 1];
50ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    return last_integer;
51ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  }
52ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
53ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  public static void initIntegerArray(Integer[] integers) {
54ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    for (int i = 0; i < integers.length; ++i) {
55ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain      integers[i] = new Integer(i);
56ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain    }
57ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain  }
58ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain
59ca0bf0349f8da35b284df49732e30eeb62591034Roland Levillain}
60