|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. 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 | +package compiler.c2.irTests; |
| 24 | + |
| 25 | +import compiler.lib.generators.Generator; |
| 26 | +import compiler.lib.generators.Generators; |
| 27 | +import compiler.lib.generators.RestrictableGenerator; |
| 28 | +import compiler.lib.ir_framework.DontCompile; |
| 29 | +import compiler.lib.ir_framework.IR; |
| 30 | +import compiler.lib.ir_framework.IRNode; |
| 31 | +import compiler.lib.ir_framework.Run; |
| 32 | +import compiler.lib.ir_framework.Test; |
| 33 | +import compiler.lib.ir_framework.TestFramework; |
| 34 | +import jdk.test.lib.Asserts; |
| 35 | + |
| 36 | +/* |
| 37 | + * @test |
| 38 | + * @bug 8350988 |
| 39 | + * @summary Test that Identity simplifications of Involution nodes are being performed as expected. |
| 40 | + * @library /test/lib / |
| 41 | + * @run driver compiler.c2.irTests.InvolutionIdentityTests |
| 42 | + */ |
| 43 | +public class InvolutionIdentityTests { |
| 44 | + |
| 45 | + public static final RestrictableGenerator<Integer> GEN_CHAR = Generators.G.safeRestrict(Generators.G.ints(), Character.MIN_VALUE, Character.MAX_VALUE); |
| 46 | + public static final RestrictableGenerator<Integer> GEN_SHORT = Generators.G.safeRestrict(Generators.G.ints(), Short.MIN_VALUE, Short.MAX_VALUE); |
| 47 | + public static final RestrictableGenerator<Long> GEN_LONG = Generators.G.longs(); |
| 48 | + public static final RestrictableGenerator<Integer> GEN_INT = Generators.G.ints(); |
| 49 | + public static final Generator<Float> GEN_FLOAT = Generators.G.floats(); |
| 50 | + public static final Generator<Double> GEN_DOUBLE = Generators.G.doubles(); |
| 51 | + |
| 52 | + public static void main(String[] args) { |
| 53 | + TestFramework.run(); |
| 54 | + } |
| 55 | + |
| 56 | + @Run(test = { |
| 57 | + "testI1", "testI2", |
| 58 | + "testL1", "testL2", |
| 59 | + "testS1", |
| 60 | + "testUS1", |
| 61 | + "testF1", |
| 62 | + "testD1" |
| 63 | + }) |
| 64 | + public void runMethod() { |
| 65 | + int ai = GEN_INT.next(); |
| 66 | + |
| 67 | + int mini = Integer.MIN_VALUE; |
| 68 | + int maxi = Integer.MAX_VALUE; |
| 69 | + |
| 70 | + assertResultI(0); |
| 71 | + assertResultI(ai); |
| 72 | + assertResultI(mini); |
| 73 | + assertResultI(maxi); |
| 74 | + |
| 75 | + long al = GEN_LONG.next(); |
| 76 | + |
| 77 | + long minl = Long.MIN_VALUE; |
| 78 | + long maxl = Long.MAX_VALUE; |
| 79 | + |
| 80 | + assertResultL(0); |
| 81 | + assertResultL(al); |
| 82 | + assertResultL(minl); |
| 83 | + assertResultL(maxl); |
| 84 | + |
| 85 | + short as = GEN_SHORT.next().shortValue(); |
| 86 | + |
| 87 | + short mins = Short.MIN_VALUE; |
| 88 | + short maxs = Short.MAX_VALUE; |
| 89 | + |
| 90 | + assertResultS((short) 0); |
| 91 | + assertResultS(as); |
| 92 | + assertResultS(mins); |
| 93 | + assertResultS(maxs); |
| 94 | + |
| 95 | + char ac = (char) GEN_CHAR.next().intValue(); |
| 96 | + |
| 97 | + char minc = Character.MIN_VALUE; |
| 98 | + char maxc = Character.MAX_VALUE; |
| 99 | + |
| 100 | + assertResultUS((char) 0); |
| 101 | + assertResultUS(ac); |
| 102 | + assertResultUS(minc); |
| 103 | + assertResultUS(maxc); |
| 104 | + |
| 105 | + float af = GEN_FLOAT.next(); |
| 106 | + float inf = Float.POSITIVE_INFINITY; |
| 107 | + float nanf = Float.NaN; |
| 108 | + |
| 109 | + assertResultF(0f); |
| 110 | + assertResultF(-0f); |
| 111 | + assertResultF(af); |
| 112 | + assertResultF(inf); |
| 113 | + assertResultF(nanf); |
| 114 | + |
| 115 | + double ad = GEN_DOUBLE.next(); |
| 116 | + double ind = Double.POSITIVE_INFINITY; |
| 117 | + double nand = Double.NaN; |
| 118 | + |
| 119 | + assertResultD(0d); |
| 120 | + assertResultD(-0d); |
| 121 | + assertResultD(ad); |
| 122 | + assertResultD(ind); |
| 123 | + assertResultD(nand); |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | + @DontCompile |
| 128 | + public void assertResultI(int a) { |
| 129 | + Asserts.assertEQ(Integer.reverseBytes(Integer.reverseBytes(a)), testI1(a)); |
| 130 | + Asserts.assertEQ(Integer.reverse(Integer.reverse(a)) , testI2(a)); |
| 131 | + } |
| 132 | + |
| 133 | + @DontCompile |
| 134 | + public void assertResultL(long a) { |
| 135 | + Asserts.assertEQ(Long.reverseBytes(Long.reverseBytes(a)), testL1(a)); |
| 136 | + Asserts.assertEQ(Long.reverse(Long.reverse(a)) , testL2(a)); |
| 137 | + } |
| 138 | + |
| 139 | + @DontCompile |
| 140 | + public void assertResultS(short a) { |
| 141 | + Asserts.assertEQ(Short.reverseBytes(Short.reverseBytes(a)), testS1(a)); |
| 142 | + } |
| 143 | + |
| 144 | + @DontCompile |
| 145 | + public void assertResultUS(char a) { |
| 146 | + Asserts.assertEQ(Character.reverseBytes(Character.reverseBytes(a)), testUS1(a)); |
| 147 | + } |
| 148 | + |
| 149 | + @DontCompile |
| 150 | + public void assertResultF(float a) { |
| 151 | + Asserts.assertEQ(Float.floatToRawIntBits(-(-a)), Float.floatToRawIntBits(testF1(a))); |
| 152 | + } |
| 153 | + |
| 154 | + @DontCompile |
| 155 | + public void assertResultD(double a) { |
| 156 | + Asserts.assertEQ(Double.doubleToRawLongBits(-(-a)), Double.doubleToRawLongBits(testD1(a))); |
| 157 | + } |
| 158 | + |
| 159 | + @Test |
| 160 | + @IR(failOn = {IRNode.REVERSE_BYTES_I}) |
| 161 | + public int testI1(int x) { |
| 162 | + return Integer.reverseBytes(Integer.reverseBytes(x)); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + @IR(failOn = {IRNode.REVERSE_I}) |
| 167 | + public int testI2(int x) { |
| 168 | + return Integer.reverse(Integer.reverse(x)); |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + @IR(failOn = {IRNode.REVERSE_BYTES_L}) |
| 173 | + public long testL1(long x) { |
| 174 | + return Long.reverseBytes(Long.reverseBytes(x)); |
| 175 | + } |
| 176 | + |
| 177 | + @Test |
| 178 | + @IR(failOn = {IRNode.REVERSE_L}) |
| 179 | + public long testL2(long x) { |
| 180 | + return Long.reverse(Long.reverse(x)); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + @IR(failOn = {IRNode.REVERSE_BYTES_S}) |
| 185 | + public short testS1(short x) { |
| 186 | + return Short.reverseBytes(Short.reverseBytes(x)); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + @IR(failOn = {IRNode.REVERSE_BYTES_US}) |
| 191 | + public char testUS1(char x) { |
| 192 | + return Character.reverseBytes(Character.reverseBytes(x)); |
| 193 | + } |
| 194 | + |
| 195 | + @Test |
| 196 | + @IR(failOn = {IRNode.NEG_F}) |
| 197 | + public float testF1(float x) { |
| 198 | + return -(-x); |
| 199 | + } |
| 200 | + |
| 201 | + @Test |
| 202 | + @IR(failOn = {IRNode.NEG_D}) |
| 203 | + public double testD1(double x) { |
| 204 | + return -(-x); |
| 205 | + } |
| 206 | +} |
0 commit comments