Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 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 | |
| 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 Adamsen | 9a8634a | 2019-07-19 13:49:14 +0200 | [diff] [blame] | 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(); |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 43 | return (float) longValue; |
| 44 | } |
| 45 | |
| 46 | static long $inline$returnConst() { |
| 47 | return 1L; |
| 48 | } |
Christoffer Quist Adamsen | 9a8634a | 2019-07-19 13:49:14 +0200 | [diff] [blame] | 49 | |
| 50 | static void $inline$preventRedundantFieldLoadEliminationInD8() {} |
Pavel Vyssotski | 4c858cd | 2016-03-16 13:59:53 +0600 | [diff] [blame] | 51 | } |