Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2017 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   public static void foo(float f) {
     20     // The reason this used to break:
     21     // 1) We inline the 'foo' call, so blocks now only contain HLoadClass instructions.
     22     // 2) We then run the select_generator pass, which cannot change the
     23     //    if/else because blocks contain instructions.
     24     // 3) We run GVN which will remove the HLoadClass instructions in the blocks.
     25     // 4) At code generation, we are in the unlikely situation that a diamond shape
     26     //    contains no instruction (usually removed by select_generator). This used
     27     //    to trip the ARM code generators.
     28     if (f < 1.2f) {
     29       foo(Main.class, Object.class);
     30       if (f < 0.2f) {
     31         foo(Main.class, Object.class);
     32       } else {
     33         foo(Main.class, Object.class);
     34       }
     35     } else {
     36       System.out.println("Hello World: " + f);
     37     }
     38   }
     39 
     40   public static void foo(Object a, Object b) {}
     41 
     42   public static void main(String[] args) {
     43     foo(0f);
     44     foo(4f);
     45     foo(0.1f);
     46   }
     47 }
     48