changeset 51116:f07979db6cb2

8202747: C2: assert(mode == ControlAroundStripMined && use == sfpt) failed: missed a node Reviewed-by: neliasso, kvn
author roland
date Mon, 11 Jun 2018 14:16:43 +0200
parents 9c361050293f
children 6dfe5ae92fa8
files src/hotspot/share/opto/loopopts.cpp test/hotspot/jtreg/compiler/loopstripmining/UnexpectedNodeInOuterLoopWhenCloning.java
diffstat 2 files changed, 99 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/opto/loopopts.cpp	Sun Jun 10 17:26:13 2018 +0200
+++ b/src/hotspot/share/opto/loopopts.cpp	Mon Jun 11 14:16:43 2018 +0200
@@ -1743,6 +1743,23 @@
   }
 }
 
+static void clone_outer_loop_helper(Node* n, const IdealLoopTree *loop, const IdealLoopTree* outer_loop,
+                                    const Node_List &old_new, Unique_Node_List& wq, PhaseIdealLoop* phase,
+                                    bool check_old_new) {
+  for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
+    Node* u = n->fast_out(j);
+    assert(check_old_new || old_new[u->_idx] == NULL, "shouldn't have been cloned");
+    if (!u->is_CFG() && (!check_old_new || old_new[u->_idx] == NULL)) {
+      Node* c = phase->get_ctrl(u);
+      IdealLoopTree* u_loop = phase->get_loop(c);
+      assert(!loop->is_member(u_loop), "can be in outer loop or out of both loops only");
+      if (outer_loop->is_member(u_loop)) {
+        wq.push(u);
+      }
+    }
+  }
+}
+
 void PhaseIdealLoop::clone_outer_loop(LoopNode* head, CloneLoopMode mode, IdealLoopTree *loop,
                                       IdealLoopTree* outer_loop, int dd, Node_List &old_new,
                                       Node_List& extra_data_nodes) {
@@ -1847,6 +1864,22 @@
       _igvn.register_new_node_with_optimizer(new_sfpt);
       _igvn.register_new_node_with_optimizer(new_cle_out);
     }
+    // Some other transformation may have pessimistically assign some
+    // data nodes to the outer loop. Set their control so they are out
+    // of the outer loop.
+    ResourceMark rm;
+    Unique_Node_List wq;
+    for (uint i = 0; i < extra_data_nodes.size(); i++) {
+      Node* old = extra_data_nodes.at(i);
+      clone_outer_loop_helper(old, loop, outer_loop, old_new, wq, this, true);
+    }
+    Node* new_ctrl = cl->outer_loop_exit();
+    assert(get_loop(new_ctrl) != outer_loop, "must be out of the loop nest");
+    for (uint i = 0; i < wq.size(); i++) {
+      Node* n = wq.at(i);
+      set_ctrl(n, new_ctrl);
+      clone_outer_loop_helper(n, loop, outer_loop, old_new, wq, this, false);
+    }
   } else {
     Node *newhead = old_new[loop->_head->_idx];
     set_idom(newhead, newhead->in(LoopNode::EntryControl), dd);
@@ -1947,7 +1980,7 @@
   }
 
   ResourceArea *area = Thread::current()->resource_area();
-  Node_List extra_data_nodes(area);
+  Node_List extra_data_nodes(area); // data nodes in the outer strip mined loop
   clone_outer_loop(head, mode, loop, outer_loop, dd, old_new, extra_data_nodes);
 
   // Step 3: Now fix control uses.  Loop varying control uses have already
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/loopstripmining/UnexpectedNodeInOuterLoopWhenCloning.java	Mon Jun 11 14:16:43 2018 +0200
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2018, 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 8202747
+ * @summary C2: assert(mode == ControlAroundStripMined && use == sfpt) failed: missed a node
+ *
+ * @run main/othervm -Xcomp -Xbatch -XX:CompileOnly=UnexpectedNodeInOuterLoopWhenCloning -XX:-TieredCompilation UnexpectedNodeInOuterLoopWhenCloning
+ *
+ */
+
+public class UnexpectedNodeInOuterLoopWhenCloning {
+
+    public static final int N = 400;
+
+    public static double dFld=0.37026;
+    public static int iArrFld[]=new int[N];
+
+    public static void vMeth() {
+
+        int i5=6, i6=-42538, i7=-209, i8=163, i10=-4, i11=191;
+        boolean b=true;
+        double dArr[]=new double[N];
+
+        for (i5 = 3; i5 < 245; i5++) {
+            i7 = 7;
+            while (--i7 > 0) {
+                iArrFld[i7] = -11995;
+                if (b) continue;
+            }
+            for (i8 = 1; i8 < 7; ++i8) {
+                for (i10 = 1; i10 < 2; i10++) {
+                    dFld -= i6;
+                    i11 += i7;
+                }
+            }
+        }
+    }
+
+    public static void main(String[] strArr) {
+        UnexpectedNodeInOuterLoopWhenCloning _instance = new UnexpectedNodeInOuterLoopWhenCloning();
+        _instance.vMeth();
+    }
+}