src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/ShortCircuitOrNodeTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/ShortCircuitOrNodeTest.java

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/ShortCircuitOrNodeTest.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2016, 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. --- 1,7 ---- /* ! * Copyright (c) 2016, 2017, 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.
*** 22,49 **** --- 22,55 ---- */ package org.graalvm.compiler.nodes.test; import java.util.function.Function; + import org.junit.Assert; import org.junit.Test; import org.graalvm.compiler.core.test.GraalCompilerTest; import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.LogicNode; import org.graalvm.compiler.nodes.ShortCircuitOrNode; + import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.ValueNode; + import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; import org.graalvm.compiler.nodes.calc.ConditionalNode; import org.graalvm.compiler.nodes.calc.IntegerEqualsNode; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration; + import org.graalvm.compiler.phases.common.CanonicalizerPhase; + import org.graalvm.compiler.phases.tiers.PhaseContext; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; public class ShortCircuitOrNodeTest extends GraalCompilerTest { + static boolean shortCircuitOr(boolean b1, boolean b2) { return b1 || b2; } @Override
*** 80,85 **** --- 86,392 ---- @Test public void testSharedCondition() { test("testSharedConditionSnippet", "String"); } + private int testInputCombinations(String snippet) { + int trueCount = 0; + for (int i = 0; i < 4; ++i) { + boolean aValue = (i <= 1); + boolean bValue = ((i % 2) == 0); + boolean returnValue = (boolean) test(snippet, new Object[]{aValue, bValue}).returnValue; + + if (returnValue) { + trueCount++; + } + } + + return trueCount; + } + + public boolean testSimpleSnippet(boolean a, boolean b) { + return shortCircuitOr(a, b); + } + + @Test + public void testSimple() { + testInputCombinations("testSimpleSnippet"); + } + + public static boolean testCascadeSnippet1(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(a, b), a); + } + + public static boolean testCascadeSnippet2(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(b, a), a); + } + + public static boolean testCascadeSnippet3(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(a, b)); + } + + public static boolean testCascadeSnippet4(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(b, a)); + } + + public static boolean testCascadeSnippet5(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(a, b), a); + } + + public static boolean testCascadeSnippet6(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(b, a), a); + } + + public static boolean testCascadeSnippet7(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(a, b)); + } + + public static boolean testCascadeSnippet8(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(b, a)); + } + + public static boolean testCascadeSnippet9(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!a, b), a); + } + + public static boolean testCascadeSnippet10(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!b, a), a); + } + + public static boolean testCascadeSnippet11(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(a, b)); + } + + public static boolean testCascadeSnippet12(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(b, a)); + } + + public static boolean testCascadeSnippet13(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!a, b), a); + } + + public static boolean testCascadeSnippet14(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!b, a), a); + } + + public static boolean testCascadeSnippet15(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(a, b)); + } + + public static boolean testCascadeSnippet16(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(!b, a)); + } + + public static boolean testCascadeSnippet17(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(a, !b), a); + } + + public static boolean testCascadeSnippet18(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(b, !a), a); + } + + public static boolean testCascadeSnippet19(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(!a, b)); + } + + public static boolean testCascadeSnippet20(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(!b, a)); + } + + public static boolean testCascadeSnippet21(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(a, !b), a); + } + + public static boolean testCascadeSnippet22(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(b, !a), a); + } + + public static boolean testCascadeSnippet23(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(!a, b)); + } + + public static boolean testCascadeSnippet24(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(!b, a)); + } + + public static boolean testCascadeSnippet25(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!a, !b), a); + } + + public static boolean testCascadeSnippet26(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!b, !a), a); + } + + public static boolean testCascadeSnippet27(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(!a, b)); + } + + public static boolean testCascadeSnippet28(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(!b, a)); + } + + public static boolean testCascadeSnippet29(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!a, !b), a); + } + + public static boolean testCascadeSnippet30(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!b, !a), a); + } + + public static boolean testCascadeSnippet31(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(!a, b)); + } + + public static boolean testCascadeSnippet32(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(!b, a)); + } + + public static boolean testCascadeSnippet33(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(a, b), !a); + } + + public static boolean testCascadeSnippet34(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(b, a), !a); + } + + public static boolean testCascadeSnippet35(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(a, !b)); + } + + public static boolean testCascadeSnippet36(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(b, !a)); + } + + public static boolean testCascadeSnippet37(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(a, b), !a); + } + + public static boolean testCascadeSnippet38(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(b, a), !a); + } + + public static boolean testCascadeSnippet39(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(a, !b)); + } + + public static boolean testCascadeSnippet40(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(b, !a)); + } + + public static boolean testCascadeSnippet41(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!a, b), !a); + } + + public static boolean testCascadeSnippet42(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!b, a), !a); + } + + public static boolean testCascadeSnippet43(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(a, !b)); + } + + public static boolean testCascadeSnippet44(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(b, !a)); + } + + public static boolean testCascadeSnippet45(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!a, b), !a); + } + + public static boolean testCascadeSnippet46(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!b, a), !a); + } + + public static boolean testCascadeSnippet47(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(a, !b)); + } + + public static boolean testCascadeSnippet48(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(!b, !a)); + } + + public static boolean testCascadeSnippet49(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(a, !b), !a); + } + + public static boolean testCascadeSnippet50(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(b, !a), !a); + } + + public static boolean testCascadeSnippet51(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(!a, !b)); + } + + public static boolean testCascadeSnippet52(boolean a, boolean b) { + return shortCircuitOr(a, shortCircuitOr(!b, !a)); + } + + public static boolean testCascadeSnippet53(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(a, !b), !a); + } + + public static boolean testCascadeSnippet54(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(b, !a), !a); + } + + public static boolean testCascadeSnippet55(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(!a, !b)); + } + + public static boolean testCascadeSnippet56(boolean a, boolean b) { + return shortCircuitOr(!a, shortCircuitOr(!b, !a)); + } + + public static boolean testCascadeSnippet57(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!a, !b), !a); + } + + public static boolean testCascadeSnippet58(boolean a, boolean b) { + return shortCircuitOr(shortCircuitOr(!b, !a), !a); + } + + public static boolean testCascadeSnippet59(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(!a, !b)); + } + + public static boolean testCascadeSnippet60(boolean a, boolean b) { + return shortCircuitOr(a, !shortCircuitOr(!b, !a)); + } + + public static boolean testCascadeSnippet61(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!a, !b), !a); + } + + public static boolean testCascadeSnippet62(boolean a, boolean b) { + return shortCircuitOr(!shortCircuitOr(!b, !a), !a); + } + + public static boolean testCascadeSnippet63(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(!a, !b)); + } + + public static boolean testCascadeSnippet64(boolean a, boolean b) { + return shortCircuitOr(!a, !shortCircuitOr(!b, !a)); + } + + @Test + public void testCascade() { + for (int i = 1; i <= 64; ++i) { + String snippet = "testCascadeSnippet" + i; + StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); + PhaseContext context = new PhaseContext(getProviders()); + CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); + canonicalizer.apply(graph, context); + int shortCircuitCount = graph.getNodes(ShortCircuitOrNode.TYPE).count(); + + int trueCount = testInputCombinations(snippet); + + if (trueCount % 2 == 0) { + // No ShortCircuitOrNode expected in the graph. + Assert.assertEquals(0, shortCircuitCount); + } else { + // Only a single ShortCircuitOrNode expected in the graph. + Assert.assertEquals(1, shortCircuitCount); + } + } + } }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/ShortCircuitOrNodeTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File