Home | History | Annotate | Download | only in src
      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   private static int[] a = { 10 };
     20 
     21   // A very particular set of operations that caused a double removal by the
     22   // ARM64 simplifier doing "forward" removals (b/27851582).
     23 
     24   /// CHECK-START-ARM: int Main.operations() instruction_simplifier_arm (before)
     25   /// CHECK-DAG: <<Get:i\d+>> ArrayGet
     26   /// CHECK-DAG: <<Not:i\d+>> Not [<<Get>>]
     27   /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Get>>,i{{\d+}}]
     28   /// CHECK-DAG:              And [<<Not>>,<<Shl>>]
     29   //
     30   /// CHECK-START-ARM: int Main.operations() instruction_simplifier_arm (after)
     31   /// CHECK-DAG: <<Get:i\d+>> ArrayGet
     32   /// CHECK-DAG: <<Not:i\d+>> Not [<<Get>>]
     33   /// CHECK-DAG:              DataProcWithShifterOp [<<Not>>,<<Get>>] kind:And+LSL shift:2
     34 
     35   /// CHECK-START-ARM64: int Main.operations() instruction_simplifier_arm64 (before)
     36   /// CHECK-DAG: <<Get:i\d+>> ArrayGet
     37   /// CHECK-DAG: <<Not:i\d+>> Not [<<Get>>]
     38   /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Get>>,i{{\d+}}]
     39   /// CHECK-DAG:              And [<<Not>>,<<Shl>>]
     40   //
     41   /// CHECK-START-ARM64: int Main.operations() instruction_simplifier_arm64 (after)
     42   /// CHECK-DAG: <<Get:i\d+>> ArrayGet
     43   /// CHECK-DAG: <<Not:i\d+>> Not [<<Get>>]
     44   /// CHECK-DAG:              DataProcWithShifterOp [<<Not>>,<<Get>>] kind:And+LSL shift:2
     45   private static int operations() {
     46      int r = a[0];
     47      int n = ~r;
     48      int s = r << 2;
     49      int a = s & n;
     50      return a;
     51   }
     52 
     53   public static void main(String[] args) {
     54     if (operations() != 32) {
     55       System.out.println("failed");
     56     } else {
     57       System.out.println("passed");
     58     }
     59   }
     60 }
     61