blob: 6ba2644b977b558fd4b10bfd70c81e51373645a7 [file] [log] [blame]
Aart Bik1e677482016-11-01 14:23:58 -07001/*
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/**
18 * Regression tests for BCE.
19 */
20public class Main {
21
22 static int[] array = new int[10];
23
24 /// CHECK-START: int Main.doNotVisitAfterForwardBCE(int[]) BCE (before)
25 /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none
26 /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none
27 //
28 /// CHECK-START: int Main.doNotVisitAfterForwardBCE(int[]) BCE (after)
29 /// CHECK-NOT: BoundsCheck
30 static int doNotVisitAfterForwardBCE(int[] a) {
31 if (a == null) {
32 throw new Error("Null");
33 }
34 int k = 0;
35 int j = 0;
36 for (int i = 1; i < 10; i++) {
37 j = i - 1;
38 // b/32547652: after DCE, bounds checks become consecutive,
39 // and second should not be revisited after forward BCE.
40 k = a[i] + a[i - 1];
41 }
42 return j;
43 }
44
45 public static void main(String[] args) {
46 expectEquals(8, doNotVisitAfterForwardBCE(array));
47 System.out.println("passed");
48 }
49
50 private static void expectEquals(int expected, int result) {
51 if (expected != result) {
52 throw new Error("Expected: " + expected + ", found: " + result);
53 }
54 }
55}