test/hotspot/jtreg/compiler/loopopts/TestOverunrolling.java
changeset 50558 d9936e986e4f
parent 50262 131a631b271a
child 50561 5756e8eecb17
--- a/test/hotspot/jtreg/compiler/loopopts/TestOverunrolling.java	Thu Jun 14 02:01:31 2018 -0400
+++ b/test/hotspot/jtreg/compiler/loopopts/TestOverunrolling.java	Thu Jun 14 09:04:55 2018 +0200
@@ -23,11 +23,12 @@
 
 /*
  * @test
- * @bug 8159016 8202949
+ * @bug 8159016 8202949 8203915
  * @summary Tests correct dominator information after over-unrolling a loop.
  * @requires vm.gc == "Parallel" | vm.gc == "null"
  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions
  *                   -Xcomp -XX:-TieredCompilation -XX:-UseSwitchProfiling
+ *                   -XX:-UseCountedLoopSafepoints -XX:LoopUnrollLimit=250
  *                   -XX:-UseG1GC -XX:+UseParallelGC compiler.loopopts.TestOverunrolling
  */
 
@@ -81,11 +82,74 @@
         }
     }
 
+    // Similar to test2 but we cannot statically determine the upper bound of
+    // the inner for loop and can therefore not prevent over-unrolling.
+    public static void test3(int[] array) {
+        int[] iArr = new int[8];
+        for (int i = 0; i < array.length; i++) {
+            for (int j = 5; j < i; j++) {
+                int k = 1;
+                do {
+                    iArr[j] = 0;
+                    switch (k) {
+                    case 1:
+                        lFld = 0;
+                        break;
+                    case 10:
+                        dFld = 0;
+                        break;
+                    }
+                } while (++k < 1);
+            }
+        }
+    }
+
+    // Similar to test3 but with negative stride and constant outer loop limit
+    public static void test4(int[] array, boolean store) {
+        int[] iArr = new int[8];
+        for (int i = -8; i < 8; i++) {
+            for (int j = 5; j > i; j--) {
+                int k = 1;
+                do {
+                    if (store) {
+                        iArr[j] = 0;
+                    }
+                    switch (k) {
+                    case 1:
+                        lFld = 0;
+                        break;
+                    case 10:
+                        dFld = 0;
+                        break;
+                    }
+                } while (++k < 1);
+            }
+        }
+    }
+
+    // The inner for-loop is over-unrolled and vectorized resulting in
+    // a crash in the matcher because the memory input to a vector is top.
+    public static int test5(int[] array) {
+        int result = 0;
+        int[] iArr = new int[8];
+        for (int i = 0; i < array.length; i++) {
+            for (int j = 5; j < i; j++) {
+                iArr[j] += array[j];
+                result += array[j];
+            }
+        }
+        return result;
+    }
+
     public static void main(String args[]) {
         for (int i = 0; i < 42; ++i) {
             test1(i);
         }
         test2();
+        int[] array = new int[8];
+        test3(array);
+        test4(array, false);
+        test5(array);
     }
 }