From 7adb688fe1213c6dcaf4d2adae3d8b7decf7c28a Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Tue, 7 Mar 2017 13:28:51 -0800 Subject: [PATCH] Improve isunit computation, some tests edits needed for SIMD. Rationale: Break-out CL of ART Vectorizer: number 4. The purpose is making the original CL smaller and easier to review. Bug: 34083438 Test: test-art-host Change-Id: I62a174944bbbe1e08f631f322c513eeaea14de26 --- compiler/optimizing/induction_var_range.cc | 3 +- test/618-checker-induction/src/Main.java | 18 ++++-- test/623-checker-loop-regressions/src/Main.java | 21 +++++++ test/641-iterations/expected.txt | 1 + test/641-iterations/info.txt | 1 + test/641-iterations/src/Main.java | 73 +++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 test/641-iterations/expected.txt create mode 100644 test/641-iterations/info.txt create mode 100644 test/641-iterations/src/Main.java diff --git a/compiler/optimizing/induction_var_range.cc b/compiler/optimizing/induction_var_range.cc index 3dfe17647..d6513c8e3 100644 --- a/compiler/optimizing/induction_var_range.cc +++ b/compiler/optimizing/induction_var_range.cc @@ -390,7 +390,8 @@ bool InductionVarRange::IsUnitStride(HInstruction* instruction, HInductionVarAnalysis::InductionInfo* trip = nullptr; if (HasInductionInfo(instruction, instruction, &loop, &info, &trip)) { if (info->induction_class == HInductionVarAnalysis::kLinear && - info->op_b->operation == HInductionVarAnalysis::kFetch) { + info->op_b->operation == HInductionVarAnalysis::kFetch && + !HInductionVarAnalysis::IsNarrowingLinear(info)) { int64_t stride_value = 0; if (IsConstant(info->op_a, kExact, &stride_value) && stride_value == 1) { int64_t off_value = 0; diff --git a/test/618-checker-induction/src/Main.java b/test/618-checker-induction/src/Main.java index ad3ff448d..2d9daf1d4 100644 --- a/test/618-checker-induction/src/Main.java +++ b/test/618-checker-induction/src/Main.java @@ -21,6 +21,8 @@ public class Main { static int[] a = new int[10]; + static int[] novec = new int[20]; // to prevent vectorization + /// CHECK-START: void Main.deadSingleLoop() loop_optimization (before) /// CHECK-DAG: Phi loop:{{B\d+}} outer_loop:none // @@ -132,16 +134,18 @@ public class Main { /// CHECK-START: void Main.deadInduction() loop_optimization (before) /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-DAG: Phi loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none // /// CHECK-START: void Main.deadInduction() loop_optimization (after) /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-NOT: Phi loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none static void deadInduction() { int dead = 0; for (int i = 0; i < a.length; i++) { - a[i] = 1; + a[i] = novec[2 * i] + 1; dead += 5; } } @@ -151,17 +155,19 @@ public class Main { /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-DAG: Phi loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none // /// CHECK-START: void Main.deadManyInduction() loop_optimization (after) /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-NOT: Phi loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none static void deadManyInduction() { int dead1 = 0, dead2 = 1, dead3 = 3; for (int i = 0; i < a.length; i++) { dead1 += 5; - a[i] = 2; + a[i] = novec[2 * i] + 2; dead2 += 10; dead3 += 100; } @@ -170,16 +176,18 @@ public class Main { /// CHECK-START: void Main.deadSequence() loop_optimization (before) /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-DAG: Phi loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none // /// CHECK-START: void Main.deadSequence() loop_optimization (after) /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-NOT: Phi loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none static void deadSequence() { int dead = 0; for (int i = 0; i < a.length; i++) { - a[i] = 3; + a[i] = novec[2 * i] + 3; // Increment value defined inside loop, // but sequence itself not used anywhere. dead += i; @@ -191,17 +199,19 @@ public class Main { /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none /// CHECK-DAG: ArrayGet loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-NOT: BoundsCheck // /// CHECK-START: void Main.deadCycleWithException(int) loop_optimization (after) /// CHECK-DAG: Phi loop:<> outer_loop:none /// CHECK-NOT: Phi loop:<> outer_loop:none /// CHECK-DAG: ArraySet loop:<> outer_loop:none + /// CHECK-DAG: ArrayGet loop:<> outer_loop:none /// CHECK-NOT: ArrayGet loop:<> outer_loop:none static void deadCycleWithException(int k) { int dead = 0; for (int i = 0; i < a.length; i++) { - a[i] = 4; + a[i] = novec[2 * i] + 4; // Increment value of dead cycle may throw exception. Dynamic // BCE takes care of the bounds check though, which enables // removing the ArrayGet after removing the dead cycle. diff --git a/test/623-checker-loop-regressions/src/Main.java b/test/623-checker-loop-regressions/src/Main.java index 2a7be2fbc..eee90ab28 100644 --- a/test/623-checker-loop-regressions/src/Main.java +++ b/test/623-checker-loop-regressions/src/Main.java @@ -261,6 +261,15 @@ public class Main { return x; } + // If vectorized, the narrowing subscript should not cause + // type inconsistencies in the synthesized code. + static void narrowingSubscript(float[] a) { + float val = 2.0f; + for (long i = 0; i < a.length; i++) { + a[(int) i] += val; + } + } + public static void main(String[] args) { expectEquals(10, earlyExitFirst(-1)); for (int i = 0; i <= 10; i++) { @@ -320,6 +329,12 @@ public class Main { expectEquals( 8070450532247928832L, geoLongMulLastValue(9223372036854775807L)); expectEquals( 0L, geoLongMulLastValue(-9223372036854775808L)); + float[] a = new float[16]; + narrowingSubscript(a); + for (int i = 0; i < 16; i++) { + expectEquals(2.0f, a[i]); + } + System.out.println("passed"); } @@ -334,4 +349,10 @@ public class Main { throw new Error("Expected: " + expected + ", found: " + result); } } + + private static void expectEquals(float expected, float result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } } diff --git a/test/641-iterations/expected.txt b/test/641-iterations/expected.txt new file mode 100644 index 000000000..b0aad4deb --- /dev/null +++ b/test/641-iterations/expected.txt @@ -0,0 +1 @@ +passed diff --git a/test/641-iterations/info.txt b/test/641-iterations/info.txt new file mode 100644 index 000000000..fd8059561 --- /dev/null +++ b/test/641-iterations/info.txt @@ -0,0 +1 @@ +Tests on varying trip counts (to validate vector/cleanup loops). diff --git a/test/641-iterations/src/Main.java b/test/641-iterations/src/Main.java new file mode 100644 index 000000000..6a27f8028 --- /dev/null +++ b/test/641-iterations/src/Main.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Tests of varying trip counts. Focused on testing + * core and cleanup loop after vectorization. + */ +public class Main { + + static int[] sA; + + static void init() { + for (int i = 0; i < sA.length; i++) + sA[i] = 100; + } + + static void doitTo(int n) { + for (int i = 0; i < n; i++) + sA[i] += 1; + } + + static void doitFrom(int n) { + for (int i = n; i < sA.length; i++) + sA[i] += 1; + } + + static void verify(int n) { + for (int i = 0; i < n; i++) + if (sA[i] != 101) + throw new Error("failed inside loop"); + for (int i = n; i < sA.length; i++) + if (sA[i] != 100) + throw new Error("failed outside loop"); + } + + static void verify() { + for (int i = 0; i < sA.length; i++) + if (sA[i] != 101) + throw new Error("failed inside loop"); + } + + static void driver() { + for (int n = 0; n <= sA.length; n++) { + init(); + doitTo(n); + verify(n); + doitFrom(n); + verify(); + } + } + + public static void main(String[] args) { + sA = new int[17]; + driver(); + sA = new int[32]; + driver(); + System.out.println("passed"); + } +} + -- 2.11.0