ConditionalEliminationTest13.java revision 12968:4d8a004e5c6d
10SN/A/*
216721Scoffeys * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
30SN/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40SN/A *
50SN/A * This code is free software; you can redistribute it and/or modify it
60SN/A * under the terms of the GNU General Public License version 2 only, as
72362SN/A * published by the Free Software Foundation.
80SN/A *
92362SN/A * This code is distributed in the hope that it will be useful, but WITHOUT
100SN/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110SN/A * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
120SN/A * version 2 for more details (a copy is included in the LICENSE file that
130SN/A * accompanied this code).
140SN/A *
150SN/A * You should have received a copy of the GNU General Public License version
160SN/A * 2 along with this work; if not, write to the Free Software Foundation,
170SN/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
180SN/A *
190SN/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
200SN/A * or visit www.oracle.com if you need additional information or have any
212362SN/A * questions.
222362SN/A */
232362SN/Apackage org.graalvm.compiler.core.test;
240SN/A
250SN/Aimport org.graalvm.compiler.debug.Debug;
260SN/Aimport org.graalvm.compiler.nodes.StructuredGraph;
270SN/Aimport org.graalvm.compiler.nodes.ValueNode;
287850SN/Aimport org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
297850SN/Aimport org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
307850SN/Aimport org.graalvm.compiler.phases.common.CanonicalizerPhase;
317850SN/Aimport org.graalvm.compiler.phases.tiers.PhaseContext;
3212433Sshermanimport org.junit.Test;
3312433Ssherman
3412433Sshermanimport jdk.vm.ci.meta.ResolvedJavaMethod;
357850SN/A
368044SN/Apublic class ConditionalEliminationTest13 extends ConditionalEliminationTestBase {
378044SN/A    public ConditionalEliminationTest13() {
380SN/A        super(false);
390SN/A    }
400SN/A
410SN/A    private static int sink0;
4217338Smli    private static int sink1;
430SN/A    private static int sink2;
440SN/A
450SN/A    @Override
467850SN/A    protected InlineInvokePlugin.InlineInfo bytecodeParserShouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
470SN/A        return InlineInvokePlugin.InlineInfo.createStandardInlineInfo(method);
4811519Sredestad    }
4911519Sredestad
5011519Sredestad    public static void referenceSnippet1(int a) {
517850SN/A        if (Integer.compareUnsigned(a, a + 1) < 0) {
527850SN/A            sink1 = 0;
537850SN/A        } else {
540SN/A            sink0 = -1;
550SN/A        }
560SN/A    }
570SN/A
581107SN/A    public static void testSnippet1(int a) {
590SN/A        if (Integer.compareUnsigned(a, a + 1) < 0 || a == 0) {
600SN/A            sink1 = 0;
610SN/A        } else {
620SN/A            sink0 = -1;
630SN/A        }
640SN/A    }
650SN/A
660SN/A    public static void referenceSnippet2(int a) {
670SN/A        if (0 < a) {
680SN/A            sink1 = 0;
690SN/A        }
700SN/A        sink0 = -1;
710SN/A    }
720SN/A
7311519Sredestad    public static void testSnippet2(int a) {
7411519Sredestad        if (0 < a) {
7511519Sredestad            if (a == -1) {
7611519Sredestad                sink2 = -2;
7711519Sredestad            }
7811519Sredestad            sink1 = 0;
7911519Sredestad        }
8011519Sredestad        sink0 = -1;
8111519Sredestad    }
8211519Sredestad
8311519Sredestad    public static void testSnippet3(int a) {
8411519Sredestad        if (0 < a) {
8511519Sredestad            if (a == 1) {
8611519Sredestad                sink2 = -2;
8711519Sredestad            }
8811519Sredestad            sink1 = 0;
8911519Sredestad        }
9011519Sredestad        sink0 = -1;
9111519Sredestad    }
9211519Sredestad
9311519Sredestad    @SuppressWarnings("unused")
9411519Sredestad    public static void referenceSnippet4(int a) {
950SN/A        sink1 = 0;
960SN/A    }
977850SN/A
987850SN/A    public static void testSnippet4(int a) {
997850SN/A        if (Integer.compareUnsigned(a - 1, a) < 0 || a == 0) {
1007850SN/A            sink1 = 0;
1017850SN/A        } else {
1027850SN/A            sink0 = -1;
1030SN/A        }
1040SN/A    }
1057850SN/A
1060SN/A    public static void testSnippet5(int a) {
1070SN/A        if (a < 0) {
1080SN/A            if (a == -1) {
1090SN/A                sink2 = -2;
1100SN/A            }
1110SN/A            sink1 = 0;
1120SN/A        }
1130SN/A        sink0 = -1;
1140SN/A    }
1157850SN/A
1167850SN/A    public static void referenceSnippet6(int a) {
1177850SN/A        if (a < 0) {
1187850SN/A            sink1 = 0;
1197850SN/A        }
1200SN/A        sink0 = -1;
1210SN/A    }
1227850SN/A
1230SN/A    public static void testSnippet6(int a) {
12411519Sredestad        if (a < 0) {
1257267SN/A            if (a == 0) {
1267850SN/A                sink2 = -2;
1277850SN/A            }
1280SN/A            sink1 = 0;
1290SN/A        }
1300SN/A        sink0 = -1;
1310SN/A    }
1321107SN/A
1330SN/A    public static void testSnippet7(int a) {
1340SN/A        if (0 < a) {
1350SN/A            if (a == 0) {
1360SN/A                sink2 = -2;
1377267SN/A            }
1381107SN/A            sink1 = 0;
1390SN/A        }
1401107SN/A        sink0 = -1;
1410SN/A    }
1420SN/A
1430SN/A    public static void testSnippet8(int a) {
1440SN/A        if (Integer.compareUnsigned(a, a + 1) < 0 || a == 0xffff_ffff) {
1450SN/A            sink1 = 0;
1460SN/A        } else {
1470SN/A            sink0 = -1;
1480SN/A        }
1490SN/A    }
1500SN/A
1517267SN/A    public static void referenceSnippet9(int a) {
1527267SN/A        if (Integer.compareUnsigned(a - 1, a) < 0) {
1537850SN/A            sink1 = 0;
1547850SN/A        } else {
1557850SN/A            sink0 = -1;
1567850SN/A        }
1577850SN/A    }
1587850SN/A
1597850SN/A    public static void testSnippet9(int a) {
1607850SN/A        if (Integer.compareUnsigned(a - 1, a) < 0 || a == 0xffff_ffff) {
1617850SN/A            sink1 = 0;
1627850SN/A        } else {
1637850SN/A            sink0 = -1;
1640SN/A        }
1657850SN/A    }
1660SN/A
1670SN/A    private static int either(int a, int b) {
16811519Sredestad        return (sink0 + sink1 + sink2) == 0 ? a : b;
16911519Sredestad    }
17011519Sredestad
17111519Sredestad    public static void testSnippet10(int a) {
17211519Sredestad        if (Integer.compareUnsigned(a, a + either(1, 2)) < 0 || a == 0xffff_ffff || a == 0xffff_fffe) {
17311519Sredestad            sink1 = 0;
17411519Sredestad        } else {
17511519Sredestad            sink0 = -1;
1767850SN/A        }
1777850SN/A    }
1787850SN/A
1797850SN/A    public static void referenceSnippet11(int a) {
1807850SN/A        if (Integer.compareUnsigned(a, Integer.MAX_VALUE + 1) > 0) {
1817850SN/A            sink1 = 0;
1827850SN/A        }
1837850SN/A        sink0 = -1;
1847850SN/A    }
1857850SN/A
1867850SN/A    public static void testSnippet11(int a) {
1877850SN/A        if (Integer.compareUnsigned(a, Integer.MAX_VALUE + 1) > 0) {
1887850SN/A            if (Integer.compareUnsigned(a, 42) <= 0) {
1897850SN/A                sink2 = -2;
1907850SN/A            }
1917850SN/A            sink1 = 0;
1927850SN/A        }
1937850SN/A        sink0 = -1;
1947850SN/A    }
19511519Sredestad
19611519Sredestad    public static void referenceSnippet12(int a) {
19711519Sredestad        if (Integer.compareUnsigned(a, 0xffff_ffff) >= 0) {
19811519Sredestad            sink1 = 0;
1997850SN/A        } else {
2007850SN/A            sink0 = -1;
2017850SN/A        }
20212433Ssherman    }
20312433Ssherman
20412433Ssherman    public static void testSnippet12(int a) {
20512433Ssherman        if (Integer.compareUnsigned(a, 0xffff_ffff) >= 0 && a == 0xffff_ffff) {
20612433Ssherman            sink1 = 0;
20712433Ssherman        } else {
20812433Ssherman            sink0 = -1;
20912433Ssherman        }
21012433Ssherman    }
21112433Ssherman
21212433Ssherman    public static void testSnippet13(int a) {
21312433Ssherman        int x = either(0, 1);
21412433Ssherman        if (a <= a + x) {
21512433Ssherman            if (a == Integer.MAX_VALUE) {
21612433Ssherman                sink2 = -2;
21712433Ssherman            }
21812433Ssherman            sink1 = 0;
21912433Ssherman        } else {
22012433Ssherman            sink0 = -1;
22112433Ssherman        }
22212433Ssherman    }
22312433Ssherman
22413532Siris    public static void referenceSnippet14(int a) {
22512433Ssherman        int x = either(0, 1);
22612433Ssherman        if (a < a + x) {
22712433Ssherman            sink1 = 0;
22812433Ssherman        } else {
22912433Ssherman            sink0 = -1;
23012433Ssherman        }
23113722Ssherman    }
23212433Ssherman
23312433Ssherman    public static void testSnippet14(int a) {
23412433Ssherman        int x = either(0, 1);
23512433Ssherman        if (a < a + x) {
23613722Ssherman            if (a == Integer.MAX_VALUE) {
23712433Ssherman                sink2 = -2;
23812433Ssherman            }
23912433Ssherman            sink1 = 0;
24012433Ssherman        } else {
24112433Ssherman            sink0 = -1;
24212433Ssherman        }
24312433Ssherman    }
24412433Ssherman
24512433Ssherman    @Test
24612433Ssherman    public void test1() {
24712433Ssherman        testConditionalElimination("testSnippet1", "referenceSnippet1");
24812433Ssherman    }
24912433Ssherman
25012433Ssherman    @Test
25112433Ssherman    public void test2() {
25212433Ssherman        testConditionalElimination("testSnippet2", "referenceSnippet2");
25312433Ssherman    }
25412433Ssherman
25512433Ssherman    @Test
25612433Ssherman    public void test3() {
25712433Ssherman        testConditionalElimination("testSnippet3", "testSnippet3");
25812433Ssherman    }
25912433Ssherman
26012433Ssherman    @Test
26112433Ssherman    public void test4() {
26212433Ssherman        testConditionalElimination("testSnippet4", "referenceSnippet4");
26313532Siris    }
26412433Ssherman
26512433Ssherman    @Test
26612433Ssherman    public void test5() {
26712433Ssherman        testConditionalElimination("testSnippet5", "testSnippet5");
26812433Ssherman    }
26912433Ssherman
27012433Ssherman    @Test
27112433Ssherman    public void test6() {
27212433Ssherman        testConditionalElimination("testSnippet6", "referenceSnippet6");
27312433Ssherman    }
27412433Ssherman
27512433Ssherman    @Test
27612433Ssherman    public void test7() {
27712433Ssherman        testConditionalElimination("testSnippet7", "referenceSnippet2");
27812433Ssherman    }
27912433Ssherman
28012433Ssherman    @Test
2817850SN/A    public void test8() {
2827850SN/A        testConditionalElimination("testSnippet8", "referenceSnippet4");
2837850SN/A    }
2847850SN/A
2857850SN/A    @Test
2867850SN/A    public void test9() {
2877850SN/A        testConditionalElimination("testSnippet9", "referenceSnippet9");
2887850SN/A    }
2897850SN/A
2907850SN/A    @Test
2917850SN/A    public void test10() {
2927850SN/A        testConditionalElimination("testSnippet10", "referenceSnippet4");
2937850SN/A    }
2947850SN/A
2957850SN/A    @Test
2967850SN/A    public void test11() {
2977850SN/A        testConditionalElimination("testSnippet11", "referenceSnippet11");
2987850SN/A    }
29911478Sredestad
30011519Sredestad    @Test
3017850SN/A    public void test12() {
3020SN/A        testConditionalElimination("testSnippet12", "referenceSnippet12");
3030SN/A    }
3040SN/A
3057267SN/A    @Test
3067850SN/A    public void test13() {
3077850SN/A        testConditionalElimination("testSnippet13", "testSnippet13");
3087850SN/A    }
3097850SN/A
3107850SN/A    @Test
3117850SN/A    public void test14() {
3127850SN/A        testConditionalElimination("testSnippet14", "referenceSnippet14");
3137850SN/A    }
3147850SN/A
3157850SN/A    @Override
3167850SN/A    protected void prepareGraph(StructuredGraph graph, CanonicalizerPhase canonicalizer, PhaseContext context, boolean applyLowering) {
3177850SN/A        super.prepareGraph(graph, canonicalizer, context, applyLowering);
3187850SN/A        graph.clearAllStateAfter();
3197850SN/A        graph.setGuardsStage(StructuredGraph.GuardsStage.AFTER_FSA);
3207850SN/A        Debug.dump(Debug.BASIC_LOG_LEVEL, graph, "After preparation");
3217850SN/A        canonicalizer.apply(graph, context);
3227850SN/A    }
32311519Sredestad}
3247850SN/A