# HG changeset patch # User Gilles Duboscq # Date 1346677948 -7200 # Node ID 6f8b6fc03c961fff28b58fae64d5139b307f6cb2 # Parent 1bb742086acdfc8fc02af9649557f716a97a109f Add a maximum number of unswitching per loop Enable Loop unswitching diff -r 1bb742086acd -r 6f8b6fc03c96 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Mon Sep 03 12:52:41 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Mon Sep 03 15:12:28 2012 +0200 @@ -106,10 +106,11 @@ public static boolean LoopPeeling = true; public static boolean ReassociateInvariants = true; public static boolean FullUnroll = true; - public static boolean LoopUnswitch = ____; + public static boolean LoopUnswitch = true; public static int FullUnrollMaxNodes = 150; public static int ExactFullUnrollMaxNodes = 600; public static float MinimumPeelProbability = 0.35f; + public static int LoopMaxUnswitch = 3; public static int LoopUnswitchMaxIncrease = 50; public static int LoopUnswitchUncertaintyBoost = 5; diff -r 1bb742086acd -r 6f8b6fc03c96 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopPolicies.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopPolicies.java Mon Sep 03 12:52:41 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopPolicies.java Mon Sep 03 15:12:28 2012 +0200 @@ -52,9 +52,8 @@ return size * exactTrips <= maxNodes; } - public static boolean shouldTryUnswitch(@SuppressWarnings("unused") LoopEx loop) { - // TODO (gd) maybe there should be a max number of unswitching per loop - return true; + public static boolean shouldTryUnswitch(LoopEx loop) { + return loop.loopBegin().unswitches() <= GraalOptions.LoopMaxUnswitch; } public static boolean shouldUnswitch(LoopEx loop, IfNode ifNode) { diff -r 1bb742086acd -r 6f8b6fc03c96 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopTransformations.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopTransformations.java Mon Sep 03 12:52:41 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/loop/LoopTransformations.java Mon Sep 03 15:12:28 2012 +0200 @@ -94,6 +94,7 @@ public static void unswitch(LoopEx loop, IfNode ifNode) { // duplicate will be true case, original will be false case + loop.loopBegin().incUnswitches(); LoopFragmentWhole originalLoop = loop.whole(); LoopFragmentWhole duplicateLoop = originalLoop.duplicate(); StructuredGraph graph = (StructuredGraph) ifNode.graph(); diff -r 1bb742086acd -r 6f8b6fc03c96 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LoopBeginNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LoopBeginNode.java Mon Sep 03 12:52:41 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LoopBeginNode.java Mon Sep 03 15:12:28 2012 +0200 @@ -34,6 +34,7 @@ public class LoopBeginNode extends MergeNode implements Node.IterableNodeType, LIRLowerable { private double loopFrequency; private int nextEndIndex; + private int unswitches; public LoopBeginNode() { loopFrequency = 1; @@ -144,6 +145,14 @@ return nextEndIndex++; } + public int unswitches() { + return unswitches; + } + + public void incUnswitches() { + unswitches++; + } + @Override public void simplify(SimplifierTool tool) { // nothing yet