src/hotspot/share/opto/loopPredicate.cpp
author thartmann
Tue, 22 Jan 2019 18:25:56 +0100
changeset 53429 1b292ae4eb50
parent 53357 c52a37f40324
child 54423 6c0ab8bd8da5
permissions -rw-r--r--
8217230: assert(t == t_no_spec) failure in NodeHash::check_no_speculative_types() Summary: Remove dead node from C2 IR. Reviewed-by: roland, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     1
/*
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50923
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     4
 *
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     8
 *
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    13
 * accompanied this code).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    14
 *
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    18
 *
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    21
 * questions.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    22
 *
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    23
 */
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    24
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    25
#include "precompiled.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    26
#include "opto/loopnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    27
#include "opto/addnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    28
#include "opto/callnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    29
#include "opto/connode.hpp"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 22234
diff changeset
    30
#include "opto/convertnode.hpp"
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    31
#include "opto/loopnode.hpp"
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
    32
#include "opto/matcher.hpp"
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    33
#include "opto/mulnode.hpp"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 22234
diff changeset
    34
#include "opto/opaquenode.hpp"
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    35
#include "opto/rootnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    36
#include "opto/subnode.hpp"
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
    37
#include <fenv.h>
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
    38
#include <math.h>
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    39
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    40
/*
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    41
 * The general idea of Loop Predication is to insert a predicate on the entry
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    42
 * path to a loop, and raise a uncommon trap if the check of the condition fails.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    43
 * The condition checks are promoted from inside the loop body, and thus
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    44
 * the checks inside the loop could be eliminated. Currently, loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    45
 * optimization has been applied to remove array range check and loop invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    46
 * checks (such as null checks).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    47
*/
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    48
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    49
//-------------------------------register_control-------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    50
void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    51
  assert(n->is_CFG(), "must be control node");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    52
  _igvn.register_new_node_with_optimizer(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    53
  loop->_body.push(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    54
  set_loop(n, loop);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    55
  // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    56
  if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    57
    set_idom(n, pred, dom_depth(pred));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    58
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    59
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    60
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    61
//------------------------------create_new_if_for_predicate------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    62
// create a new if above the uct_if_pattern for the predicate to be promoted.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    63
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    64
//          before                                after
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    65
//        ----------                           ----------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    66
//           ctrl                                 ctrl
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    67
//            |                                     |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    68
//            |                                     |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    69
//            v                                     v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    70
//           iff                                 new_iff
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    71
//          /    \                                /      \
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    72
//         /      \                              /        \
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    73
//        v        v                            v          v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    74
//  uncommon_proj cont_proj                   if_uct     if_cont
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    75
// \      |        |                           |          |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    76
//  \     |        |                           |          |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    77
//   v    v        v                           |          v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    78
//     rgn       loop                          |         iff
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    79
//      |                                      |        /     \
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    80
//      |                                      |       /       \
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    81
//      v                                      |      v         v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    82
// uncommon_trap                               | uncommon_proj cont_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    83
//                                           \  \    |           |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    84
//                                            \  \   |           |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    85
//                                             v  v  v           v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    86
//                                               rgn           loop
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    87
//                                                |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    88
//                                                |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    89
//                                                v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    90
//                                           uncommon_trap
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    91
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    92
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    93
// We will create a region to guard the uct call if there is no one there.
50632
fd430e352427 8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents: 50623
diff changeset
    94
// The true projection (if_cont) of the new_iff is returned.
30309
da3efc8ed2cb 8078426: mb/jvm/compiler/InterfaceCalls/testAC2 - assert(predicate_proj == 0L) failed: only one predicate entry expected
roland
parents: 26166
diff changeset
    95
// This code is also used to clone predicates to cloned loops.
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    96
ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
    97
                                                      Deoptimization::DeoptReason reason,
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
    98
                                                      int opcode) {
21089
e1986ff6fe2e 8024069: replace_in_map() should operate on parent maps
roland
parents: 17383
diff changeset
    99
  assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!");
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   100
  IfNode* iff = cont_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   102
  ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   103
  Node     *rgn   = uncommon_proj->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   104
  assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   105
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   106
  uint proj_index = 1; // region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   107
  if (!rgn->is_Region()) { // create a region to guard the call
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   108
    assert(rgn->is_Call(), "must be call uct");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   109
    CallNode* call = rgn->as_Call();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   110
    IdealLoopTree* loop = get_loop(call);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   111
    rgn = new RegionNode(1);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   112
    rgn->add_req(uncommon_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   113
    register_control(rgn, loop, uncommon_proj);
25913
81dbc151e91c 8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents: 24923
diff changeset
   114
    _igvn.replace_input_of(call, 0, rgn);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   115
    // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   116
    if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   117
      set_idom(call, rgn, dom_depth(rgn));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   118
    }
32733
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   119
    for (DUIterator_Fast imax, i = uncommon_proj->fast_outs(imax); i < imax; i++) {
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   120
      Node* n = uncommon_proj->fast_out(i);
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   121
      if (n->is_Load() || n->is_Store()) {
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   122
        _igvn.replace_input_of(n, 0, rgn);
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   123
        --i; --imax;
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   124
      }
0982a7e7eb15 8134974: 8130847 broken with loop predicates
roland
parents: 31035
diff changeset
   125
    }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   126
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   127
    // Find region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   128
    for (; proj_index < rgn->req(); proj_index++)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   129
      if (rgn->in(proj_index) == uncommon_proj) break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   130
    assert(proj_index < rgn->req(), "sanity");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   131
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   132
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   133
  Node* entry = iff->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   134
  if (new_entry != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   135
    // Clonning the predicate to new location.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   136
    entry = new_entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   137
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   138
  // Create new_iff
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   139
  IdealLoopTree* lp = get_loop(entry);
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   140
  IfNode* new_iff = NULL;
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   141
  if (opcode == Op_If) {
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   142
    new_iff = new IfNode(entry, iff->in(1), iff->_prob, iff->_fcnt);
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   143
  } else {
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   144
    assert(opcode == Op_RangeCheck, "no other if variant here");
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   145
    new_iff = new RangeCheckNode(entry, iff->in(1), iff->_prob, iff->_fcnt);
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   146
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   147
  register_control(new_iff, lp, entry);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   148
  Node *if_cont = new IfTrueNode(new_iff);
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   149
  Node *if_uct  = new IfFalseNode(new_iff);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   150
  if (cont_proj->is_IfFalse()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   151
    // Swap
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   152
    Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   153
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   154
  register_control(if_cont, lp, new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   155
  register_control(if_uct, get_loop(rgn), new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   156
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   157
  // if_uct to rgn
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   158
  _igvn.hash_delete(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   159
  rgn->add_req(if_uct);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   160
  // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   161
  if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   162
    Node* ridom = idom(rgn);
53357
c52a37f40324 8215757: C2: PhaseIdealLoop::create_new_if_for_predicate() computes wrong IDOM
vlivanov
parents: 53306
diff changeset
   163
    Node* nrdom = dom_lca_internal(ridom, new_iff);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   164
    set_idom(rgn, nrdom, dom_depth(rgn));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   165
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   166
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   167
  // If rgn has phis add new edges which has the same
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   168
  // value as on original uncommon_proj pass.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   169
  assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   170
  bool has_phi = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   171
  for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   172
    Node* use = rgn->fast_out(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   173
    if (use->is_Phi() && use->outcnt() > 0) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   174
      assert(use->in(0) == rgn, "");
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10263
diff changeset
   175
      _igvn.rehash_node_delayed(use);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   176
      use->add_req(use->in(proj_index));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   177
      has_phi = true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   178
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   179
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   180
  assert(!has_phi || rgn->req() > 3, "no phis when region is created");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   181
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   182
  if (new_entry == NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   183
    // Attach if_cont to iff
25913
81dbc151e91c 8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents: 24923
diff changeset
   184
    _igvn.replace_input_of(iff, 0, if_cont);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   185
    if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   186
      set_idom(iff, if_cont, dom_depth(iff));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   187
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   188
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   189
  return if_cont->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   190
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   191
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   192
//------------------------------create_new_if_for_predicate------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   193
// Create a new if below new_entry for the predicate to be cloned (IGVN optimization)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   194
ProjNode* PhaseIterGVN::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   195
                                                    Deoptimization::DeoptReason reason,
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   196
                                                    int opcode) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   197
  assert(new_entry != 0, "only used for clone predicate");
21089
e1986ff6fe2e 8024069: replace_in_map() should operate on parent maps
roland
parents: 17383
diff changeset
   198
  assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!");
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   199
  IfNode* iff = cont_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   200
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   201
  ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   202
  Node     *rgn   = uncommon_proj->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   203
  assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   204
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   205
  uint proj_index = 1; // region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   206
  if (!rgn->is_Region()) { // create a region to guard the call
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   207
    assert(rgn->is_Call(), "must be call uct");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   208
    CallNode* call = rgn->as_Call();
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   209
    rgn = new RegionNode(1);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   210
    register_new_node_with_optimizer(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   211
    rgn->add_req(uncommon_proj);
25913
81dbc151e91c 8040213: C2 does not put all modified nodes on IGVN worklist
thartmann
parents: 24923
diff changeset
   212
    replace_input_of(call, 0, rgn);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   213
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   214
    // Find region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   215
    for (; proj_index < rgn->req(); proj_index++)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   216
      if (rgn->in(proj_index) == uncommon_proj) break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   217
    assert(proj_index < rgn->req(), "sanity");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   218
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   219
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   220
  // Create new_iff in new location.
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   221
  IfNode* new_iff = NULL;
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   222
  if (opcode == Op_If) {
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   223
    new_iff = new IfNode(new_entry, iff->in(1), iff->_prob, iff->_fcnt);
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   224
  } else {
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   225
    assert(opcode == Op_RangeCheck, "no other if variant here");
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   226
    new_iff = new RangeCheckNode(new_entry, iff->in(1), iff->_prob, iff->_fcnt);
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   227
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   228
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   229
  register_new_node_with_optimizer(new_iff);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   230
  Node *if_cont = new IfTrueNode(new_iff);
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   231
  Node *if_uct  = new IfFalseNode(new_iff);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   232
  if (cont_proj->is_IfFalse()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   233
    // Swap
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   234
    Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   235
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   236
  register_new_node_with_optimizer(if_cont);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   237
  register_new_node_with_optimizer(if_uct);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   238
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   239
  // if_uct to rgn
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   240
  hash_delete(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   241
  rgn->add_req(if_uct);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   242
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   243
  // If rgn has phis add corresponding new edges which has the same
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   244
  // value as on original uncommon_proj pass.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   245
  assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   246
  bool has_phi = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   247
  for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   248
    Node* use = rgn->fast_out(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   249
    if (use->is_Phi() && use->outcnt() > 0) {
12958
009b6c9586d8 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 10263
diff changeset
   250
      rehash_node_delayed(use);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   251
      use->add_req(use->in(proj_index));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   252
      has_phi = true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   253
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   254
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   255
  assert(!has_phi || rgn->req() > 3, "no phis when region is created");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   256
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   257
  return if_cont->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   258
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   259
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   260
//--------------------------clone_predicate-----------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   261
ProjNode* PhaseIdealLoop::clone_predicate(ProjNode* predicate_proj, Node* new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   262
                                          Deoptimization::DeoptReason reason,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   263
                                          PhaseIdealLoop* loop_phase,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   264
                                          PhaseIterGVN* igvn) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   265
  ProjNode* new_predicate_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   266
  if (loop_phase != NULL) {
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   267
    new_predicate_proj = loop_phase->create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   268
  } else {
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
   269
    new_predicate_proj =       igvn->create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   270
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   271
  IfNode* iff = new_predicate_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   272
  Node* ctrl  = iff->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   273
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   274
  // Match original condition since predicate's projections could be swapped.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   275
  assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   276
  Node* opq = new Opaque1Node(igvn->C, predicate_proj->in(0)->in(1)->in(1)->in(1));
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   277
  igvn->C->add_predicate_opaq(opq);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   278
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   279
  Node* bol = new Conv2BNode(opq);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   280
  if (loop_phase != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   281
    loop_phase->register_new_node(opq, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   282
    loop_phase->register_new_node(bol, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   283
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   284
    igvn->register_new_node_with_optimizer(opq);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   285
    igvn->register_new_node_with_optimizer(bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   286
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   287
  igvn->hash_delete(iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   288
  iff->set_req(1, bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   289
  return new_predicate_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   290
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   291
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   292
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   293
//--------------------------clone_loop_predicates-----------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   294
// Interface from IGVN
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   295
Node* PhaseIterGVN::clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check) {
10258
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   296
  return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, clone_limit_check, NULL, this);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   297
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   298
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   299
// Interface from PhaseIdealLoop
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   300
Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check) {
10258
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   301
  return clone_loop_predicates(old_entry, new_entry, clone_limit_check, this, &this->_igvn);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   302
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   303
52414
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   304
void PhaseIdealLoop::clone_loop_predicates_fix_mem(ProjNode* dom_proj , ProjNode* proj,
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   305
                                                   PhaseIdealLoop* loop_phase,
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   306
                                                   PhaseIterGVN* igvn) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   307
  Compile* C = NULL;
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   308
  if (loop_phase != NULL) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   309
    igvn = &loop_phase->igvn();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   310
  }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   311
  C = igvn->C;
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   312
  ProjNode* other_dom_proj = dom_proj->in(0)->as_Multi()->proj_out(1-dom_proj->_con);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   313
  Node* dom_r = other_dom_proj->unique_ctrl_out();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   314
  if (dom_r->is_Region()) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   315
    assert(dom_r->unique_ctrl_out()->is_Call(), "unc expected");
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   316
    ProjNode* other_proj = proj->in(0)->as_Multi()->proj_out(1-proj->_con);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   317
    Node* r = other_proj->unique_ctrl_out();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   318
    assert(r->is_Region() && r->unique_ctrl_out()->is_Call(), "cloned predicate should have caused region to be added");
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   319
    for (DUIterator_Fast imax, i = dom_r->fast_outs(imax); i < imax; i++) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   320
      Node* dom_use = dom_r->fast_out(i);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   321
      if (dom_use->is_Phi() && dom_use->bottom_type() == Type::MEMORY) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   322
        assert(dom_use->in(0) == dom_r, "");
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   323
        Node* phi = NULL;
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   324
        for (DUIterator_Fast jmax, j = r->fast_outs(jmax); j < jmax; j++) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   325
          Node* use = r->fast_out(j);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   326
          if (use->is_Phi() && use->bottom_type() == Type::MEMORY &&
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   327
              use->adr_type() == dom_use->adr_type()) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   328
            assert(use->in(0) == r, "");
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   329
            assert(phi == NULL, "only one phi");
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   330
            phi = use;
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   331
          }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   332
        }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   333
        if (phi == NULL) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   334
          const TypePtr* adr_type = dom_use->adr_type();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   335
          int alias = C->get_alias_index(adr_type);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   336
          Node* call = r->unique_ctrl_out();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   337
          Node* mem = call->in(TypeFunc::Memory);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   338
          MergeMemNode* mm = NULL;
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   339
          if (mem->is_MergeMem()) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   340
            mm = mem->clone()->as_MergeMem();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   341
            if (adr_type == TypePtr::BOTTOM) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   342
              mem = mem->as_MergeMem()->base_memory();
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   343
            } else {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   344
              mem = mem->as_MergeMem()->memory_at(alias);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   345
            }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   346
          } else {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   347
            mm = MergeMemNode::make(mem);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   348
          }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   349
          phi = PhiNode::make(r, mem, Type::MEMORY, adr_type);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   350
          if (adr_type == TypePtr::BOTTOM) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   351
            mm->set_base_memory(phi);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   352
          } else {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   353
            mm->set_memory_at(alias, phi);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   354
          }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   355
          if (loop_phase != NULL) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   356
            loop_phase->register_new_node(mm, r);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   357
            loop_phase->register_new_node(phi, r);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   358
          } else {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   359
            igvn->register_new_node_with_optimizer(mm);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   360
            igvn->register_new_node_with_optimizer(phi);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   361
          }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   362
          igvn->replace_input_of(call, TypeFunc::Memory, mm);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   363
        }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   364
        igvn->replace_input_of(phi, r->find_edge(other_proj), dom_use->in(dom_r->find_edge(other_dom_proj)));
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   365
      }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   366
    }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   367
  }
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   368
}
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   369
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   370
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   371
// Clone loop predicates to cloned loops (peeled, unswitched, split_if).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   372
Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry,
52608
61241fc2217a 8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents: 52490
diff changeset
   373
                                            bool clone_limit_check,
61241fc2217a 8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents: 52490
diff changeset
   374
                                            PhaseIdealLoop* loop_phase,
61241fc2217a 8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents: 52490
diff changeset
   375
                                            PhaseIterGVN* igvn) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   376
#ifdef ASSERT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   377
  if (new_entry == NULL || !(new_entry->is_Proj() || new_entry->is_Region() || new_entry->is_SafePoint())) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   378
    if (new_entry != NULL)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   379
      new_entry->dump();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   380
    assert(false, "not IfTrue, IfFalse, Region or SafePoint");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   381
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   382
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   383
  // Search original predicates
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   384
  Node* entry = old_entry;
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   385
  ProjNode* limit_check_proj = NULL;
37287
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   386
  limit_check_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   387
  if (limit_check_proj != NULL) {
52608
61241fc2217a 8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents: 52490
diff changeset
   388
    entry = skip_loop_predicates(entry);
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   389
  }
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   390
  ProjNode* profile_predicate_proj = NULL;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   391
  ProjNode* predicate_proj = NULL;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   392
  if (UseProfiledLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   393
    profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   394
    if (profile_predicate_proj != NULL) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   395
      entry = skip_loop_predicates(entry);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   396
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   397
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   398
  if (UseLoopPredicate) {
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   399
    predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   400
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   401
  if (predicate_proj != NULL) { // right pattern that can be used by loop predication
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   402
    // clone predicate
52414
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   403
    ProjNode* proj = clone_predicate(predicate_proj, new_entry,
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   404
                                     Deoptimization::Reason_predicate,
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   405
                                     loop_phase, igvn);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   406
    assert(proj != NULL, "IfTrue or IfFalse after clone predicate");
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   407
    new_entry = proj;
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   408
    if (TraceLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   409
      tty->print("Loop Predicate cloned: ");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   410
      debug_only( new_entry->in(0)->dump(); );
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   411
    }
52414
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   412
    if (profile_predicate_proj != NULL) {
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   413
      // A node that produces memory may be out of loop and depend on
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   414
      // a profiled predicates. In that case the memory state at the
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   415
      // end of profiled predicates and at the end of predicates are
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   416
      // not the same. The cloned predicates are dominated by the
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   417
      // profiled predicates but may have the wrong memory
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   418
      // state. Update it.
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   419
      clone_loop_predicates_fix_mem(profile_predicate_proj, proj, loop_phase, igvn);
6d42c07ba238 8212610: Fix handling of memory in PhaseIdealLoop::clone_loop_predicates()
roland
parents: 51333
diff changeset
   420
    }
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   421
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   422
  if (profile_predicate_proj != NULL) { // right pattern that can be used by loop predication
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   423
    // clone predicate
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   424
    new_entry = clone_predicate(profile_predicate_proj, new_entry,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   425
                                Deoptimization::Reason_profile_predicate,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   426
                                loop_phase, igvn);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   427
    assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone predicate");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   428
    if (TraceLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   429
      tty->print("Loop Predicate cloned: ");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   430
      debug_only( new_entry->in(0)->dump(); );
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   431
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   432
  }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   433
  if (limit_check_proj != NULL && clone_limit_check) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   434
    // Clone loop limit check last to insert it before loop.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   435
    // Don't clone a limit check which was already finalized
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   436
    // for this counted loop (only one limit check is needed).
10258
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   437
    new_entry = clone_predicate(limit_check_proj, new_entry,
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   438
                                Deoptimization::Reason_loop_limit_check,
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   439
                                loop_phase, igvn);
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   440
    assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone limit check");
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   441
    if (TraceLoopLimitCheck) {
10258
10c77b8c8d3e 7068051: SIGSEGV in PhaseIdealLoop::build_loop_late_post
kvn
parents: 10253
diff changeset
   442
      tty->print("Loop Limit Check cloned: ");
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   443
      debug_only( new_entry->in(0)->dump(); )
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   444
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   445
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   446
  return new_entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   447
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   448
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   449
//--------------------------skip_loop_predicates------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   450
// Skip related predicates.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   451
Node* PhaseIdealLoop::skip_loop_predicates(Node* entry) {
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   452
  IfNode* iff = entry->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   453
  ProjNode* uncommon_proj = iff->proj_out(1 - entry->as_Proj()->_con);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   454
  Node* rgn = uncommon_proj->unique_ctrl_out();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   455
  assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   456
  entry = entry->in(0)->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   457
  while (entry != NULL && entry->is_Proj() && entry->in(0)->is_If()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   458
    uncommon_proj = entry->in(0)->as_If()->proj_out(1 - entry->as_Proj()->_con);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   459
    if (uncommon_proj->unique_ctrl_out() != rgn)
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   460
      break;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   461
    entry = entry->in(0)->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   462
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   463
  return entry;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   464
}
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   465
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   466
Node* PhaseIdealLoop::skip_all_loop_predicates(Node* entry) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   467
  Node* predicate = NULL;
37287
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   468
  predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   469
  if (predicate != NULL) {
52608
61241fc2217a 8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents: 52490
diff changeset
   470
    entry = skip_loop_predicates(entry);
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   471
  }
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   472
  if (UseProfiledLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   473
    predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   474
    if (predicate != NULL) { // right pattern that can be used by loop predication
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   475
      entry = skip_loop_predicates(entry);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   476
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   477
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   478
  if (UseLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   479
    predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   480
    if (predicate != NULL) { // right pattern that can be used by loop predication
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   481
      entry = skip_loop_predicates(entry);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   482
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   483
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   484
  return entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   485
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   486
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   487
//--------------------------find_predicate_insertion_point-------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   488
// Find a good location to insert a predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   489
ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   490
  if (start_c == NULL || !start_c->is_Proj())
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   491
    return NULL;
21089
e1986ff6fe2e 8024069: replace_in_map() should operate on parent maps
roland
parents: 17383
diff changeset
   492
  if (start_c->as_Proj()->is_uncommon_trap_if_pattern(reason)) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   493
    return start_c->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   494
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   495
  return NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   496
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   497
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   498
//--------------------------find_predicate------------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   499
// Find a predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   500
Node* PhaseIdealLoop::find_predicate(Node* entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   501
  Node* predicate = NULL;
37287
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   502
  predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   503
  if (predicate != NULL) { // right pattern that can be used by loop predication
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   504
    return entry;
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   505
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   506
  if (UseLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   507
    predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   508
    if (predicate != NULL) { // right pattern that can be used by loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   509
      return entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   510
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   511
  }
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   512
  if (UseProfiledLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   513
    predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   514
    if (predicate != NULL) { // right pattern that can be used by loop predication
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   515
      return entry;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   516
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   517
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   518
  return NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   519
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   520
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   521
//------------------------------Invariance-----------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   522
// Helper class for loop_predication_impl to compute invariance on the fly and
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   523
// clone invariants.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   524
class Invariance : public StackObj {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   525
  VectorSet _visited, _invariant;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   526
  Node_Stack _stack;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   527
  VectorSet _clone_visited;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   528
  Node_List _old_new; // map of old to new (clone)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   529
  IdealLoopTree* _lpt;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   530
  PhaseIdealLoop* _phase;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   531
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   532
  // Helper function to set up the invariance for invariance computation
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   533
  // If n is a known invariant, set up directly. Otherwise, look up the
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   534
  // the possibility to push n onto the stack for further processing.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   535
  void visit(Node* use, Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   536
    if (_lpt->is_invariant(n)) { // known invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   537
      _invariant.set(n->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   538
    } else if (!n->is_CFG()) {
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 52608
diff changeset
   539
      if (n->Opcode() == Op_ShenandoahWriteBarrier) {
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 52608
diff changeset
   540
        return;
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 52608
diff changeset
   541
      }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   542
      Node *n_ctrl = _phase->ctrl_or_self(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   543
      Node *u_ctrl = _phase->ctrl_or_self(use); // self if use is a CFG
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   544
      if (_phase->is_dominator(n_ctrl, u_ctrl)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   545
        _stack.push(n, n->in(0) == NULL ? 1 : 0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   546
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   547
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   548
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   549
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   550
  // Compute invariance for "the_node" and (possibly) all its inputs recursively
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   551
  // on the fly
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   552
  void compute_invariance(Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   553
    assert(_visited.test(n->_idx), "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   554
    visit(n, n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   555
    while (_stack.is_nonempty()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   556
      Node*  n = _stack.node();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   557
      uint idx = _stack.index();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   558
      if (idx == n->req()) { // all inputs are processed
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   559
        _stack.pop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   560
        // n is invariant if it's inputs are all invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   561
        bool all_inputs_invariant = true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   562
        for (uint i = 0; i < n->req(); i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   563
          Node* in = n->in(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   564
          if (in == NULL) continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   565
          assert(_visited.test(in->_idx), "must have visited input");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   566
          if (!_invariant.test(in->_idx)) { // bad guy
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   567
            all_inputs_invariant = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   568
            break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   569
          }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   570
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   571
        if (all_inputs_invariant) {
31035
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   572
          // If n's control is a predicate that was moved out of the
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   573
          // loop, it was marked invariant but n is only invariant if
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   574
          // it depends only on that test. Otherwise, unless that test
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   575
          // is out of the loop, it's not invariant.
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   576
          if (n->is_CFG() || n->depends_only_on_test() || n->in(0) == NULL || !_phase->is_member(_lpt, n->in(0))) {
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   577
            _invariant.set(n->_idx); // I am a invariant too
0f0743952c41 8077504: Unsafe load can loose control dependency and cause crash
roland
parents: 30309
diff changeset
   578
          }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   579
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   580
      } else { // process next input
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   581
        _stack.set_index(idx + 1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   582
        Node* m = n->in(idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   583
        if (m != NULL && !_visited.test_set(m->_idx)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   584
          visit(n, m);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   585
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   586
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   587
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   588
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   589
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   590
  // Helper function to set up _old_new map for clone_nodes.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   591
  // If n is a known invariant, set up directly ("clone" of n == n).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   592
  // Otherwise, push n onto the stack for real cloning.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   593
  void clone_visit(Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   594
    assert(_invariant.test(n->_idx), "must be invariant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   595
    if (_lpt->is_invariant(n)) { // known invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   596
      _old_new.map(n->_idx, n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   597
    } else { // to be cloned
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   598
      assert(!n->is_CFG(), "should not see CFG here");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   599
      _stack.push(n, n->in(0) == NULL ? 1 : 0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   600
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   601
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   602
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   603
  // Clone "n" and (possibly) all its inputs recursively
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   604
  void clone_nodes(Node* n, Node* ctrl) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   605
    clone_visit(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   606
    while (_stack.is_nonempty()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   607
      Node*  n = _stack.node();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   608
      uint idx = _stack.index();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   609
      if (idx == n->req()) { // all inputs processed, clone n!
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   610
        _stack.pop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   611
        // clone invariant node
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   612
        Node* n_cl = n->clone();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   613
        _old_new.map(n->_idx, n_cl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   614
        _phase->register_new_node(n_cl, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   615
        for (uint i = 0; i < n->req(); i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   616
          Node* in = n_cl->in(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   617
          if (in == NULL) continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   618
          n_cl->set_req(i, _old_new[in->_idx]);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   619
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   620
      } else { // process next input
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   621
        _stack.set_index(idx + 1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   622
        Node* m = n->in(idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   623
        if (m != NULL && !_clone_visited.test_set(m->_idx)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   624
          clone_visit(m); // visit the input
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   625
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   626
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   627
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   628
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   629
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   630
 public:
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   631
  Invariance(Arena* area, IdealLoopTree* lpt) :
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   632
    _visited(area), _invariant(area),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   633
    _stack(area, 10 /* guess */),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   634
    _clone_visited(area), _old_new(area),
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51078
diff changeset
   635
    _lpt(lpt), _phase(lpt->_phase)
35558
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   636
  {
48145
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
   637
    LoopNode* head = _lpt->_head->as_Loop();
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
   638
    Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
35558
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   639
    if (entry->outcnt() != 1) {
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   640
      // If a node is pinned between the predicates and the loop
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   641
      // entry, we won't be able to move any node in the loop that
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   642
      // depends on it above it in a predicate. Mark all those nodes
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   643
      // as non loop invariatnt.
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   644
      Unique_Node_List wq;
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   645
      wq.push(entry);
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   646
      for (uint next = 0; next < wq.size(); ++next) {
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   647
        Node *n = wq.at(next);
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   648
        for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   649
          Node* u = n->fast_out(i);
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   650
          if (!u->is_CFG()) {
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   651
            Node* c = _phase->get_ctrl(u);
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   652
            if (_lpt->is_member(_phase->get_loop(c)) || _phase->is_dominator(c, head)) {
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   653
              _visited.set(u->_idx);
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   654
              wq.push(u);
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   655
            }
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   656
          }
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   657
        }
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   658
      }
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   659
    }
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   660
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   661
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   662
  // Map old to n for invariance computation and clone
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   663
  void map_ctrl(Node* old, Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   664
    assert(old->is_CFG() && n->is_CFG(), "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   665
    _old_new.map(old->_idx, n); // "clone" of old is n
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   666
    _invariant.set(old->_idx);  // old is invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   667
    _clone_visited.set(old->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   668
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   669
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   670
  // Driver function to compute invariance
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   671
  bool is_invariant(Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   672
    if (!_visited.test_set(n->_idx))
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   673
      compute_invariance(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   674
    return (_invariant.test(n->_idx) != 0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   675
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   676
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   677
  // Driver function to clone invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   678
  Node* clone(Node* n, Node* ctrl) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   679
    assert(ctrl->is_CFG(), "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   680
    assert(_invariant.test(n->_idx), "must be an invariant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   681
    if (!_clone_visited.test(n->_idx))
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   682
      clone_nodes(n, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   683
    return _old_new[n->_idx];
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   684
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   685
};
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   686
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   687
//------------------------------is_range_check_if -----------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   688
// Returns true if the predicate of iff is in "scale*iv + offset u< load_range(ptr)" format
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   689
// Note: this function is particularly designed for loop predication. We require load_range
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   690
//       and offset to be loop invariant computed on the fly by "invar"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   691
bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   692
  if (!is_loop_exit(iff)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   693
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   694
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   695
  if (!iff->in(1)->is_Bool()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   696
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   697
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   698
  const BoolNode *bol = iff->in(1)->as_Bool();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   699
  if (bol->_test._test != BoolTest::lt) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   700
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   701
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   702
  if (!bol->in(1)->is_Cmp()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   703
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   704
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   705
  const CmpNode *cmp = bol->in(1)->as_Cmp();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   706
  if (cmp->Opcode() != Op_CmpU) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   707
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   708
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   709
  Node* range = cmp->in(2);
34180
f0ec91019db2 8042997: Make intrinsic some or all check index/range methods
roland
parents: 34164
diff changeset
   710
  if (range->Opcode() != Op_LoadRange && !iff->is_RangeCheck()) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   711
    const TypeInt* tint = phase->_igvn.type(range)->isa_int();
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   712
    if (tint == NULL || tint->empty() || tint->_lo < 0) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   713
      // Allow predication on positive values that aren't LoadRanges.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   714
      // This allows optimization of loops where the length of the
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   715
      // array is a known value and doesn't need to be loaded back
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   716
      // from the array.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   717
      return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   718
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   719
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   720
  if (!invar.is_invariant(range)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   721
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   722
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   723
  Node *iv     = _head->as_CountedLoop()->phi();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   724
  int   scale  = 0;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   725
  Node *offset = NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   726
  if (!phase->is_scaled_iv_plus_offset(cmp->in(1), iv, &scale, &offset)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   727
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   728
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   729
  if (offset && !invar.is_invariant(offset)) { // offset must be invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   730
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   731
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   732
  return true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   733
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   734
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   735
//------------------------------rc_predicate-----------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   736
// Create a range check predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   737
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   738
// for (i = init; i < limit; i += stride) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   739
//    a[scale*i+offset]
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   740
// }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   741
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   742
// Compute max(scale*i + offset) for init <= i < limit and build the predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   743
// as "max(scale*i + offset) u< a.length".
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   744
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   745
// There are two cases for max(scale*i + offset):
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   746
// (1) stride*scale > 0
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   747
//   max(scale*i + offset) = scale*(limit-stride) + offset
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   748
// (2) stride*scale < 0
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   749
//   max(scale*i + offset) = scale*init + offset
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
   750
BoolNode* PhaseIdealLoop::rc_predicate(IdealLoopTree *loop, Node* ctrl,
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   751
                                       int scale, Node* offset,
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   752
                                       Node* init, Node* limit, jint stride,
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   753
                                       Node* range, bool upper, bool &overflow) {
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
   754
  jint con_limit  = (limit != NULL && limit->is_Con())  ? limit->get_int()  : 0;
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   755
  jint con_init   = init->is_Con()   ? init->get_int()   : 0;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   756
  jint con_offset = offset->is_Con() ? offset->get_int() : 0;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   757
9437
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   758
  stringStream* predString = NULL;
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   759
  if (TraceLoopPredicate) {
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   760
    predString = new stringStream();
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   761
    predString->print("rc_predicate ");
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   762
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   763
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   764
  overflow = false;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   765
  Node* max_idx_expr = NULL;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   766
  const TypeInt* idx_type = TypeInt::INT;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   767
  if ((stride > 0) == (scale > 0) == upper) {
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50923
diff changeset
   768
    guarantee(limit != NULL, "sanity");
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   769
    if (TraceLoopPredicate) {
46735
kvn
parents: 46630 45965
diff changeset
   770
      if (limit->is_Con()) {
kvn
parents: 46630 45965
diff changeset
   771
        predString->print("(%d ", con_limit);
kvn
parents: 46630 45965
diff changeset
   772
      } else {
kvn
parents: 46630 45965
diff changeset
   773
        predString->print("(limit ");
kvn
parents: 46630 45965
diff changeset
   774
      }
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   775
      predString->print("- %d) ", stride);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   776
    }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   777
    // Check if (limit - stride) may overflow
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   778
    const TypeInt* limit_type = _igvn.type(limit)->isa_int();
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   779
    jint limit_lo = limit_type->_lo;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   780
    jint limit_hi = limit_type->_hi;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   781
    if ((stride > 0 && (java_subtract(limit_lo, stride) < limit_lo)) ||
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   782
        (stride < 0 && (java_subtract(limit_hi, stride) > limit_hi))) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   783
      // No overflow possible
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   784
      ConINode* con_stride = _igvn.intcon(stride);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   785
      set_ctrl(con_stride, C->root());
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   786
      max_idx_expr = new SubINode(limit, con_stride);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   787
      idx_type = TypeInt::make(limit_lo - stride, limit_hi - stride, limit_type->_widen);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   788
    } else {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   789
      // May overflow
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   790
      overflow = true;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   791
      limit = new ConvI2LNode(limit);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   792
      register_new_node(limit, ctrl);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   793
      ConLNode* con_stride = _igvn.longcon(stride);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   794
      set_ctrl(con_stride, C->root());
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   795
      max_idx_expr = new SubLNode(limit, con_stride);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   796
    }
37287
c2660335bf81 8072422: Cleanup: Remove some unused flags/code in loop optimizations
zmajo
parents: 35558
diff changeset
   797
    register_new_node(max_idx_expr, ctrl);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   798
  } else {
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   799
    if (TraceLoopPredicate) {
46735
kvn
parents: 46630 45965
diff changeset
   800
      if (init->is_Con()) {
kvn
parents: 46630 45965
diff changeset
   801
        predString->print("%d ", con_init);
kvn
parents: 46630 45965
diff changeset
   802
      } else {
kvn
parents: 46630 45965
diff changeset
   803
        predString->print("init ");
kvn
parents: 46630 45965
diff changeset
   804
      }
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   805
    }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   806
    idx_type = _igvn.type(init)->isa_int();
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   807
    max_idx_expr = init;
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   808
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   809
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   810
  if (scale != 1) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   811
    ConNode* con_scale = _igvn.intcon(scale);
35558
9b3b2740c3ec 8146792: Predicate moved after partial peel may lead to broken graph
roland
parents: 34180
diff changeset
   812
    set_ctrl(con_scale, C->root());
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   813
    if (TraceLoopPredicate) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   814
      predString->print("* %d ", scale);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   815
    }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   816
    // Check if (scale * max_idx_expr) may overflow
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   817
    const TypeInt* scale_type = TypeInt::make(scale);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   818
    MulINode* mul = new MulINode(max_idx_expr, con_scale);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   819
    idx_type = (TypeInt*)mul->mul_ring(idx_type, scale_type);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   820
    if (overflow || TypeInt::INT->higher_equal(idx_type)) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   821
      // May overflow
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   822
      mul->destruct();
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   823
      if (!overflow) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   824
        max_idx_expr = new ConvI2LNode(max_idx_expr);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   825
        register_new_node(max_idx_expr, ctrl);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   826
      }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   827
      overflow = true;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   828
      con_scale = _igvn.longcon(scale);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   829
      set_ctrl(con_scale, C->root());
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   830
      max_idx_expr = new MulLNode(max_idx_expr, con_scale);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   831
    } else {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   832
      // No overflow possible
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   833
      max_idx_expr = mul;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   834
    }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   835
    register_new_node(max_idx_expr, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   836
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   837
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   838
  if (offset && (!offset->is_Con() || con_offset != 0)){
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   839
    if (TraceLoopPredicate) {
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 37287
diff changeset
   840
      if (offset->is_Con()) {
46735
kvn
parents: 46630 45965
diff changeset
   841
        predString->print("+ %d ", con_offset);
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 37287
diff changeset
   842
      } else {
46735
kvn
parents: 46630 45965
diff changeset
   843
        predString->print("+ offset");
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 37287
diff changeset
   844
      }
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   845
    }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   846
    // Check if (max_idx_expr + offset) may overflow
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   847
    const TypeInt* offset_type = _igvn.type(offset)->isa_int();
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   848
    jint lo = java_add(idx_type->_lo, offset_type->_lo);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   849
    jint hi = java_add(idx_type->_hi, offset_type->_hi);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   850
    if (overflow || (lo > hi) ||
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   851
        ((idx_type->_lo & offset_type->_lo) < 0 && lo >= 0) ||
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   852
        ((~(idx_type->_hi | offset_type->_hi)) < 0 && hi < 0)) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   853
      // May overflow
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   854
      if (!overflow) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   855
        max_idx_expr = new ConvI2LNode(max_idx_expr);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   856
        register_new_node(max_idx_expr, ctrl);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   857
      }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   858
      overflow = true;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   859
      offset = new ConvI2LNode(offset);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   860
      register_new_node(offset, ctrl);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   861
      max_idx_expr = new AddLNode(max_idx_expr, offset);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   862
    } else {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   863
      // No overflow possible
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   864
      max_idx_expr = new AddINode(max_idx_expr, offset);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   865
    }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   866
    register_new_node(max_idx_expr, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   867
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   868
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   869
  CmpNode* cmp = NULL;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   870
  if (overflow) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   871
    // Integer expressions may overflow, do long comparison
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   872
    range = new ConvI2LNode(range);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   873
    register_new_node(range, ctrl);
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
   874
    cmp = new CmpULNode(max_idx_expr, range);
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   875
  } else {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   876
    cmp = new CmpUNode(max_idx_expr, range);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 37287
diff changeset
   877
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   878
  register_new_node(cmp, ctrl);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24424
diff changeset
   879
  BoolNode* bol = new BoolNode(cmp, BoolTest::lt);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   880
  register_new_node(bol, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   881
9437
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   882
  if (TraceLoopPredicate) {
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   883
    predString->print_cr("<u range");
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23528
diff changeset
   884
    tty->print("%s", predString->as_string());
9437
9981851b4b8c 7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents: 9101
diff changeset
   885
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   886
  return bol;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   887
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   888
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   889
// Should loop predication look not only in the path from tail to head
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   890
// but also in branches of the loop body?
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   891
bool PhaseIdealLoop::loop_predication_should_follow_branches(IdealLoopTree *loop, ProjNode *predicate_proj, float& loop_trip_cnt) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   892
  if (!UseProfiledLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   893
    return false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   894
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   895
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   896
  if (predicate_proj == NULL) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   897
    return false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   898
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   899
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   900
  LoopNode* head = loop->_head->as_Loop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   901
  bool follow_branches = true;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   902
  IdealLoopTree* l = loop->_child;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   903
  // For leaf loops and loops with a single inner loop
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   904
  while (l != NULL && follow_branches) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   905
    IdealLoopTree* child = l;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   906
    if (child->_child != NULL &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   907
        child->_head->is_OuterStripMinedLoop()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   908
      assert(child->_child->_next == NULL, "only one inner loop for strip mined loop");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   909
      assert(child->_child->_head->is_CountedLoop() && child->_child->_head->as_CountedLoop()->is_strip_mined(), "inner loop should be strip mined");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   910
      child = child->_child;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   911
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   912
    if (child->_child != NULL || child->_irreducible) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   913
      follow_branches = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   914
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   915
    l = l->_next;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   916
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   917
  if (follow_branches) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   918
    loop->compute_profile_trip_cnt(this);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   919
    if (head->is_profile_trip_failed()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   920
      follow_branches = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   921
    } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   922
      loop_trip_cnt = head->profile_trip_cnt();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   923
      if (head->is_CountedLoop()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   924
        CountedLoopNode* cl = head->as_CountedLoop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   925
        if (cl->phi() != NULL) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   926
          const TypeInt* t = _igvn.type(cl->phi())->is_int();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   927
          float worst_case_trip_cnt = ((float)t->_hi - t->_lo) / ABS(cl->stride_con());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   928
          if (worst_case_trip_cnt < loop_trip_cnt) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   929
            loop_trip_cnt = worst_case_trip_cnt;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   930
          }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   931
        }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   932
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   933
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   934
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   935
  return follow_branches;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   936
}
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   937
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   938
// Compute probability of reaching some CFG node from a fixed
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   939
// dominating CFG node
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   940
class PathFrequency {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   941
private:
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   942
  Node* _dom; // frequencies are computed relative to this node
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   943
  Node_Stack _stack;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   944
  GrowableArray<float> _freqs_stack; // keep track of intermediate result at regions
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   945
  GrowableArray<float> _freqs; // cache frequencies
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   946
  PhaseIdealLoop* _phase;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   947
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   948
  void set_rounding(int mode) {
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   949
    // fesetround is broken on windows
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   950
    NOT_WINDOWS(fesetround(mode);)
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   951
  }
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   952
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   953
  void check_frequency(float f) {
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   954
    NOT_WINDOWS(assert(f <= 1 && f >= 0, "Incorrect frequency");)
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   955
  }
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   956
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   957
public:
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   958
  PathFrequency(Node* dom, PhaseIdealLoop* phase)
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   959
    : _dom(dom), _stack(0), _phase(phase) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   960
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   961
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   962
  float to(Node* n) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   963
    // post order walk on the CFG graph from n to _dom
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   964
    set_rounding(FE_TOWARDZERO); // make sure rounding doesn't push frequency above 1
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   965
    IdealLoopTree* loop = _phase->get_loop(_dom);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   966
    Node* c = n;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   967
    for (;;) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   968
      assert(_phase->get_loop(c) == loop, "have to be in the same loop");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   969
      if (c == _dom || _freqs.at_grow(c->_idx, -1) >= 0) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   970
        float f = c == _dom ? 1 : _freqs.at(c->_idx);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   971
        Node* prev = c;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   972
        while (_stack.size() > 0 && prev == c) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   973
          Node* n = _stack.node();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   974
          if (!n->is_Region()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   975
            if (_phase->get_loop(n) != _phase->get_loop(n->in(0))) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   976
              // Found an inner loop: compute frequency of reaching this
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   977
              // exit from the loop head by looking at the number of
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   978
              // times each loop exit was taken
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   979
              IdealLoopTree* inner_loop = _phase->get_loop(n->in(0));
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   980
              LoopNode* inner_head = inner_loop->_head->as_Loop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   981
              assert(_phase->get_loop(n) == loop, "only 1 inner loop");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   982
              if (inner_head->is_OuterStripMinedLoop()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   983
                inner_head->verify_strip_mined(1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   984
                if (n->in(0) == inner_head->in(LoopNode::LoopBackControl)->in(0)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   985
                  n = n->in(0)->in(0)->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   986
                }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   987
                inner_loop = inner_loop->_child;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   988
                inner_head = inner_loop->_head->as_Loop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   989
                inner_head->verify_strip_mined(1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   990
              }
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   991
              set_rounding(FE_UPWARD);  // make sure rounding doesn't push frequency above 1
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   992
              float loop_exit_cnt = 0.0f;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   993
              for (uint i = 0; i < inner_loop->_body.size(); i++) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   994
                Node *n = inner_loop->_body[i];
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   995
                float c = inner_loop->compute_profile_trip_cnt_helper(n);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   996
                loop_exit_cnt += c;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   997
              }
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
   998
              set_rounding(FE_TOWARDZERO);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
   999
              float cnt = -1;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1000
              if (n->in(0)->is_If()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1001
                IfNode* iff = n->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1002
                float p = n->in(0)->as_If()->_prob;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1003
                if (n->Opcode() == Op_IfFalse) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1004
                  p = 1 - p;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1005
                }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1006
                if (p > PROB_MIN) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1007
                  cnt = p * iff->_fcnt;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1008
                } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1009
                  cnt = 0;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1010
                }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1011
              } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1012
                assert(n->in(0)->is_Jump(), "unsupported node kind");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1013
                JumpNode* jmp = n->in(0)->as_Jump();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1014
                float p = n->in(0)->as_Jump()->_probs[n->as_JumpProj()->_con];
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1015
                cnt = p * jmp->_fcnt;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1016
              }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1017
              float this_exit_f = cnt > 0 ? cnt / loop_exit_cnt : 0;
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
  1018
              check_frequency(this_exit_f);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1019
              f = f * this_exit_f;
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
  1020
              check_frequency(f);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1021
            } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1022
              float p = -1;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1023
              if (n->in(0)->is_If()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1024
                p = n->in(0)->as_If()->_prob;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1025
                if (n->Opcode() == Op_IfFalse) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1026
                  p = 1 - p;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1027
                }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1028
              } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1029
                assert(n->in(0)->is_Jump(), "unsupported node kind");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1030
                p = n->in(0)->as_Jump()->_probs[n->as_JumpProj()->_con];
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1031
              }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1032
              f = f * p;
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
  1033
              check_frequency(f);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1034
            }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1035
            _freqs.at_put_grow(n->_idx, (float)f, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1036
            _stack.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1037
          } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1038
            float prev_f = _freqs_stack.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1039
            float new_f = f;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1040
            f = new_f + prev_f;
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
  1041
            check_frequency(f);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1042
            uint i = _stack.index();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1043
            if (i < n->req()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1044
              c = n->in(i);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1045
              _stack.set_index(i+1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1046
              _freqs_stack.push(f);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1047
            } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1048
              _freqs.at_put_grow(n->_idx, f, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1049
              _stack.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1050
            }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1051
          }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1052
        }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1053
        if (_stack.size() == 0) {
52490
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
  1054
          set_rounding(FE_TONEAREST);
61915e1458bc 8205574: Loop predication "assert(f <= 1 && f >= 0) failed Incorrect frequency"
roland
parents: 52414
diff changeset
  1055
          check_frequency(f);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1056
          return f;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1057
        }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1058
      } else if (c->is_Loop()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1059
        ShouldNotReachHere();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1060
        c = c->in(LoopNode::EntryControl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1061
      } else if (c->is_Region()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1062
        _freqs_stack.push(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1063
        _stack.push(c, 2);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1064
        c = c->in(1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1065
      } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1066
        if (c->is_IfProj()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1067
          IfNode* iff = c->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1068
          if (iff->_prob == PROB_UNKNOWN) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1069
            // assume never taken
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1070
            _freqs.at_put_grow(c->_idx, 0, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1071
          } else if (_phase->get_loop(c) != _phase->get_loop(iff)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1072
            if (iff->_fcnt == COUNT_UNKNOWN) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1073
              // assume never taken
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1074
              _freqs.at_put_grow(c->_idx, 0, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1075
            } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1076
              // skip over loop
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1077
              _stack.push(c, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1078
              c = _phase->get_loop(c->in(0))->_head->as_Loop()->skip_strip_mined()->in(LoopNode::EntryControl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1079
            }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1080
          } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1081
            _stack.push(c, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1082
            c = iff;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1083
          }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1084
        } else if (c->is_JumpProj()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1085
          JumpNode* jmp = c->in(0)->as_Jump();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1086
          if (_phase->get_loop(c) != _phase->get_loop(jmp)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1087
            if (jmp->_fcnt == COUNT_UNKNOWN) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1088
              // assume never taken
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1089
              _freqs.at_put_grow(c->_idx, 0, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1090
            } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1091
              // skip over loop
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1092
              _stack.push(c, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1093
              c = _phase->get_loop(c->in(0))->_head->as_Loop()->skip_strip_mined()->in(LoopNode::EntryControl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1094
            }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1095
          } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1096
            _stack.push(c, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1097
            c = jmp;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1098
          }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1099
        } else if (c->Opcode() == Op_CatchProj &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1100
                   c->in(0)->Opcode() == Op_Catch &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1101
                   c->in(0)->in(0)->is_Proj() &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1102
                   c->in(0)->in(0)->in(0)->is_Call()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1103
          // assume exceptions are never thrown
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1104
          uint con = c->as_Proj()->_con;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1105
          if (con == CatchProjNode::fall_through_index) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1106
            Node* call = c->in(0)->in(0)->in(0)->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1107
            if (_phase->get_loop(call) != _phase->get_loop(c)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1108
              _freqs.at_put_grow(c->_idx, 0, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1109
            } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1110
              c = call;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1111
            }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1112
          } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1113
            assert(con >= CatchProjNode::catch_all_index, "what else?");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1114
            _freqs.at_put_grow(c->_idx, 0, -1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1115
          }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1116
        } else if (c->unique_ctrl_out() == NULL && !c->is_If() && !c->is_Jump()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1117
          ShouldNotReachHere();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1118
        } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1119
          c = c->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1120
        }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1121
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1122
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1123
    ShouldNotReachHere();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1124
    return -1;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1125
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1126
};
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1127
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1128
void PhaseIdealLoop::loop_predication_follow_branches(Node *n, IdealLoopTree *loop, float loop_trip_cnt,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1129
                                                      PathFrequency& pf, Node_Stack& stack, VectorSet& seen,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1130
                                                      Node_List& if_proj_list) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1131
  assert(n->is_Region(), "start from a region");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1132
  Node* tail = loop->tail();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1133
  stack.push(n, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1134
  do {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1135
    Node* c = stack.node();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1136
    assert(c->is_Region() || c->is_IfProj(), "only region here");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1137
    uint i = stack.index();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1138
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1139
    if (i < c->req()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1140
      stack.set_index(i+1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1141
      Node* in = c->in(i);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1142
      while (!is_dominator(in, tail) && !seen.test_set(in->_idx)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1143
        IdealLoopTree* in_loop = get_loop(in);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1144
        if (in_loop != loop) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1145
          in = in_loop->_head->in(LoopNode::EntryControl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1146
        } else if (in->is_Region()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1147
          stack.push(in, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1148
          break;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1149
        } else if (in->is_IfProj() &&
50923
c98bf5aa35c5 8205515: assert(opcode == Op_RangeCheck) failed: no other if variant here
roland
parents: 50632
diff changeset
  1150
                   in->as_Proj()->is_uncommon_trap_if_pattern(Deoptimization::Reason_none) &&
c98bf5aa35c5 8205515: assert(opcode == Op_RangeCheck) failed: no other if variant here
roland
parents: 50632
diff changeset
  1151
                   (in->in(0)->Opcode() == Op_If ||
c98bf5aa35c5 8205515: assert(opcode == Op_RangeCheck) failed: no other if variant here
roland
parents: 50632
diff changeset
  1152
                    in->in(0)->Opcode() == Op_RangeCheck)) {
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1153
          if (pf.to(in) * loop_trip_cnt >= 1) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1154
            stack.push(in, 1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1155
          }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1156
          in = in->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1157
        } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1158
          in = in->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1159
        }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1160
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1161
    } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1162
      if (c->is_IfProj()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1163
        if_proj_list.push(c);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1164
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1165
      stack.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1166
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1167
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1168
  } while (stack.size() > 0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1169
}
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1170
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1171
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1172
bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree *loop, ProjNode* proj, ProjNode *predicate_proj,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1173
                                                  CountedLoopNode *cl, ConNode* zero, Invariance& invar,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1174
                                                  Deoptimization::DeoptReason reason) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1175
  // Following are changed to nonnull when a predicate can be hoisted
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1176
  ProjNode* new_predicate_proj = NULL;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1177
  IfNode*   iff  = proj->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1178
  Node*     test = iff->in(1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1179
  if (!test->is_Bool()){ //Conv2B, ...
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1180
    return false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1181
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1182
  BoolNode* bol = test->as_Bool();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1183
  if (invar.is_invariant(bol)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1184
    // Invariant test
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1185
    new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1186
                                                     reason,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1187
                                                     iff->Opcode());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1188
    Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1189
    BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1190
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1191
    // Negate test if necessary
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1192
    bool negated = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1193
    if (proj->_con != predicate_proj->_con) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1194
      new_predicate_bol = new BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1195
      register_new_node(new_predicate_bol, ctrl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1196
      negated = true;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1197
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1198
    IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1199
    _igvn.hash_delete(new_predicate_iff);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1200
    new_predicate_iff->set_req(1, new_predicate_bol);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1201
#ifndef PRODUCT
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1202
    if (TraceLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1203
      tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1204
      loop->dump_head();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1205
    } else if (TraceLoopOpts) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1206
      tty->print("Predicate IC ");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1207
      loop->dump_head();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1208
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1209
#endif
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1210
  } else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1211
    // Range check for counted loops
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1212
    const Node*    cmp    = bol->in(1)->as_Cmp();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1213
    Node*          idx    = cmp->in(1);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1214
    assert(!invar.is_invariant(idx), "index is variant");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1215
    Node* rng = cmp->in(2);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1216
    assert(rng->Opcode() == Op_LoadRange || iff->is_RangeCheck() || _igvn.type(rng)->is_int()->_lo >= 0, "must be");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1217
    assert(invar.is_invariant(rng), "range must be invariant");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1218
    int scale    = 1;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1219
    Node* offset = zero;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1220
    bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1221
    assert(ok, "must be index expression");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1222
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1223
    Node* init    = cl->init_trip();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1224
    // Limit is not exact.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1225
    // Calculate exact limit here.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1226
    // Note, counted loop's test is '<' or '>'.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1227
    Node* limit   = exact_limit(loop);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1228
    int  stride   = cl->stride()->get_int();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1229
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1230
    // Build if's for the upper and lower bound tests.  The
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1231
    // lower_bound test will dominate the upper bound test and all
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1232
    // cloned or created nodes will use the lower bound test as
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1233
    // their declared control.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1234
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1235
    // Perform cloning to keep Invariance state correct since the
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1236
    // late schedule will place invariant things in the loop.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1237
    Node *ctrl = predicate_proj->in(0)->as_If()->in(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1238
    rng = invar.clone(rng, ctrl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1239
    if (offset && offset != zero) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1240
      assert(invar.is_invariant(offset), "offset must be loop invariant");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1241
      offset = invar.clone(offset, ctrl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1242
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1243
    // If predicate expressions may overflow in the integer range, longs are used.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1244
    bool overflow = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1245
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1246
    // Test the lower bound
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1247
    BoolNode* lower_bound_bol = rc_predicate(loop, ctrl, scale, offset, init, limit, stride, rng, false, overflow);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1248
    // Negate test if necessary
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1249
    bool negated = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1250
    if (proj->_con != predicate_proj->_con) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1251
      lower_bound_bol = new BoolNode(lower_bound_bol->in(1), lower_bound_bol->_test.negate());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1252
      register_new_node(lower_bound_bol, ctrl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1253
      negated = true;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1254
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1255
    ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, reason, overflow ? Op_If : iff->Opcode());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1256
    IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1257
    _igvn.hash_delete(lower_bound_iff);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1258
    lower_bound_iff->set_req(1, lower_bound_bol);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1259
    if (TraceLoopPredicate) tty->print_cr("lower bound check if: %s %d ", negated ? " negated" : "", lower_bound_iff->_idx);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1260
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1261
    // Test the upper bound
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1262
    BoolNode* upper_bound_bol = rc_predicate(loop, lower_bound_proj, scale, offset, init, limit, stride, rng, true, overflow);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1263
    negated = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1264
    if (proj->_con != predicate_proj->_con) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1265
      upper_bound_bol = new BoolNode(upper_bound_bol->in(1), upper_bound_bol->_test.negate());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1266
      register_new_node(upper_bound_bol, ctrl);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1267
      negated = true;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1268
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1269
    ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, reason, overflow ? Op_If : iff->Opcode());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1270
    assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1271
    IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1272
    _igvn.hash_delete(upper_bound_iff);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1273
    upper_bound_iff->set_req(1, upper_bound_bol);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1274
    if (TraceLoopPredicate) tty->print_cr("upper bound check if: %s %d ", negated ? " negated" : "", lower_bound_iff->_idx);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1275
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1276
    // Fall through into rest of the clean up code which will move
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1277
    // any dependent nodes onto the upper bound test.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1278
    new_predicate_proj = upper_bound_proj;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1279
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1280
    if (iff->is_RangeCheck()) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1281
      new_predicate_proj = insert_skeleton_predicate(iff, loop, proj, predicate_proj, upper_bound_proj, scale, offset, init, limit, stride, rng, overflow, reason);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1282
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1283
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1284
#ifndef PRODUCT
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1285
    if (TraceLoopOpts && !TraceLoopPredicate) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1286
      tty->print("Predicate RC ");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1287
      loop->dump_head();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1288
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1289
#endif
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1290
  } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1291
    // Loop variant check (for example, range check in non-counted loop)
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1292
    // with uncommon trap.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1293
    return false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1294
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1295
  assert(new_predicate_proj != NULL, "sanity");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1296
  // Success - attach condition (new_predicate_bol) to predicate if
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1297
  invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1298
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1299
  // Eliminate the old If in the loop body
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1300
  dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con );
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1301
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1302
  C->set_major_progress();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1303
  return true;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1304
}
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1305
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1306
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1307
// After pre/main/post loops are created, we'll put a copy of some
50632
fd430e352427 8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents: 50623
diff changeset
  1308
// range checks between the pre and main loop to validate the value
fd430e352427 8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents: 50623
diff changeset
  1309
// of the main loop induction variable. Make a copy of the predicates
fd430e352427 8205033: [REDO] Induction variable of over-unrolled loop conflicts with range checks
thartmann
parents: 50623
diff changeset
  1310
// here with an opaque node as a place holder for the value (will be
53306
8e260023fc53 8216135: C2 assert(!had_error) failed: bad dominance
roland
parents: 52925
diff changeset
  1311
// updated by PhaseIdealLoop::clone_skeleton_predicate()).
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1312
ProjNode* PhaseIdealLoop::insert_skeleton_predicate(IfNode* iff, IdealLoopTree *loop,
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1313
                                                    ProjNode* proj, ProjNode *predicate_proj,
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1314
                                                    ProjNode* upper_bound_proj,
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1315
                                                    int scale, Node* offset,
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1316
                                                    Node* init, Node* limit, jint stride,
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1317
                                                    Node* rng, bool &overflow,
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1318
                                                    Deoptimization::DeoptReason reason) {
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1319
  assert(proj->_con && predicate_proj->_con, "not a range check?");
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1320
  Node* opaque_init = new Opaque1Node(C, init);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1321
  register_new_node(opaque_init, upper_bound_proj);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1322
  BoolNode* bol = rc_predicate(loop, upper_bound_proj, scale, offset, opaque_init, limit, stride, rng, (stride > 0) != (scale > 0), overflow);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1323
  Node* opaque_bol = new Opaque4Node(C, bol, _igvn.intcon(1)); // This will go away once loop opts are over
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1324
  register_new_node(opaque_bol, upper_bound_proj);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1325
  ProjNode* new_proj = create_new_if_for_predicate(predicate_proj, NULL, reason, overflow ? Op_If : iff->Opcode());
49487
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1326
  _igvn.replace_input_of(new_proj->in(0), 1, opaque_bol);
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1327
  assert(opaque_init->outcnt() > 0, "should be used");
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1328
  return new_proj;
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1329
}
bde392011cd8 8193130: Bad graph when unrolled loop bounds conflicts with range checks
roland
parents: 48145
diff changeset
  1330
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1331
//------------------------------ loop_predication_impl--------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1332
// Insert loop predicates for null checks and range checks
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1333
bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1334
  if (!UseLoopPredicate) return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1335
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1336
  if (!loop->_head->is_Loop()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1337
    // Could be a simple region when irreducible loops are present.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1338
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1339
  }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1340
  LoopNode* head = loop->_head->as_Loop();
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1341
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1342
  if (head->unique_ctrl_out()->Opcode() == Op_NeverBranch) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1343
    // do nothing for infinite loops
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1344
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1345
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1346
48145
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1347
  if (head->is_OuterStripMinedLoop()) {
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1348
    return false;
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1349
  }
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1350
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1351
  CountedLoopNode *cl = NULL;
10263
fa58671dde31 7077439: Possible reference through NULL in loopPredicate.cpp:726
kvn
parents: 10258
diff changeset
  1352
  if (head->is_valid_counted_loop()) {
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1353
    cl = head->as_CountedLoop();
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1354
    // do nothing for iteration-splitted loops
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1355
    if (!cl->is_normal_loop()) return false;
10253
35b975b1e8f3 7070134: Hotspot crashes with sigsegv from PorterStemmer
kvn
parents: 9446
diff changeset
  1356
    // Avoid RCE if Counted loop's test is '!='.
35b975b1e8f3 7070134: Hotspot crashes with sigsegv from PorterStemmer
kvn
parents: 9446
diff changeset
  1357
    BoolTest::mask bt = cl->loopexit()->test_trip();
35b975b1e8f3 7070134: Hotspot crashes with sigsegv from PorterStemmer
kvn
parents: 9446
diff changeset
  1358
    if (bt != BoolTest::lt && bt != BoolTest::gt)
35b975b1e8f3 7070134: Hotspot crashes with sigsegv from PorterStemmer
kvn
parents: 9446
diff changeset
  1359
      cl = NULL;
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1360
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1361
48145
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1362
  Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1363
  ProjNode *loop_limit_proj = NULL;
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1364
  ProjNode *predicate_proj = NULL;
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1365
  ProjNode *profile_predicate_proj = NULL;
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1366
  // Loop limit check predicate should be near the loop.
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1367
  loop_limit_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1368
  if (loop_limit_proj != NULL) {
52608
61241fc2217a 8211451: ~2.5% regression on compression benchmark starting with 12-b11
roland
parents: 52490
diff changeset
  1369
    entry = skip_loop_predicates(loop_limit_proj);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1370
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1371
  bool has_profile_predicates = false;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1372
  profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1373
  if (profile_predicate_proj != NULL) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1374
    Node* n = skip_loop_predicates(entry);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1375
    // Check if predicates were already added to the profile predicate
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1376
    // block
50923
c98bf5aa35c5 8205515: assert(opcode == Op_RangeCheck) failed: no other if variant here
roland
parents: 50632
diff changeset
  1377
    if (n != entry->in(0)->in(0) || n->outcnt() != 1) {
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1378
      has_profile_predicates = true;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1379
    }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1380
    entry = n;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1381
  }
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1382
  predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1383
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1384
  float loop_trip_cnt = -1;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1385
  bool follow_branches = loop_predication_should_follow_branches(loop, profile_predicate_proj, loop_trip_cnt);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1386
  assert(!follow_branches || loop_trip_cnt >= 0, "negative trip count?");
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1387
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1388
  if (predicate_proj == NULL && !follow_branches) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1389
#ifndef PRODUCT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1390
    if (TraceLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1391
      tty->print("missing predicate:");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1392
      loop->dump_head();
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents: 9437
diff changeset
  1393
      head->dump(1);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1394
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1395
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1396
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1397
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1398
  ConNode* zero = _igvn.intcon(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1399
  set_ctrl(zero, C->root());
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1400
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1401
  ResourceArea *area = Thread::current()->resource_area();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1402
  Invariance invar(area, loop);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1403
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1404
  // Create list of if-projs such that a newer proj dominates all older
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1405
  // projs in the list, and they all dominate loop->tail()
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1406
  Node_List if_proj_list(area);
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1407
  Node_List regions(area);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1408
  Node *current_proj = loop->tail(); //start from tail
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1409
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1410
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1411
  Node_List controls(area);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1412
  while (current_proj != head) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1413
    if (loop == get_loop(current_proj) && // still in the loop ?
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1414
        current_proj->is_Proj()        && // is a projection  ?
34164
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
  1415
        (current_proj->in(0)->Opcode() == Op_If ||
a9e6034d7707 8137168: Replace IfNode with a new RangeCheckNode for range checks
roland
parents: 32733
diff changeset
  1416
         current_proj->in(0)->Opcode() == Op_RangeCheck)) { // is a if projection ?
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1417
      if_proj_list.push(current_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1418
    }
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1419
    if (follow_branches &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1420
        current_proj->Opcode() == Op_Region &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1421
        loop == get_loop(current_proj)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1422
      regions.push(current_proj);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1423
    }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1424
    current_proj = idom(current_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1425
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1426
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1427
  bool hoisted = false; // true if at least one proj is promoted
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1428
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1429
  if (!has_profile_predicates) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1430
    while (if_proj_list.size() > 0) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1431
      Node* n = if_proj_list.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1432
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1433
      ProjNode* proj = n->as_Proj();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1434
      IfNode*   iff  = proj->in(0)->as_If();
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1435
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1436
      CallStaticJavaNode* call = proj->is_uncommon_trap_if_pattern(Deoptimization::Reason_none);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1437
      if (call == NULL) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1438
        if (loop->is_loop_exit(iff)) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1439
          // stop processing the remaining projs in the list because the execution of them
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1440
          // depends on the condition of "iff" (iff->in(1)).
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1441
          break;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1442
        } else {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1443
          // Both arms are inside the loop. There are two cases:
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1444
          // (1) there is one backward branch. In this case, any remaining proj
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1445
          //     in the if_proj list post-dominates "iff". So, the condition of "iff"
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1446
          //     does not determine the execution the remining projs directly, and we
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1447
          //     can safely continue.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1448
          // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj"
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1449
          //     does not dominate loop->tail(), so it can not be in the if_proj list.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1450
          continue;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1451
        }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1452
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1453
      Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(call->uncommon_trap_request());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1454
      if (reason == Deoptimization::Reason_predicate) {
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1455
        break;
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1456
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1457
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1458
      if (predicate_proj != NULL) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1459
        hoisted = loop_predication_impl_helper(loop, proj, predicate_proj, cl, zero, invar, Deoptimization::Reason_predicate) | hoisted;
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1460
      }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1461
    } // end while
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1462
  }
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1463
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1464
  Node_List if_proj_list_freq(area);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1465
  if (follow_branches) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1466
    PathFrequency pf(loop->_head, this);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1467
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1468
    // Some projections were skipped by regular predicates because of
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1469
    // an early loop exit. Try them with profile data.
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1470
    while (if_proj_list.size() > 0) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1471
      Node* proj = if_proj_list.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1472
      float f = pf.to(proj);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1473
      if (proj->as_Proj()->is_uncommon_trap_if_pattern(Deoptimization::Reason_none) &&
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1474
          f * loop_trip_cnt >= 1) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1475
        hoisted = loop_predication_impl_helper(loop, proj->as_Proj(), profile_predicate_proj, cl, zero, invar, Deoptimization::Reason_profile_predicate) | hoisted;
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1476
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1477
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1478
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1479
    // And look into all branches
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1480
    Node_Stack stack(0);
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1481
    VectorSet seen(Thread::current()->resource_area());
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1482
    while (regions.size() > 0) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1483
      Node* c = regions.pop();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1484
      loop_predication_follow_branches(c, loop, loop_trip_cnt, pf, stack, seen, if_proj_list_freq);
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1485
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1486
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1487
    for (uint i = 0; i < if_proj_list_freq.size(); i++) {
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1488
      ProjNode* proj = if_proj_list_freq.at(i)->as_Proj();
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1489
      hoisted = loop_predication_impl_helper(loop, proj, profile_predicate_proj, cl, zero, invar, Deoptimization::Reason_profile_predicate) | hoisted;
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1490
    }
50623
5209d8a6303e 8203197: C2: consider all paths in loop body for loop predication
roland
parents: 50561
diff changeset
  1491
  }
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1492
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1493
#ifndef PRODUCT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1494
  // report that the loop predication has been actually performed
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1495
  // for this loop
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1496
  if (TraceLoopPredicate && hoisted) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1497
    tty->print("Loop Predication Performed:");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1498
    loop->dump_head();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1499
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1500
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1501
48145
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1502
  head->verify_strip_mined(1);
f913f6dba2d3 8186027: C2: loop strip mining
roland
parents: 47216
diff changeset
  1503
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1504
  return hoisted;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1505
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1506
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1507
//------------------------------loop_predication--------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1508
// driver routine for loop predication optimization
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1509
bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1510
  bool hoisted = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1511
  // Recursively promote predicates
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1512
  if (_child) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1513
    hoisted = _child->loop_predication( phase);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1514
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1515
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1516
  // self
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1517
  if (!_irreducible && !tail()->is_top()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1518
    hoisted |= phase->loop_predication_impl(this);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1519
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1520
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1521
  if (_next) { //sibling
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1522
    hoisted |= _next->loop_predication( phase);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1523
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1524
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1525
  return hoisted;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
  1526
}