1 /* 2 * Copyright (C) 2014 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 { main(String[] args)18 public static void main(String[] args) { 19 if (new Main().$opt$TestFloatPhi() != 33.0f) { 20 throw new Error("Unexpected result"); 21 } 22 } 23 $opt$TestFloatPhi()24 public float $opt$TestFloatPhi() { 25 float a = floatField; 26 float b = 42.0f; 27 if (test1) { 28 // The phi for `a` will be found to be of type float. 29 a = otherFloatField; 30 // The phi for `b` will be found to be of type int (constants in DEX). 31 b = 33.0f; 32 } 33 // Use a different condition to avoid having dx being too clever. 34 if (test2) { 35 // Type propagation now realizes that `b` must be of type float. So 36 // it requests a float equivalent for `b`. Because the phi for `a` is 37 // next to the phi for `b` in the phi list, the compiler used to crash, 38 // assuming that a float phi following a phi *must* be for the same DEX 39 // register. 40 a = b; 41 } 42 return a; 43 } 44 45 float floatField = 4.2f; 46 float otherFloatField = 42.2f; 47 boolean test1 = true; 48 boolean test2 = true; 49 } 50