Debian Codegraph @

test/593-checker-long-2-float-regression/src/Main.java

raw
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 long longValue;
20
21 public static void assertEquals(float expected, float result) {
22 if (expected != result) {
23 throw new Error("Expected: " + expected + ", found: " + result);
24 }
25 }
26
27 public static void main(String[] args) {
28 assertEquals(1.0F, $noinline$longToFloat(true));
29 assertEquals(2.0F, $noinline$longToFloat(false));
30 }
31
32 /// CHECK-START: float Main.$noinline$longToFloat(boolean) register (after)
33 /// CHECK: <<Get:j\d+>> StaticFieldGet field_name:Main.longValue
34 /// CHECK: <<Convert:f\d+>> TypeConversion [<<Get>>]
35 /// CHECK: Return [<<Convert>>]
36
37 static float $noinline$longToFloat(boolean param) {
38 // This if else is to avoid constant folding the long constant into a float constant.
39 if (param) {
40 longValue = $inline$returnConstOne();
41 } else {
42 longValue = $inline$returnConstTwo();
43 }
44 // This call prevents D8 from replacing the result of the sget instruction
45 // in the return below by the result of the call to $inline$returnConstOne/Two() above.
46 $inline$preventRedundantFieldLoadEliminationInD8();
47 return (float) longValue;
48 }
49
50 static long $inline$returnConstOne() {
51 return 1L;
52 }
53
54 static long $inline$returnConstTwo() {
55 return 2L;
56 }
57
58 static void $inline$preventRedundantFieldLoadEliminationInD8() {}
59 }