--- old/src/hotspot/share/opto/loopopts.cpp 2019-08-27 11:14:30.000000000 +0200 +++ new/src/hotspot/share/opto/loopopts.cpp 2019-08-27 11:14:25.000000000 +0200 @@ -1418,6 +1418,19 @@ // 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); + if (x_loop->_head->is_OuterStripMinedLoop() && is_dominator(n_ctrl, x_loop->_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_loop->_head->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 2019-08-27 11:14:35.000000000 +0200 +++ new/test/hotspot/jtreg/compiler/loopstripmining/AntiDependentLoadInOuterStripMinedLoop.java 2019-08-27 11:14:30.000000000 +0200 @@ -0,0 +1,60 @@ +/* + * 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 int field2; + private static volatile int barrier; + + public static void main(String[] args) { + int[] array = new int[1]; + for (int i = 0; i < 20_000; i++) { + test(array); + } + } + + private static int test(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; + } +}