< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop.test/src/org/graalvm/compiler/loop/test/LoopPartialUnrollTest.java

Print this page
rev 52509 : [mq]: graal2


  66         NodeIterable<LoopBeginNode> loops = graph.getNodes().filter(LoopBeginNode.class);
  67         for (LoopBeginNode loop : loops) {
  68             if (loop.isMainLoop()) {
  69                 return true;
  70             }
  71         }
  72         return false;
  73     }
  74 
  75     public static long sumWithEqualityLimit(int[] text) {
  76         long sum = 0;
  77         for (int i = 0; branchProbability(0.99, i != text.length); ++i) {
  78             sum += volatileInt;
  79         }
  80         return sum;
  81     }
  82 
  83     @Ignore("equality limits aren't working properly")
  84     @Test
  85     public void testSumWithEqualityLimit() {
  86         for (int i = 0; i < 128; i++) {
  87             int[] data = new int[i];
  88             test("sumWithEqualityLimit", data);
  89         }
  90     }
  91 
  92     @Test
  93     public void testLoopCarried() {
  94         for (int i = 0; i < 64; i++) {
  95             test("testLoopCarriedSnippet", i);
  96         }
  97     }
  98 
  99     @Test
 100     public void testLoopCarriedDuplication() {
 101         testDuplicateBody("testLoopCarriedReference", "testLoopCarriedSnippet");
 102     }
 103 
 104     static volatile int volatileInt = 3;
 105 
 106     public int testLoopCarriedSnippet(int iterations) {
 107         int a = 0;
 108         int b = 0;
 109         int c = 0;
 110 
 111         for (int i = 0; branchProbability(0.99, i < iterations); i++) {
 112             int t1 = volatileInt;
 113             int t2 = a + b;
 114             c = b;
 115             b = a;
 116             a = t1 + t2;
 117         }
 118 
 119         return c;
 120     }
 121 
 122     public int testLoopCarriedReference(int iterations) {
 123         int a = 0;
 124         int b = 0;
 125         int c = 0;
 126 
 127         for (int i = 0; branchProbability(0.99, i < iterations); i += 2) {
 128             int t1 = volatileInt;
 129             int t2 = a + b;
 130             c = b;
 131             b = a;
 132             a = t1 + t2;
 133             t1 = volatileInt;
 134             t2 = a + b;
 135             c = b;
 136             b = a;
 137             a = t1 + t2;
 138         }
 139 
 140         return c;
 141     }
 142 































 143     public static long init = Runtime.getRuntime().totalMemory();
 144     private int x;
 145     private int z;
 146 
 147     public int[] testComplexSnippet(int d) {
 148         x = 3;
 149         int y = 5;
 150         z = 7;
 151         for (int i = 0; i < d; i++) {
 152             for (int j = 0; branchProbability(0.99, j < i); j++) {
 153                 z += x;
 154             }
 155             y = x ^ z;
 156             if ((i & 4) == 0) {
 157                 z--;
 158             } else if ((i & 8) == 0) {
 159                 Runtime.getRuntime().totalMemory();
 160             }
 161         }
 162         return new int[]{x, y, z};
 163     }
 164 
 165     @Test
 166     public void testComplex() {
 167         for (int i = 0; i < 10; i++) {
 168             test("testComplexSnippet", i);
 169         }
 170         test("testComplexSnippet", 10);
 171         test("testComplexSnippet", 100);
 172         test("testComplexSnippet", 1000);
 173     }
 174 
 175     public static long testSignExtensionSnippet(long arg) {
 176         long r = 1;
 177         for (int i = 0; branchProbability(0.99, i < arg); i++) {
 178             r *= i;
 179         }
 180         return r;
 181     }
 182 
 183     @Test
 184     public void testSignExtension() {
 185         test("testSignExtensionSnippet", 9L);
 186     }
 187 


 223 
 224             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 225             canonicalizer.apply(graph, context);
 226             new RemoveValueProxyPhase().apply(graph);
 227             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 228             new FloatingReadPhase().apply(graph);
 229             new DeadCodeEliminationPhase().apply(graph);
 230             new ConditionalEliminationPhase(true).apply(graph, context);
 231             ComputeLoopFrequenciesClosure.compute(graph);
 232             new GuardLoweringPhase().apply(graph, context);
 233             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
 234             new FrameStateAssignmentPhase().apply(graph);
 235             new DeoptimizationGroupingPhase().apply(graph, context);
 236             canonicalizer.apply(graph, context);
 237             new ConditionalEliminationPhase(true).apply(graph, context);
 238             if (partialUnroll) {
 239                 LoopsData dataCounted = new LoopsData(graph);
 240                 dataCounted.detectedCountedLoops();
 241                 for (LoopEx loop : dataCounted.countedLoops()) {
 242                     LoopFragmentInside newSegment = loop.inside().duplicate();
 243                     newSegment.insertWithinAfter(loop, false);
 244                 }
 245                 canonicalizer.apply(graph, getDefaultMidTierContext());
 246             }
 247             new DeadCodeEliminationPhase().apply(graph);
 248             canonicalizer.apply(graph, context);
 249             graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "before compare");
 250             return graph;
 251         } catch (Throwable e) {
 252             throw getDebugContext().handle(e);
 253         }
 254     }
 255 
 256     public void testDuplicateBody(String reference, String test) {
 257 
 258         StructuredGraph referenceGraph = buildGraph(reference, false);
 259         StructuredGraph testGraph = buildGraph(test, true);
 260         CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 261         canonicalizer.apply(testGraph, getDefaultMidTierContext());
 262         canonicalizer.apply(referenceGraph, getDefaultMidTierContext());
 263         assertEquals(referenceGraph, testGraph);


  66         NodeIterable<LoopBeginNode> loops = graph.getNodes().filter(LoopBeginNode.class);
  67         for (LoopBeginNode loop : loops) {
  68             if (loop.isMainLoop()) {
  69                 return true;
  70             }
  71         }
  72         return false;
  73     }
  74 
  75     public static long sumWithEqualityLimit(int[] text) {
  76         long sum = 0;
  77         for (int i = 0; branchProbability(0.99, i != text.length); ++i) {
  78             sum += volatileInt;
  79         }
  80         return sum;
  81     }
  82 
  83     @Ignore("equality limits aren't working properly")
  84     @Test
  85     public void testSumWithEqualityLimit() {
  86         for (int i = -1; i < 128; i++) {
  87             int[] data = new int[i];
  88             test("sumWithEqualityLimit", data);
  89         }
  90     }
  91 
  92     @Test
  93     public void testLoopCarried() {
  94         for (int i = -1; i < 64; i++) {
  95             test("testLoopCarriedSnippet", i);
  96         }
  97     }
  98 
  99     @Test
 100     public void testLoopCarriedDuplication() {
 101         testDuplicateBody("testLoopCarriedReference", "testLoopCarriedSnippet");
 102     }
 103 
 104     static volatile int volatileInt = 3;
 105 
 106     public static int testLoopCarriedSnippet(int iterations) {
 107         int a = 0;
 108         int b = 0;
 109         int c = 0;
 110 
 111         for (int i = 0; branchProbability(0.99, i < iterations); i++) {
 112             int t1 = volatileInt;
 113             int t2 = a + b;
 114             c = b;
 115             b = a;
 116             a = t1 + t2;
 117         }
 118 
 119         return c;
 120     }
 121 
 122     public static int testLoopCarriedReference(int iterations) {
 123         int a = 0;
 124         int b = 0;
 125         int c = 0;
 126 
 127         for (int i = 0; branchProbability(0.99, i < iterations); i += 2) {
 128             int t1 = volatileInt;
 129             int t2 = a + b;
 130             c = b;
 131             b = a;
 132             a = t1 + t2;
 133             t1 = volatileInt;
 134             t2 = a + b;
 135             c = b;
 136             b = a;
 137             a = t1 + t2;
 138         }
 139 
 140         return c;
 141     }
 142 
 143     @Test
 144     public void testLoopCarried2() {
 145         for (int i = -1; i < 64; i++) {
 146             for (int j = -1; j < 64; j++) {
 147                 test("testLoopCarried2Snippet", i, j);
 148             }
 149         }
 150         test("testLoopCarried2Snippet", Integer.MAX_VALUE - 32, Integer.MAX_VALUE);
 151         test("testLoopCarried2Snippet", Integer.MAX_VALUE - 4, Integer.MAX_VALUE);
 152         test("testLoopCarried2Snippet", Integer.MAX_VALUE, 0);
 153         test("testLoopCarried2Snippet", Integer.MIN_VALUE, Integer.MIN_VALUE + 32);
 154         test("testLoopCarried2Snippet", Integer.MIN_VALUE, Integer.MIN_VALUE + 4);
 155         test("testLoopCarried2Snippet", 0, Integer.MIN_VALUE);
 156     }
 157 
 158     public static int testLoopCarried2Snippet(int start, int end) {
 159         int a = 0;
 160         int b = 0;
 161         int c = 0;
 162 
 163         for (int i = start; branchProbability(0.99, i < end); i++) {
 164             int t1 = volatileInt;
 165             int t2 = a + b;
 166             c = b;
 167             b = a;
 168             a = t1 + t2;
 169         }
 170 
 171         return c;
 172     }
 173 
 174     public static long init = Runtime.getRuntime().totalMemory();
 175     private int x;
 176     private int z;
 177 
 178     public int[] testComplexSnippet(int d) {
 179         x = 3;
 180         int y = 5;
 181         z = 7;
 182         for (int i = 0; i < d; i++) {
 183             for (int j = 0; branchProbability(0.99, j < i); j++) {
 184                 z += x;
 185             }
 186             y = x ^ z;
 187             if ((i & 4) == 0) {
 188                 z--;
 189             } else if ((i & 8) == 0) {
 190                 Runtime.getRuntime().totalMemory();
 191             }
 192         }
 193         return new int[]{x, y, z};
 194     }
 195 
 196     @Test
 197     public void testComplex() {
 198         for (int i = -1; i < 10; i++) {
 199             test("testComplexSnippet", i);
 200         }
 201         test("testComplexSnippet", 10);
 202         test("testComplexSnippet", 100);
 203         test("testComplexSnippet", 1000);
 204     }
 205 
 206     public static long testSignExtensionSnippet(long arg) {
 207         long r = 1;
 208         for (int i = 0; branchProbability(0.99, i < arg); i++) {
 209             r *= i;
 210         }
 211         return r;
 212     }
 213 
 214     @Test
 215     public void testSignExtension() {
 216         test("testSignExtensionSnippet", 9L);
 217     }
 218 


 254 
 255             CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 256             canonicalizer.apply(graph, context);
 257             new RemoveValueProxyPhase().apply(graph);
 258             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 259             new FloatingReadPhase().apply(graph);
 260             new DeadCodeEliminationPhase().apply(graph);
 261             new ConditionalEliminationPhase(true).apply(graph, context);
 262             ComputeLoopFrequenciesClosure.compute(graph);
 263             new GuardLoweringPhase().apply(graph, context);
 264             new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
 265             new FrameStateAssignmentPhase().apply(graph);
 266             new DeoptimizationGroupingPhase().apply(graph, context);
 267             canonicalizer.apply(graph, context);
 268             new ConditionalEliminationPhase(true).apply(graph, context);
 269             if (partialUnroll) {
 270                 LoopsData dataCounted = new LoopsData(graph);
 271                 dataCounted.detectedCountedLoops();
 272                 for (LoopEx loop : dataCounted.countedLoops()) {
 273                     LoopFragmentInside newSegment = loop.inside().duplicate();
 274                     newSegment.insertWithinAfter(loop, null);
 275                 }
 276                 canonicalizer.apply(graph, getDefaultMidTierContext());
 277             }
 278             new DeadCodeEliminationPhase().apply(graph);
 279             canonicalizer.apply(graph, context);
 280             graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "before compare");
 281             return graph;
 282         } catch (Throwable e) {
 283             throw getDebugContext().handle(e);
 284         }
 285     }
 286 
 287     public void testDuplicateBody(String reference, String test) {
 288 
 289         StructuredGraph referenceGraph = buildGraph(reference, false);
 290         StructuredGraph testGraph = buildGraph(test, true);
 291         CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
 292         canonicalizer.apply(testGraph, getDefaultMidTierContext());
 293         canonicalizer.apply(referenceGraph, getDefaultMidTierContext());
 294         assertEquals(referenceGraph, testGraph);
< prev index next >