jdk
1/*
2* Copyright (c) 2022, Arm Limited. All rights reserved.
3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*
5* This code is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License version 2 only, as
7* published by the Free Software Foundation.
8*
9* This code is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12* version 2 for more details (a copy is included in the LICENSE file that
13* accompanied this code).
14*
15* You should have received a copy of the GNU General Public License version
16* 2 along with this work; if not, write to the Free Software Foundation,
17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18*
19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20* or visit www.oracle.com if you need additional information or have any
21* questions.
22*/
23
24package compiler.c2.irTests;25
26import compiler.lib.ir_framework.*;27import java.util.Random;28import jdk.test.lib.Utils;29
30/*
31* @test
32* @bug 8288107
33* @summary Auto-vectorization enhancement for integer Math.max/Math.min operations
34* @library /test/lib /
35* @requires vm.compiler2.enabled
36* @requires (os.simpleArch == "x64" & (vm.opt.UseSSE == "null" | vm.opt.UseSSE > 3))
37* | os.arch == "aarch64" | (os.arch == "riscv64" & vm.opt.UseRVV == true)
38* @run driver compiler.c2.irTests.TestAutoVecIntMinMax
39*/
40
41public class TestAutoVecIntMinMax {42private final static int LENGTH = 2000;43private final static Random RANDOM = Utils.getRandomInstance();44
45private static int[] a;46private static int[] b;47private static int[] c;48
49static {50a = new int[LENGTH];51b = new int[LENGTH];52c = new int[LENGTH];53for(int i = 0; i < LENGTH; i++) {54a[i] = RANDOM.nextInt();55b[i] = RANDOM.nextInt();56}57}58
59public static void main(String[] args) {60TestFramework.run();61}62
63// Test for auto-vectorization of Math.min operation on an array of integers64@Test65@IR(counts = {IRNode.LOAD_VECTOR_I, " >0 "})66@IR(counts = {IRNode.MIN_VI, " >0 "})67@IR(counts = {IRNode.STORE_VECTOR, " >0 "})68private static void testIntMin(int[] a, int[] b) {69for(int i = 0; i < LENGTH; i++) {70c[i] = Math.min(a[i], b[i]);71}72}73
74// Test for auto-vectorization of StrictMath.min operation on an array of integers75@Test76@IR(counts = {IRNode.LOAD_VECTOR_I, " >0 "})77@IR(counts = {IRNode.MIN_VI, " >0 "})78@IR(counts = {IRNode.STORE_VECTOR, " >0 "})79private static void testIntStrictMin(int[] a, int[] b) {80for(int i = 0; i < LENGTH; i++) {81c[i] = StrictMath.min(a[i], b[i]);82}83}84
85// Test for auto-vectorization of Math.max operation on an array of integers86@Test87@IR(counts = {IRNode.LOAD_VECTOR_I, " >0 "})88@IR(counts = {IRNode.MAX_VI, " >0 "})89@IR(counts = {IRNode.STORE_VECTOR, " >0 "})90private static void testIntMax(int[] a, int[] b) {91for(int i = 0; i < LENGTH; i++) {92c[i] = Math.max(a[i], b[i]);93}94}95
96// Test for auto-vectorization of StrictMath.max operation on an array of integers97@Test98@IR(counts = {IRNode.LOAD_VECTOR_I, " >0 "})99@IR(counts = {IRNode.MAX_VI, " >0 "})100@IR(counts = {IRNode.STORE_VECTOR, " >0 "})101private static void testIntStrictMax(int[] a, int[] b) {102for(int i = 0; i < LENGTH; i++) {103c[i] = StrictMath.max(a[i], b[i]);104}105}106
107@Run(test = {"testIntMin", "testIntStrictMin", "testIntMax", "testIntStrictMax"})108private void testIntMinMax_runner() {109testIntMin(a, b);110testIntStrictMin(a, b);111testIntMax(a, b);112testIntStrictMax(a, b);113}114}
115