8229483: Sinking load out of loop may trigger: assert(found_sfpt) failed: no node in loop that's not input to safepoint
authorroland
Mon, 23 Sep 2019 16:49:09 +0200
changeset 58311 88fce7eea1f6
parent 58310 81134def991d
child 58312 ce960527ecee
child 58329 483f14c3e0a2
8229483: Sinking load out of loop may trigger: assert(found_sfpt) failed: no node in loop that's not input to safepoint Reviewed-by: thartmann, neliasso
src/hotspot/share/opto/loopopts.cpp
test/hotspot/jtreg/compiler/loopstripmining/AntiDependentLoadInOuterStripMinedLoop.java
--- a/src/hotspot/share/opto/loopopts.cpp	Tue Sep 24 20:16:13 2019 -0700
+++ b/src/hotspot/share/opto/loopopts.cpp	Mon Sep 23 16:49:09 2019 +0200
@@ -1443,6 +1443,20 @@
               // Such nodes should only have ProjNodes as outs, e.g. IfNode
               // should only have IfTrueNode and IfFalseNode (4985384).
               x_ctrl = find_non_split_ctrl(x_ctrl);
+
+              IdealLoopTree* x_loop = get_loop(x_ctrl);
+              Node* x_head = x_loop->_head;
+              if (x_head->is_Loop() && (x_head->is_OuterStripMinedLoop() || x_head->as_Loop()->is_strip_mined()) && is_dominator(n_ctrl, x_head)) {
+                // Anti dependence analysis is sometimes too
+                // conservative: a store in the outer strip mined loop
+                // can prevent a load from floating out of the outer
+                // strip mined loop but the load may not be referenced
+                // from the safepoint: loop strip mining verification
+                // code reports a problem in that case. Make sure the
+                // load is not moved in the outer strip mined loop in
+                // that case.
+                x_ctrl = x_head->as_Loop()->skip_strip_mined()->in(LoopNode::EntryControl);
+              }
               assert(dom_depth(n_ctrl) <= dom_depth(x_ctrl), "n is later than its clone");
 
               x->set_req(0, x_ctrl);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/loopstripmining/AntiDependentLoadInOuterStripMinedLoop.java	Mon Sep 23 16:49:09 2019 +0200
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2019, Red Hat, Inc. 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8229483
+ * @summary Sinking load out of loop may trigger: assert(found_sfpt) failed: no node in loop that's not input to safepoint
+ *
+ * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:LoopMaxUnroll=0 AntiDependentLoadInOuterStripMinedLoop
+ *
+ */
+
+public class AntiDependentLoadInOuterStripMinedLoop {
+    private static int field;
+    private static volatile int barrier;
+
+    public static void main(String[] args) {
+        int[] array = new int[1];
+        A a = new A();
+        for (int i = 0; i < 20_000; i++) {
+            test1(array);
+            test2(a, array);
+            test2_helper(array, 0, 0);
+        }
+    }
+
+    private static int test1(int[] array) {
+        int res = 1;
+
+        for (int i = 0; i < 10; i++) {
+            barrier = 1;
+            // field load doesn't float higher than here
+
+            for (int j = 0; j < 2000; j++) {
+                array[0] = j;  // seen as anti dependence by C2 during loop opts, sunk out of loop
+                res *= j;
+            }
+        }
+
+        return field + res + field * 2;
+    }
+
+    private static int test2(A a, int[] array) {
+        int ignore = a.field;
+        int res = 1;
+
+        int k = 0;
+        for (k = 0; k < 2; k++) {
+        }
+
+        for (int i = 0; i < 10; i++) {
+            barrier = 1;
+
+            for (int j = 0; j < 2000; j++) {
+                test2_helper(array, k, j);
+                res *= j;
+            }
+        }
+
+        return a.field + res + a.field * 2;
+    }
+
+    private static void test2_helper(int[] array, int k, int j) {
+        if (k == 2) {
+            array[0] = j;
+        }
+    }
+
+    private static class A {
+        public int field;
+    }
+}