|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | + |
| 24 | +package compiler.c2.irTests; |
| 25 | + |
| 26 | +import jdk.test.lib.Asserts; |
| 27 | +import compiler.lib.ir_framework.*; |
| 28 | + |
| 29 | +/* |
| 30 | + * @test |
| 31 | + * @bug 8278471 |
| 32 | + * @summary Remove unreached rules in AddNode::IdealIL |
| 33 | + * @library /test/lib / |
| 34 | + * @run driver compiler.c2.irTests.TestSpecialCasesOf_AMinusB_Plus_CMinusD_InAddIdeal |
| 35 | + */ |
| 36 | +/* Test conversion from (a - b) + (b - c) to (a - c) and conversion |
| 37 | + * from (a - b) + (c - a) to (c - b) have really happened so we can |
| 38 | + * safely remove both. */ |
| 39 | +public class TestSpecialCasesOf_AMinusB_Plus_CMinusD_InAddIdeal { |
| 40 | + |
| 41 | + public static void main(String[] args) { |
| 42 | + TestFramework.run(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) |
| 47 | + @IR(failOn = {IRNode.ADD_I}) |
| 48 | + @IR(counts = {IRNode.SUB_I, "1"}) |
| 49 | + public int test1Int(int a, int b, int c) { |
| 50 | + return (a - b) + (b - c); // transformed to a - c rather than (a + b) - (b + c) |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) |
| 55 | + @IR(failOn = {IRNode.ADD_L}) |
| 56 | + @IR(counts = {IRNode.SUB_L, "1"}) |
| 57 | + public long test1Long(long a, long b, long c) { |
| 58 | + return (a - b) + (b - c); // transformed to a - c rather than (a + b) - (b + c) |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) |
| 63 | + @IR(failOn = {IRNode.ADD_I}) |
| 64 | + @IR(counts = {IRNode.SUB_I, "1"}) |
| 65 | + public int test2Int(int b, int a, int c) { // make sure inputs sorted |
| 66 | + return (a - b) + (c - a); // transformed to c - b rather than (a + c) - (b + a) |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) |
| 71 | + @IR(failOn = {IRNode.ADD_L}) |
| 72 | + @IR(counts = {IRNode.SUB_L, "1"}) |
| 73 | + public long test2Long(long b, long a, long c) { // make sure inputs sorted |
| 74 | + return (a - b) + (c - a); // transformed to return c - b rather than (a + c) - (b + a) |
| 75 | + } |
| 76 | +} |
0 commit comments