1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug JDK-8310130
* @summary Special test cases for PhaseIdealLoop::move_unordered_reduction_out_of_loop
* Here a case with partial vectorization of the reduction.
* @requires vm.bits == "64"
* @library /test/lib /
* @run driver compiler.loopopts.superword.TestUnorderedReductionPartialVectorization
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class TestUnorderedReductionPartialVectorization {
static final int RANGE = 1024;
static final int ITER = 10;
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = {"test1"})
@Warmup(0)
public void runTests() throws Exception {
int[] data = new int[RANGE];
init(data);
for (int i = 0; i < ITER; i++) {
long r1 = test1(data, i);
long r2 = ref1(data, i);
if (r1 != r2) {
throw new RuntimeException("Wrong result test1: " + r1 + " != " + r2);
}
}
}
@Test
@IR(counts = {IRNode.LOAD_VECTOR_I, IRNode.VECTOR_SIZE + "min(max_int, max_long)", "> 0",
IRNode.VECTOR_CAST_I2L, IRNode.VECTOR_SIZE + "min(max_int, max_long)", "> 0",
IRNode.OR_REDUCTION_V, "> 0",},
applyIfCPUFeatureOr = {"avx2", "true"})
static long test1(int[] data, long sum) {
for (int i = 0; i < data.length; i++) {
// Mixing int and long ops means we only end up allowing half of the int
// loads in one pack, and we have two int packs. The first pack has one
// of the pairs missing because of the store, which creates a dependency.
// The first pack is rejected and left as scalar, the second pack succeeds
// with vectorization. That means we have a mixed scalar/vector reduction
// chain. This way it is possible that a vector-reduction has a scalar
// reduction as input, which is neigher a phi nor a vector reduction.
// In such a case, we must bail out of the optimization in
// PhaseIdealLoop::move_unordered_reduction_out_of_loop
int v = data[i]; // int read
data[0] = 0; // ruin the first pack
sum |= v; // long reduction (and implicit cast from int to long)
}
return sum;
}
static long ref1(int[] data, long sum) {
for (int i = 0; i < data.length; i++) {
int v = data[i];
data[0] = 0;
sum |= v;
}
return sum;
}
static void init(int[] data) {
for (int i = 0; i < RANGE; i++) {
data[i] = i + 1;
}
}
}
|