|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 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 jdk.test.lib.Asserts; |
| 26 | +import compiler.lib.ir_framework.*; |
| 27 | + |
| 28 | +/* |
| 29 | + * @test |
| 30 | + * @bug 8322077 |
| 31 | + * @summary Test that Ideal transformations on the De Morgan's Law perform |
| 32 | + as expected for long. |
| 33 | + * @library /test/lib / |
| 34 | + * @run driver compiler.c2.irTests.DeMorganLawLongTests |
| 35 | + */ |
| 36 | +public class DeMorganLawLongTests { |
| 37 | + |
| 38 | + public static void main(String[] args) { |
| 39 | + TestFramework.run(); |
| 40 | + } |
| 41 | + |
| 42 | + @Run(test = { "test1", "test2", "test3", "test4" }) |
| 43 | + public void runMethod() { |
| 44 | + long a = RunInfo.getRandom().nextLong(); |
| 45 | + long b = RunInfo.getRandom().nextLong(); |
| 46 | + long c = RunInfo.getRandom().nextLong(); |
| 47 | + long d = RunInfo.getRandom().nextLong(); |
| 48 | + |
| 49 | + long min = Long.MIN_VALUE; |
| 50 | + long max = Long.MAX_VALUE; |
| 51 | + |
| 52 | + assertResult(0, 0, 0, 0); |
| 53 | + assertResult(a, b, c, d); |
| 54 | + assertResult(min, min, min, min); |
| 55 | + assertResult(max, max, max, max); |
| 56 | + } |
| 57 | + |
| 58 | + @DontCompile |
| 59 | + public void assertResult(long a, long b, long c, long d) { |
| 60 | + Asserts.assertEQ((~a | ~b) & (~c | ~d), test1(a, b, c, d)); |
| 61 | + Asserts.assertEQ((~a & ~b) | (~c & ~d), test2(a, b, c, d)); |
| 62 | + Asserts.assertEQ((~a | ~b) | (~c | ~d), test3(a, b, c, d)); |
| 63 | + Asserts.assertEQ((~a & ~b) & (~c & ~d), test4(a, b, c, d)); |
| 64 | + } |
| 65 | + |
| 66 | + // Checks (~a | ~b) & (~c | ~d) |
| 67 | + // => ~(a & b) & ~(c & d) |
| 68 | + // => ~((a & b) | (c & d)) |
| 69 | + @Test |
| 70 | + @IR(counts = { IRNode.AND , "2", |
| 71 | + IRNode.OR , "1", |
| 72 | + IRNode.XOR, "1", }) |
| 73 | + public long test1(long a, long b, long c, long d) { |
| 74 | + return (~a | ~b) & (~c | ~d); |
| 75 | + } |
| 76 | + |
| 77 | + // Checks (~a & ~b) | (~c & ~d) |
| 78 | + // => ~(a | b) | ~(c | d) |
| 79 | + // => ~((a | b) & (c | d)) |
| 80 | + @Test |
| 81 | + @IR(counts = { IRNode.AND , "1", |
| 82 | + IRNode.OR , "2", |
| 83 | + IRNode.XOR, "1", }) |
| 84 | + public long test2(long a, long b, long c, long d) { |
| 85 | + return (~a & ~b) | (~c & ~d); |
| 86 | + } |
| 87 | + |
| 88 | + // Checks (~a | ~b) | (~c | ~d) |
| 89 | + // => ~(a & b) | ~(c & d) |
| 90 | + // => ~((a & b) & (c & d)) |
| 91 | + @Test |
| 92 | + @IR(failOn = { IRNode.OR }) |
| 93 | + @IR(counts = { IRNode.AND , "3", |
| 94 | + IRNode.XOR, "1", }) |
| 95 | + public long test3(long a, long b, long c, long d) { |
| 96 | + return (~a | ~b) | (~c | ~d); |
| 97 | + } |
| 98 | + |
| 99 | + // Checks (~a & ~b) & (~c & ~d) |
| 100 | + // => ~(a | b) & ~(c | d) |
| 101 | + // => ~((a | b) | (c | d)) |
| 102 | + @Test |
| 103 | + @IR(failOn = { IRNode.AND }) |
| 104 | + @IR(counts = { IRNode.OR , "3", |
| 105 | + IRNode.XOR, "1", }) |
| 106 | + public long test4(long a, long b, long c, long d) { |
| 107 | + return (~a & ~b) & (~c & ~d); |
| 108 | + } |
| 109 | +} |
0 commit comments