1 /*
2  * Copyright (C) 2017 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 public class Main {
18 
main(String[] args)19   public static void main(String[] args) {
20     System.out.println(test());
21   }
22 
23   public static long testField = 0;
24   public static long longField0 = 0;
25   public static long longField1 = 0;
26   public static long longField2 = 0;
27   public static long longField3 = 0;
28   public static long longField4 = 0;
29   public static long longField5 = 0;
30   public static long longField6 = 0;
31   public static long longField7 = 0;
32 
33   /// CHECK-START-ARM: int Main.test() register (after)
34   /// CHECK: TypeConversion locations:[#-8690466096623102344]->{{.*}}
test()35   public static int test() {
36     // To avoid constant folding TypeConversion(const), hide the constant in a field.
37     // We do not run constant folding after load-store-elimination.
38     testField = 0x8765432112345678L;
39     long value = testField;
40     // Now, the `value` is in a register because of the store but we need
41     // a constant location to trigger the bug, so load a bunch of other fields.
42     long l0 = longField0;
43     long l1 = longField1;
44     long l2 = longField2;
45     long l3 = longField3;
46     long l4 = longField4;
47     long l5 = longField5;
48     long l6 = longField6;
49     long l7 = longField7;
50     if (l0 != 0 || l1 != 0 || l2 != 0 || l3 != 0 || l4 != 0 || l5 != 0 || l6 != 0 || l7 != 0) {
51       throw new Error();
52     }
53     // Do the conversion from constant location.
54     return (int)value;
55   }
56 }
57