1 /*
2  * Copyright (C) 2016 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 
19   static boolean doThrow = false;
20   static long longValue;
21 
assertEquals(float expected, float result)22   public static void assertEquals(float expected, float result) {
23     if (expected != result) {
24       throw new Error("Expected: " + expected + ", found: " + result);
25     }
26   }
27 
main(String[] args)28   public static void main(String[] args) {
29     assertEquals(1.0F, $noinline$longToFloat());
30   }
31 
32   /// CHECK-START: float Main.$noinline$longToFloat() register (after)
33   /// CHECK-DAG:     <<Const1:j\d+>>   LongConstant 1
34   /// CHECK-DAG:     <<Convert:f\d+>>  TypeConversion [<<Const1>>]
35   /// CHECK-DAG:                       Return [<<Convert>>]
36 
$noinline$longToFloat()37   static float $noinline$longToFloat() {
38     if (doThrow) { throw new Error(); }
39     longValue = $inline$returnConst();
40     // This call prevents D8 from replacing the result of the sget instruction
41     // in line 43 by the result of the call to $inline$returnConst() in line 39.
42     $inline$preventRedundantFieldLoadEliminationInD8();
43     return (float) longValue;
44   }
45 
$inline$returnConst()46   static long $inline$returnConst() {
47     return 1L;
48   }
49 
$inline$preventRedundantFieldLoadEliminationInD8()50   static void $inline$preventRedundantFieldLoadEliminationInD8() {}
51 }
52