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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* 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.
*/
package compiler.c2.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
import java.util.Random;
import jdk.test.lib.Utils;
/*
* @test
* @summary Test that patterns involving duplicated conversion nodes behind phi are properly optimized.
* @bug 8316918
* @library /test/lib /
* @requires vm.compiler2.enabled
* @run driver compiler.c2.irTests.TestPhiDuplicatedConversion
*/
public class TestPhiDuplicatedConversion {
public static void main(String[] args) {
TestFramework.run();
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static float int2Float(boolean c, int a, int b) {
return c ? a : b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static double int2Double(boolean c, int a, int b) {
return c ? a : b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static long int2Long(boolean c, int a, int b) {
return c ? a : b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static int float2Int(boolean c, float a, float b) {
return c ? (int)a : (int)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static double float2Double(boolean c, float a, float b) {
return c ? (double)a : (double)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static long float2Long(boolean c, float a, float b) {
return c ? (long)a : (long)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static int double2Int(boolean c, double a, double b) {
return c ? (int)a : (int)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static float double2Float(boolean c, double a, double b) {
return c ? (float)a : (float)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static long double2Long(boolean c, double a, double b) {
return c ? (long)a : (long)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static float long2Float(boolean c, long a, long b) {
return c ? a : b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static double long2Double(boolean c, long a, long b) {
return c ? a : b;
}
@Test
@IR(counts = {IRNode.CONV, "1"})
public static int long2Int(boolean c, long a, long b) {
return c ? (int)a : (int)b;
}
@Test
@IR(counts = {IRNode.CONV, "1"}, applyIfCPUFeatureOr = {"f16c", "true", "avx512vl", "true", "asimd", "true", "rvv", "true"})
public static short float2HalfFloat(boolean c, float a, float b) {
return c ? Float.floatToFloat16(a) : Float.floatToFloat16(b);
}
@Test
@IR(counts = {IRNode.CONV, "1"}, applyIfCPUFeatureOr = {"f16c", "true", "avx512vl", "true", "asimd", "true", "rvv", "true"})
public static float halfFloat2Float(boolean c, short a, short b) {
return c ? Float.float16ToFloat(a) : Float.float16ToFloat(b);
}
@Run(test = {"int2Float", "int2Double", "int2Long",
"float2Int", "float2Double", "float2Long",
"double2Int", "double2Float", "double2Long",
"long2Float", "long2Double", "long2Int",
"float2HalfFloat", "halfFloat2Float"})
public void runTests() {
assertResults(true, 10, 20, 3.14f, -1.6f, 3.1415, -1.618, 30L, 400L, Float.floatToFloat16(10.5f), Float.floatToFloat16(20.5f));
assertResults(false, 10, 20, 3.14f, -1.6f, 3.1415, -1.618, 30L, 400L, Float.floatToFloat16(10.5f), Float.floatToFloat16(20.5f));
}
@DontCompile
public void assertResults(boolean c, int intA, int intB, float floatA, float floatB, double doubleA, double doubleB, long longA, long longB, short halfFloatA, short halfFloatB) {
Asserts.assertEQ(c ? (float)intA : (float)intB, int2Float(c, intA, intB));
Asserts.assertEQ(c ? (double)intA : (double)intB, int2Double(c, intA, intB));
Asserts.assertEQ(c ? (long)intA : (long)intB, int2Long(c, intA, intB));
Asserts.assertEQ(c ? (int)floatA : (int)floatB, float2Int(c, floatA, floatB));
Asserts.assertEQ(c ? (double)floatA : (double)floatB, float2Double(c, floatA, floatB));
Asserts.assertEQ(c ? (long)floatA : (long)floatB, float2Long(c, floatA, floatB));
Asserts.assertEQ(c ? (int)doubleA : (int)doubleB, double2Int(c, doubleA, doubleB));
Asserts.assertEQ(c ? (float)doubleA : (float)doubleB, double2Float(c, doubleA, doubleB));
Asserts.assertEQ(c ? (long)doubleA : (long)doubleB, double2Long(c, doubleA, doubleB));
Asserts.assertEQ(c ? (float)longA : (float)longB, long2Float(c, longA, longB));
Asserts.assertEQ(c ? (double)longA : (double)longB, long2Double(c, longA, longB));
Asserts.assertEQ(c ? (int)longA : (int)longB, long2Int(c, longA, longB));
Asserts.assertEQ(c ? Float.floatToFloat16(floatA) : Float.floatToFloat16(floatB), float2HalfFloat(c, floatA, floatB));
Asserts.assertEQ(c ? Float.float16ToFloat(halfFloatA) : Float.float16ToFloat(halfFloatB), halfFloat2Float(c, halfFloatA, halfFloatB));
}
}
|