121cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray/*
221cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
321cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray *
421cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
521cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * you may not use this file except in compliance with the License.
621cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * You may obtain a copy of the License at
721cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray *
821cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
921cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray *
1021cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
1121cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
1221cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1321cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * See the License for the specific language governing permissions and
1421cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray * limitations under the License.
1521cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray */
1621cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray
1721cc798cd56a069a3d51a0215020676065780939Nicolas Geoffraypublic class Main {
1821cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  public static void main(String[] args) {
1921cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    if (new Main().$opt$TestFloatPhi() != 33.0f) {
2021cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      throw new Error("Unexpected result");
2121cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    }
2221cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  }
2321cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray
2421cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  public float $opt$TestFloatPhi() {
2521cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    float a = floatField;
2621cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    float b = 42.0f;
2721cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    if (test1) {
2821cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // The phi for `a` will be found to be of type float.
2921cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      a = otherFloatField;
3021cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // The phi for `b` will be found to be of type int (constants in DEX).
3121cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      b = 33.0f;
3221cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    }
3321cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    // Use a different condition to avoid having dx being too clever.
3421cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    if (test2) {
3521cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // Type propagation now realizes that `b` must be of type float. So
3621cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // it requests a float equivalent for `b`. Because the phi for `a` is
3721cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // next to the phi for `b` in the phi list, the compiler used to crash,
3821cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // assuming that a float phi following a phi *must* be for the same DEX
3921cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      // register.
4021cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray      a = b;
4121cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    }
4221cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray    return a;
4321cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  }
4421cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray
4521cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  float floatField = 4.2f;
4621cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  float otherFloatField = 42.2f;
4721cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  boolean test1 = true;
4821cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray  boolean test2 = true;
4921cc798cd56a069a3d51a0215020676065780939Nicolas Geoffray}
50