blob: b31cbdef6755cc401119a5a6d8ee4a16ffbb49fd [file] [log] [blame]
Pavel Vyssotski4c858cd2016-03-16 13:59:53 +06001/*
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
17public class Main {
18
19 static boolean doThrow = false;
20 static long longValue;
21
22 public static void assertEquals(float expected, float result) {
23 if (expected != result) {
24 throw new Error("Expected: " + expected + ", found: " + result);
25 }
26 }
27
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
37 static float $noinline$longToFloat() {
38 if (doThrow) { throw new Error(); }
39 longValue = $inline$returnConst();
Christoffer Quist Adamsen9a8634a2019-07-19 13:49:14 +020040 // 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();
Pavel Vyssotski4c858cd2016-03-16 13:59:53 +060043 return (float) longValue;
44 }
45
46 static long $inline$returnConst() {
47 return 1L;
48 }
Christoffer Quist Adamsen9a8634a2019-07-19 13:49:14 +020049
50 static void $inline$preventRedundantFieldLoadEliminationInD8() {}
Pavel Vyssotski4c858cd2016-03-16 13:59:53 +060051}