hotspot/src/share/vm/opto/loopPredicate.cpp
author kvn
Sat, 02 Apr 2011 10:54:15 -0700
changeset 9101 ff58f9a8e31c
child 9437 9981851b4b8c
permissions -rw-r--r--
7004535: Clone loop predicate during loop unswitch Summary: Clone loop predicate for clonned loops Reviewed-by: never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9101
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     1
/*
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    30
#include "opto/loopnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    31
#include "opto/mulnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    32
#include "opto/rootnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    33
#include "opto/subnode.hpp"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    34
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    35
/*
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    36
 * 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
    37
 * 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
    38
 * The condition checks are promoted from inside the loop body, and thus
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    39
 * the checks inside the loop could be eliminated. Currently, loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    40
 * optimization has been applied to remove array range check and loop invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    41
 * checks (such as null checks).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    42
*/
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    43
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    44
//-------------------------------is_uncommon_trap_proj----------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    45
// Return true if proj is the form of "proj->[region->..]call_uct"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    46
bool PhaseIdealLoop::is_uncommon_trap_proj(ProjNode* proj, Deoptimization::DeoptReason reason) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    47
  int path_limit = 10;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    48
  assert(proj, "invalid argument");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    49
  Node* out = proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    50
  for (int ct = 0; ct < path_limit; ct++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    51
    out = out->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    52
    if (out == NULL)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    53
      return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    54
    if (out->is_CallStaticJava()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    55
      int req = out->as_CallStaticJava()->uncommon_trap_request();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    56
      if (req != 0) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    57
        Deoptimization::DeoptReason trap_reason = Deoptimization::trap_request_reason(req);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    58
        if (trap_reason == reason || reason == Deoptimization::Reason_none) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    59
           return true;
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
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    62
      return false; // don't do further after call
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
    if (out->Opcode() != Op_Region)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    65
      return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    66
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    67
  return false;
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
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    70
//-------------------------------is_uncommon_trap_if_pattern-------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    71
// Return true  for "if(test)-> proj -> ...
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
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    74
//                      other_proj->[region->..]call_uct"
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
// "must_reason_predicate" means the uct reason must be Reason_predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    77
bool PhaseIdealLoop::is_uncommon_trap_if_pattern(ProjNode *proj, Deoptimization::DeoptReason reason) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    78
  Node *in0 = proj->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    79
  if (!in0->is_If()) return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    80
  // Variation of a dead If node.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    81
  if (in0->outcnt() < 2)  return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    82
  IfNode* iff = in0->as_If();
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
  // we need "If(Conv2B(Opaque1(...)))" pattern for reason_predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    85
  if (reason != Deoptimization::Reason_none) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    86
    if (iff->in(1)->Opcode() != Op_Conv2B ||
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    87
       iff->in(1)->in(1)->Opcode() != Op_Opaque1) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    88
      return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    89
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    90
  }
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
  ProjNode* other_proj = iff->proj_out(1-proj->_con)->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    93
  if (is_uncommon_trap_proj(other_proj, reason)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    94
    assert(reason == Deoptimization::Reason_none ||
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    95
           Compile::current()->is_predicate_opaq(iff->in(1)->in(1)), "should be on the list");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    96
    return true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    97
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    98
  return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
    99
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   100
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   101
//-------------------------------register_control-------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   102
void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   103
  assert(n->is_CFG(), "must be control node");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   104
  _igvn.register_new_node_with_optimizer(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   105
  loop->_body.push(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   106
  set_loop(n, loop);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   107
  // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   108
  if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   109
    set_idom(n, pred, dom_depth(pred));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   110
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   111
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   112
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   113
//------------------------------create_new_if_for_predicate------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   114
// 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
   115
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   116
//          before                                after
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   117
//        ----------                           ----------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   118
//           ctrl                                 ctrl
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   119
//            |                                     |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   120
//            |                                     |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   121
//            v                                     v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   122
//           iff                                 new_iff
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   123
//          /    \                                /      \
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   124
//         /      \                              /        \
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   125
//        v        v                            v          v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   126
//  uncommon_proj cont_proj                   if_uct     if_cont
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   127
// \      |        |                           |          |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   128
//  \     |        |                           |          |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   129
//   v    v        v                           |          v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   130
//     rgn       loop                          |         iff
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
//      v                                      |      v         v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   134
// uncommon_trap                               | uncommon_proj cont_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   135
//                                           \  \    |           |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   136
//                                            \  \   |           |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   137
//                                             v  v  v           v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   138
//                                               rgn           loop
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   139
//                                                |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   140
//                                                |
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   141
//                                                v
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   142
//                                           uncommon_trap
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   143
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   144
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   145
// We will create a region to guard the uct call if there is no one there.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   146
// The true projecttion (if_cont) of the new_iff is returned.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   147
// This code is also used to clone predicates to clonned loops.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   148
ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   149
                                                      Deoptimization::DeoptReason reason) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   150
  assert(is_uncommon_trap_if_pattern(cont_proj, reason), "must be a uct if pattern!");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   151
  IfNode* iff = cont_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   152
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   153
  ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   154
  Node     *rgn   = uncommon_proj->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   155
  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
   156
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   157
  uint proj_index = 1; // region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   158
  if (!rgn->is_Region()) { // create a region to guard the call
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   159
    assert(rgn->is_Call(), "must be call uct");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   160
    CallNode* call = rgn->as_Call();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   161
    IdealLoopTree* loop = get_loop(call);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   162
    rgn = new (C, 1) RegionNode(1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   163
    rgn->add_req(uncommon_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   164
    register_control(rgn, loop, uncommon_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   165
    _igvn.hash_delete(call);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   166
    call->set_req(0, rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   167
    // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   168
    if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   169
      set_idom(call, rgn, dom_depth(rgn));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   170
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   171
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   172
    // Find region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   173
    for (; proj_index < rgn->req(); proj_index++)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   174
      if (rgn->in(proj_index) == uncommon_proj) break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   175
    assert(proj_index < rgn->req(), "sanity");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   176
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   177
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   178
  Node* entry = iff->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   179
  if (new_entry != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   180
    // Clonning the predicate to new location.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   181
    entry = new_entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   182
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   183
  // Create new_iff
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   184
  IdealLoopTree* lp = get_loop(entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   185
  IfNode *new_iff = iff->clone()->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   186
  new_iff->set_req(0, entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   187
  register_control(new_iff, lp, entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   188
  Node *if_cont = new (C, 1) IfTrueNode(new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   189
  Node *if_uct  = new (C, 1) IfFalseNode(new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   190
  if (cont_proj->is_IfFalse()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   191
    // Swap
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   192
    Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   193
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   194
  register_control(if_cont, lp, new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   195
  register_control(if_uct, get_loop(rgn), new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   196
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   197
  // if_uct to rgn
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   198
  _igvn.hash_delete(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   199
  rgn->add_req(if_uct);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   200
  // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   201
  if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   202
    Node* ridom = idom(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   203
    Node* nrdom = dom_lca(ridom, new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   204
    set_idom(rgn, nrdom, dom_depth(rgn));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   205
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   206
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   207
  // If rgn has phis add new edges which has the same
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   208
  // value as on original uncommon_proj pass.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   209
  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
   210
  bool has_phi = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   211
  for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   212
    Node* use = rgn->fast_out(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   213
    if (use->is_Phi() && use->outcnt() > 0) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   214
      assert(use->in(0) == rgn, "");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   215
      _igvn.hash_delete(use);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   216
      use->add_req(use->in(proj_index));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   217
      _igvn._worklist.push(use);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   218
      has_phi = true;
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
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   221
  assert(!has_phi || rgn->req() > 3, "no phis when region is created");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   222
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   223
  if (new_entry == NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   224
    // Attach if_cont to iff
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   225
    _igvn.hash_delete(iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   226
    iff->set_req(0, if_cont);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   227
    if (_idom != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   228
      set_idom(iff, if_cont, dom_depth(iff));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   229
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   230
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   231
  return if_cont->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   232
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   233
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   234
//------------------------------create_new_if_for_predicate------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   235
// 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
   236
ProjNode* PhaseIterGVN::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   237
                                                    Deoptimization::DeoptReason reason) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   238
  assert(new_entry != 0, "only used for clone predicate");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   239
  assert(PhaseIdealLoop::is_uncommon_trap_if_pattern(cont_proj, reason), "must be a uct if pattern!");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   240
  IfNode* iff = cont_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   241
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   242
  ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   243
  Node     *rgn   = uncommon_proj->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   244
  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
   245
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   246
  uint proj_index = 1; // region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   247
  if (!rgn->is_Region()) { // create a region to guard the call
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   248
    assert(rgn->is_Call(), "must be call uct");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   249
    CallNode* call = rgn->as_Call();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   250
    rgn = new (C, 1) RegionNode(1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   251
    register_new_node_with_optimizer(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   252
    rgn->add_req(uncommon_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   253
    hash_delete(call);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   254
    call->set_req(0, rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   255
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   256
    // Find region's edge corresponding to uncommon_proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   257
    for (; proj_index < rgn->req(); proj_index++)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   258
      if (rgn->in(proj_index) == uncommon_proj) break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   259
    assert(proj_index < rgn->req(), "sanity");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   260
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   261
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   262
  // Create new_iff in new location.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   263
  IfNode *new_iff = iff->clone()->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   264
  new_iff->set_req(0, new_entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   265
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   266
  register_new_node_with_optimizer(new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   267
  Node *if_cont = new (C, 1) IfTrueNode(new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   268
  Node *if_uct  = new (C, 1) IfFalseNode(new_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   269
  if (cont_proj->is_IfFalse()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   270
    // Swap
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   271
    Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   272
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   273
  register_new_node_with_optimizer(if_cont);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   274
  register_new_node_with_optimizer(if_uct);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   275
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   276
  // if_uct to rgn
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   277
  hash_delete(rgn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   278
  rgn->add_req(if_uct);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   279
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   280
  // If rgn has phis add corresponding new edges which has the same
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   281
  // value as on original uncommon_proj pass.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   282
  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
   283
  bool has_phi = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   284
  for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   285
    Node* use = rgn->fast_out(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   286
    if (use->is_Phi() && use->outcnt() > 0) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   287
      hash_delete(use);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   288
      use->add_req(use->in(proj_index));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   289
      _worklist.push(use);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   290
      has_phi = true;
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
  assert(!has_phi || rgn->req() > 3, "no phis when region is created");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   294
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   295
  return if_cont->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   296
}
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
//--------------------------clone_predicate-----------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   299
ProjNode* PhaseIdealLoop::clone_predicate(ProjNode* predicate_proj, Node* new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   300
                                          Deoptimization::DeoptReason reason,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   301
                                          PhaseIdealLoop* loop_phase,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   302
                                          PhaseIterGVN* igvn) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   303
  ProjNode* new_predicate_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   304
  if (loop_phase != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   305
    new_predicate_proj = loop_phase->create_new_if_for_predicate(predicate_proj, new_entry, reason);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   306
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   307
    new_predicate_proj =       igvn->create_new_if_for_predicate(predicate_proj, new_entry, reason);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   308
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   309
  IfNode* iff = new_predicate_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   310
  Node* ctrl  = iff->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   311
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   312
  // Match original condition since predicate's projections could be swapped.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   313
  assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   314
  Node* opq = new (igvn->C, 2) Opaque1Node(igvn->C, predicate_proj->in(0)->in(1)->in(1)->in(1));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   315
  igvn->C->add_predicate_opaq(opq);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   316
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   317
  Node* bol = new (igvn->C, 2) Conv2BNode(opq);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   318
  if (loop_phase != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   319
    loop_phase->register_new_node(opq, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   320
    loop_phase->register_new_node(bol, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   321
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   322
    igvn->register_new_node_with_optimizer(opq);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   323
    igvn->register_new_node_with_optimizer(bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   324
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   325
  igvn->hash_delete(iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   326
  iff->set_req(1, bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   327
  return new_predicate_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   328
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   329
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   330
//--------------------------move_predicate-----------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   331
// Cut predicate from old place and move it to new.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   332
ProjNode* PhaseIdealLoop::move_predicate(ProjNode* predicate_proj, Node* new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   333
                                         Deoptimization::DeoptReason reason,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   334
                                         PhaseIdealLoop* loop_phase,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   335
                                         PhaseIterGVN* igvn) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   336
  assert(new_entry != NULL, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   337
  assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   338
  IfNode* iff = predicate_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   339
  Node* old_entry = iff->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   340
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   341
  // Cut predicate from old place.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   342
  Node* old = predicate_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   343
  igvn->_worklist.push(old);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   344
  for (DUIterator_Last imin, i = old->last_outs(imin); i >= imin; ) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   345
    Node* use = old->last_out(i);  // for each use...
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   346
    igvn->hash_delete(use);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   347
    igvn->_worklist.push(use);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   348
    // Update use-def info
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   349
    uint uses_found = 0;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   350
    for (uint j = 0; j < use->req(); j++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   351
      if (use->in(j) == old) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   352
        use->set_req(j, old_entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   353
        uses_found++;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   354
        if (loop_phase != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   355
          if (use->is_CFG()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   356
            // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   357
            if (loop_phase->_idom != NULL)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   358
              loop_phase->set_idom(use, old_entry, loop_phase->dom_depth(use));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   359
          } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   360
            loop_phase->set_ctrl(use, old_entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   361
          }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   362
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   363
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   364
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   365
    i -= uses_found;    // we deleted 1 or more copies of this edge
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   366
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   367
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   368
  // Move predicate.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   369
  igvn->hash_delete(iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   370
  iff->set_req(0, new_entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   371
  igvn->_worklist.push(iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   372
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   373
  if (loop_phase != NULL) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   374
    // Fix up idom and ctrl.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   375
    loop_phase->set_ctrl(iff->in(1), new_entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   376
    loop_phase->set_ctrl(iff->in(1)->in(1), new_entry);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   377
    // When called from beautify_loops() idom is not constructed yet.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   378
    if (loop_phase->_idom != NULL)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   379
      loop_phase->set_idom(iff, new_entry, loop_phase->dom_depth(iff));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   380
  }
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
  return predicate_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   383
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   384
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   385
//--------------------------clone_loop_predicates-----------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   386
// Interface from IGVN
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   387
Node* PhaseIterGVN::clone_loop_predicates(Node* old_entry, Node* new_entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   388
  return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, false, NULL, this);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   389
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   390
Node* PhaseIterGVN::move_loop_predicates(Node* old_entry, Node* new_entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   391
  return PhaseIdealLoop::clone_loop_predicates(old_entry, new_entry, true, NULL, this);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   392
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   393
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   394
// Interface from PhaseIdealLoop
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   395
Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   396
  return clone_loop_predicates(old_entry, new_entry, false, this, &this->_igvn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   397
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   398
Node* PhaseIdealLoop::move_loop_predicates(Node* old_entry, Node* new_entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   399
  return clone_loop_predicates(old_entry, new_entry, true, this, &this->_igvn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   400
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   401
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   402
// Clone loop predicates to cloned loops (peeled, unswitched, split_if).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   403
Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   404
                                                bool move_predicates,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   405
                                                PhaseIdealLoop* loop_phase,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   406
                                                PhaseIterGVN* igvn) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   407
#ifdef ASSERT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   408
  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
   409
    if (new_entry != NULL)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   410
      new_entry->dump();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   411
    assert(false, "not IfTrue, IfFalse, Region or SafePoint");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   412
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   413
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   414
  // Search original predicates
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   415
  Node* entry = old_entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   416
  if (UseLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   417
    ProjNode* predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   418
    if (predicate_proj != NULL) { // right pattern that can be used by loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   419
      assert(entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   420
      if (move_predicates) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   421
        new_entry =  move_predicate(predicate_proj, new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   422
                                    Deoptimization::Reason_predicate,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   423
                                    loop_phase, igvn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   424
        assert(new_entry == predicate_proj, "old predicate fall through projection");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   425
      } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   426
        // clone predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   427
        new_entry = clone_predicate(predicate_proj, new_entry,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   428
                                    Deoptimization::Reason_predicate,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   429
                                    loop_phase, igvn);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   430
        assert(new_entry != NULL && new_entry->is_Proj(), "IfTrue or IfFalse after clone predicate");
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
      if (TraceLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   433
        tty->print_cr("Loop Predicate %s: ", move_predicates ? "moved" : "cloned");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   434
        debug_only( new_entry->in(0)->dump(); )
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   435
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   436
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   437
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   438
  return new_entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   439
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   440
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   441
//--------------------------eliminate_loop_predicates-----------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   442
void PhaseIdealLoop::eliminate_loop_predicates(Node* entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   443
  if (UseLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   444
    ProjNode* predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   445
    if (predicate_proj != NULL) { // right pattern that can be used by loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   446
      Node* n = entry->in(0)->in(1)->in(1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   447
      assert(n->Opcode()==Op_Opaque1, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   448
      // Remove Opaque1 node from predicates list.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   449
      // IGVN will remove this predicate check.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   450
      _igvn.replace_node(n, n->in(1));
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   451
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   452
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   453
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   454
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   455
//--------------------------skip_loop_predicates------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   456
// Skip related predicates.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   457
Node* PhaseIdealLoop::skip_loop_predicates(Node* entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   458
  Node* predicate = NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   459
  if (UseLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   460
    predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   461
    if (predicate != NULL) { // right pattern that can be used by loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   462
      assert(entry->is_Proj() && entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   463
      IfNode* iff = entry->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   464
      ProjNode* uncommon_proj = iff->proj_out(1 - entry->as_Proj()->_con);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   465
      Node* rgn = uncommon_proj->unique_ctrl_out();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   466
      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
   467
      entry = entry->in(0)->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   468
      while (entry != NULL && entry->is_Proj() && entry->in(0)->is_If()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   469
        uncommon_proj = entry->in(0)->as_If()->proj_out(1 - entry->as_Proj()->_con);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   470
        if (uncommon_proj->unique_ctrl_out() != rgn)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   471
          break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   472
        entry = entry->in(0)->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   473
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   474
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   475
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   476
  return entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   477
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   478
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   479
//--------------------------find_predicate_insertion_point-------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   480
// Find a good location to insert a predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   481
ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   482
  if (start_c == NULL || !start_c->is_Proj())
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   483
    return NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   484
  if (is_uncommon_trap_if_pattern(start_c->as_Proj(), reason)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   485
    return start_c->as_Proj();
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
  return NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   488
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   489
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   490
//--------------------------find_predicate------------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   491
// Find a predicate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   492
Node* PhaseIdealLoop::find_predicate(Node* entry) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   493
  Node* predicate = NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   494
  if (UseLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   495
    predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   496
    if (predicate != NULL) { // right pattern that can be used by loop predication
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   497
      assert(entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   498
      return entry;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   499
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   500
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   501
  return NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   502
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   503
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   504
//------------------------------Invariance-----------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   505
// 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
   506
// clone invariants.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   507
class Invariance : public StackObj {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   508
  VectorSet _visited, _invariant;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   509
  Node_Stack _stack;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   510
  VectorSet _clone_visited;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   511
  Node_List _old_new; // map of old to new (clone)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   512
  IdealLoopTree* _lpt;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   513
  PhaseIdealLoop* _phase;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   514
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   515
  // Helper function to set up the invariance for invariance computation
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   516
  // 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
   517
  // the possibility to push n onto the stack for further processing.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   518
  void visit(Node* use, Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   519
    if (_lpt->is_invariant(n)) { // known invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   520
      _invariant.set(n->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   521
    } else if (!n->is_CFG()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   522
      Node *n_ctrl = _phase->ctrl_or_self(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   523
      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
   524
      if (_phase->is_dominator(n_ctrl, u_ctrl)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   525
        _stack.push(n, n->in(0) == NULL ? 1 : 0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   526
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   527
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   528
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   529
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   530
  // Compute invariance for "the_node" and (possibly) all its inputs recursively
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   531
  // on the fly
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   532
  void compute_invariance(Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   533
    assert(_visited.test(n->_idx), "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   534
    visit(n, n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   535
    while (_stack.is_nonempty()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   536
      Node*  n = _stack.node();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   537
      uint idx = _stack.index();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   538
      if (idx == n->req()) { // all inputs are processed
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   539
        _stack.pop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   540
        // n is invariant if it's inputs are all invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   541
        bool all_inputs_invariant = true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   542
        for (uint i = 0; i < n->req(); i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   543
          Node* in = n->in(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   544
          if (in == NULL) continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   545
          assert(_visited.test(in->_idx), "must have visited input");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   546
          if (!_invariant.test(in->_idx)) { // bad guy
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   547
            all_inputs_invariant = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   548
            break;
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
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   551
        if (all_inputs_invariant) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   552
          _invariant.set(n->_idx); // I am a invariant too
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   553
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   554
      } else { // process next input
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   555
        _stack.set_index(idx + 1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   556
        Node* m = n->in(idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   557
        if (m != NULL && !_visited.test_set(m->_idx)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   558
          visit(n, m);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   559
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   560
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   561
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   562
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   563
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   564
  // Helper function to set up _old_new map for clone_nodes.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   565
  // 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
   566
  // Otherwise, push n onto the stack for real cloning.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   567
  void clone_visit(Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   568
    assert(_invariant.test(n->_idx), "must be invariant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   569
    if (_lpt->is_invariant(n)) { // known invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   570
      _old_new.map(n->_idx, n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   571
    } else { // to be cloned
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   572
      assert(!n->is_CFG(), "should not see CFG here");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   573
      _stack.push(n, n->in(0) == NULL ? 1 : 0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   574
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   575
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   576
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   577
  // Clone "n" and (possibly) all its inputs recursively
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   578
  void clone_nodes(Node* n, Node* ctrl) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   579
    clone_visit(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   580
    while (_stack.is_nonempty()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   581
      Node*  n = _stack.node();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   582
      uint idx = _stack.index();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   583
      if (idx == n->req()) { // all inputs processed, clone n!
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   584
        _stack.pop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   585
        // clone invariant node
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   586
        Node* n_cl = n->clone();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   587
        _old_new.map(n->_idx, n_cl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   588
        _phase->register_new_node(n_cl, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   589
        for (uint i = 0; i < n->req(); i++) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   590
          Node* in = n_cl->in(i);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   591
          if (in == NULL) continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   592
          n_cl->set_req(i, _old_new[in->_idx]);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   593
        }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   594
      } else { // process next input
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   595
        _stack.set_index(idx + 1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   596
        Node* m = n->in(idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   597
        if (m != NULL && !_clone_visited.test_set(m->_idx)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   598
          clone_visit(m); // visit the input
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   599
        }
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
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   604
 public:
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   605
  Invariance(Arena* area, IdealLoopTree* lpt) :
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   606
    _lpt(lpt), _phase(lpt->_phase),
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   607
    _visited(area), _invariant(area), _stack(area, 10 /* guess */),
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   608
    _clone_visited(area), _old_new(area)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   609
  {}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   610
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   611
  // Map old to n for invariance computation and clone
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   612
  void map_ctrl(Node* old, Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   613
    assert(old->is_CFG() && n->is_CFG(), "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   614
    _old_new.map(old->_idx, n); // "clone" of old is n
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   615
    _invariant.set(old->_idx);  // old is invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   616
    _clone_visited.set(old->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   617
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   618
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   619
  // Driver function to compute invariance
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   620
  bool is_invariant(Node* n) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   621
    if (!_visited.test_set(n->_idx))
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   622
      compute_invariance(n);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   623
    return (_invariant.test(n->_idx) != 0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   624
  }
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
  // Driver function to clone invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   627
  Node* clone(Node* n, Node* ctrl) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   628
    assert(ctrl->is_CFG(), "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   629
    assert(_invariant.test(n->_idx), "must be an invariant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   630
    if (!_clone_visited.test(n->_idx))
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   631
      clone_nodes(n, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   632
    return _old_new[n->_idx];
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   633
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   634
};
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   635
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   636
//------------------------------is_range_check_if -----------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   637
// 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
   638
// 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
   639
//       and offset to be loop invariant computed on the fly by "invar"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   640
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
   641
  if (!is_loop_exit(iff)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   642
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   643
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   644
  if (!iff->in(1)->is_Bool()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   645
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   646
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   647
  const BoolNode *bol = iff->in(1)->as_Bool();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   648
  if (bol->_test._test != BoolTest::lt) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   649
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   650
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   651
  if (!bol->in(1)->is_Cmp()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   652
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   653
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   654
  const CmpNode *cmp = bol->in(1)->as_Cmp();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   655
  if (cmp->Opcode() != Op_CmpU) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   656
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   657
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   658
  Node* range = cmp->in(2);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   659
  if (range->Opcode() != Op_LoadRange) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   660
    const TypeInt* tint = phase->_igvn.type(range)->isa_int();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   661
    if (!OptimizeFill || tint == NULL || tint->empty() || tint->_lo < 0) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   662
      // Allow predication on positive values that aren't LoadRanges.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   663
      // This allows optimization of loops where the length of the
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   664
      // 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
   665
      // from the array.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   666
      return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   667
    }
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
  if (!invar.is_invariant(range)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   670
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   671
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   672
  Node *iv     = _head->as_CountedLoop()->phi();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   673
  int   scale  = 0;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   674
  Node *offset = NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   675
  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
   676
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   677
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   678
  if (offset && !invar.is_invariant(offset)) { // offset must be invariant
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   679
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   680
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   681
  return true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   682
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   683
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   684
//------------------------------rc_predicate-----------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   685
// Create a range check predicate
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
// for (i = init; i < limit; i += stride) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   688
//    a[scale*i+offset]
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   689
// }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   690
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   691
// 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
   692
// as "max(scale*i + offset) u< a.length".
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   693
//
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   694
// There are two cases for max(scale*i + offset):
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   695
// (1) stride*scale > 0
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   696
//   max(scale*i + offset) = scale*(limit-stride) + offset
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   697
// (2) stride*scale < 0
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   698
//   max(scale*i + offset) = scale*init + offset
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   699
BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   700
                                       int scale, Node* offset,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   701
                                       Node* init, Node* limit, Node* stride,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   702
                                       Node* range, bool upper) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   703
  DEBUG_ONLY(ttyLocker ttyl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   704
  if (TraceLoopPredicate) tty->print("rc_predicate ");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   705
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   706
  Node* max_idx_expr  = init;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   707
  int stride_con = stride->get_int();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   708
  if ((stride_con > 0) == (scale > 0) == upper) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   709
    max_idx_expr = new (C, 3) SubINode(limit, stride);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   710
    register_new_node(max_idx_expr, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   711
    if (TraceLoopPredicate) tty->print("(limit - stride) ");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   712
  } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   713
    if (TraceLoopPredicate) tty->print("init ");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   714
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   715
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   716
  if (scale != 1) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   717
    ConNode* con_scale = _igvn.intcon(scale);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   718
    max_idx_expr = new (C, 3) MulINode(max_idx_expr, con_scale);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   719
    register_new_node(max_idx_expr, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   720
    if (TraceLoopPredicate) tty->print("* %d ", scale);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   721
  }
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
  if (offset && (!offset->is_Con() || offset->get_int() != 0)){
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   724
    max_idx_expr = new (C, 3) AddINode(max_idx_expr, offset);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   725
    register_new_node(max_idx_expr, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   726
    if (TraceLoopPredicate)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   727
      if (offset->is_Con()) tty->print("+ %d ", offset->get_int());
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   728
      else tty->print("+ offset ");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   729
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   730
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   731
  CmpUNode* cmp = new (C, 3) CmpUNode(max_idx_expr, range);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   732
  register_new_node(cmp, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   733
  BoolNode* bol = new (C, 2) BoolNode(cmp, BoolTest::lt);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   734
  register_new_node(bol, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   735
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   736
  if (TraceLoopPredicate) tty->print_cr("<u range");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   737
  return bol;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   738
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   739
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   740
//------------------------------ loop_predication_impl--------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   741
// Insert loop predicates for null checks and range checks
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   742
bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   743
  if (!UseLoopPredicate) return false;
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
  if (!loop->_head->is_Loop()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   746
    // Could be a simple region when irreducible loops are present.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   747
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   748
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   749
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   750
  if (loop->_head->unique_ctrl_out()->Opcode() == Op_NeverBranch) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   751
    // do nothing for infinite loops
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   752
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   753
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   754
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   755
  CountedLoopNode *cl = NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   756
  if (loop->_head->is_CountedLoop()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   757
    cl = loop->_head->as_CountedLoop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   758
    // do nothing for iteration-splitted loops
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   759
    if (!cl->is_normal_loop()) return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   760
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   761
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   762
  LoopNode *lpn  = loop->_head->as_Loop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   763
  Node* entry = lpn->in(LoopNode::EntryControl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   764
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   765
  ProjNode *predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   766
  if (!predicate_proj) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   767
#ifndef PRODUCT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   768
    if (TraceLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   769
      tty->print("missing predicate:");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   770
      loop->dump_head();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   771
      lpn->dump(1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   772
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   773
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   774
    return false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   775
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   776
  ConNode* zero = _igvn.intcon(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   777
  set_ctrl(zero, C->root());
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   778
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   779
  ResourceArea *area = Thread::current()->resource_area();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   780
  Invariance invar(area, loop);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   781
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   782
  // 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
   783
  // projs in the list, and they all dominate loop->tail()
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   784
  Node_List if_proj_list(area);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   785
  LoopNode *head  = loop->_head->as_Loop();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   786
  Node *current_proj = loop->tail(); //start from tail
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   787
  while (current_proj != head) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   788
    if (loop == get_loop(current_proj) && // still in the loop ?
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   789
        current_proj->is_Proj()        && // is a projection  ?
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   790
        current_proj->in(0)->Opcode() == Op_If) { // is a if projection ?
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   791
      if_proj_list.push(current_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   792
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   793
    current_proj = idom(current_proj);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   794
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   795
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   796
  bool hoisted = false; // true if at least one proj is promoted
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   797
  while (if_proj_list.size() > 0) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   798
    // Following are changed to nonnull when a predicate can be hoisted
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   799
    ProjNode* new_predicate_proj = NULL;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   800
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   801
    ProjNode* proj = if_proj_list.pop()->as_Proj();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   802
    IfNode*   iff  = proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   803
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   804
    if (!is_uncommon_trap_if_pattern(proj, Deoptimization::Reason_none)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   805
      if (loop->is_loop_exit(iff)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   806
        // stop processing the remaining projs in the list because the execution of them
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   807
        // depends on the condition of "iff" (iff->in(1)).
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   808
        break;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   809
      } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   810
        // Both arms are inside the loop. There are two cases:
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   811
        // (1) there is one backward branch. In this case, any remaining proj
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   812
        //     in the if_proj list post-dominates "iff". So, the condition of "iff"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   813
        //     does not determine the execution the remining projs directly, and we
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   814
        //     can safely continue.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   815
        // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj"
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   816
        //     does not dominate loop->tail(), so it can not be in the if_proj list.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   817
        continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   818
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   819
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   820
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   821
    Node*     test = iff->in(1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   822
    if (!test->is_Bool()){ //Conv2B, ...
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   823
      continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   824
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   825
    BoolNode* bol = test->as_Bool();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   826
    if (invar.is_invariant(bol)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   827
      // Invariant test
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   828
      new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL,
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   829
                                                       Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   830
      Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   831
      BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   832
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   833
      // Negate test if necessary
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   834
      bool negated = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   835
      if (proj->_con != predicate_proj->_con) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   836
        new_predicate_bol = new (C, 2) BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate());
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   837
        register_new_node(new_predicate_bol, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   838
        negated = true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   839
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   840
      IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   841
      _igvn.hash_delete(new_predicate_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   842
      new_predicate_iff->set_req(1, new_predicate_bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   843
#ifndef PRODUCT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   844
      if (TraceLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   845
        tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   846
        loop->dump_head();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   847
      } else if (TraceLoopOpts) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   848
        tty->print("Predicate IC ");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   849
        loop->dump_head();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   850
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   851
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   852
    } else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   853
      assert(proj->_con == predicate_proj->_con, "must match");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   854
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   855
      // Range check for counted loops
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   856
      const Node*    cmp    = bol->in(1)->as_Cmp();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   857
      Node*          idx    = cmp->in(1);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   858
      assert(!invar.is_invariant(idx), "index is variant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   859
      assert(cmp->in(2)->Opcode() == Op_LoadRange || OptimizeFill, "must be");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   860
      Node* rng = cmp->in(2);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   861
      assert(invar.is_invariant(rng), "range must be invariant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   862
      int scale    = 1;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   863
      Node* offset = zero;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   864
      bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   865
      assert(ok, "must be index expression");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   866
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   867
      Node* init    = cl->init_trip();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   868
      Node* limit   = cl->limit();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   869
      Node* stride  = cl->stride();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   870
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   871
      // Build if's for the upper and lower bound tests.  The
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   872
      // lower_bound test will dominate the upper bound test and all
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   873
      // cloned or created nodes will use the lower bound test as
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   874
      // their declared control.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   875
      ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   876
      ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   877
      assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   878
      Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   879
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   880
      // Perform cloning to keep Invariance state correct since the
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   881
      // late schedule will place invariant things in the loop.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   882
      rng = invar.clone(rng, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   883
      if (offset && offset != zero) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   884
        assert(invar.is_invariant(offset), "offset must be loop invariant");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   885
        offset = invar.clone(offset, ctrl);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   886
      }
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
      // Test the lower bound
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   889
      Node*  lower_bound_bol = rc_predicate(ctrl, scale, offset, init, limit, stride, rng, false);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   890
      IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   891
      _igvn.hash_delete(lower_bound_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   892
      lower_bound_iff->set_req(1, lower_bound_bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   893
      if (TraceLoopPredicate) tty->print_cr("lower bound check if: %d", lower_bound_iff->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   894
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   895
      // Test the upper bound
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   896
      Node* upper_bound_bol = rc_predicate(ctrl, scale, offset, init, limit, stride, rng, true);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   897
      IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   898
      _igvn.hash_delete(upper_bound_iff);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   899
      upper_bound_iff->set_req(1, upper_bound_bol);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   900
      if (TraceLoopPredicate) tty->print_cr("upper bound check if: %d", lower_bound_iff->_idx);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   901
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   902
      // Fall through into rest of the clean up code which will move
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   903
      // any dependent nodes onto the upper bound test.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   904
      new_predicate_proj = upper_bound_proj;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   905
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   906
#ifndef PRODUCT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   907
      if (TraceLoopOpts && !TraceLoopPredicate) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   908
        tty->print("Predicate RC ");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   909
        loop->dump_head();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   910
      }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   911
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   912
    } else {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   913
      // Loop variant check (for example, range check in non-counted loop)
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   914
      // with uncommon trap.
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   915
      continue;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   916
    }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   917
    assert(new_predicate_proj != NULL, "sanity");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   918
    // Success - attach condition (new_predicate_bol) to predicate if
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   919
    invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   920
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   921
    // Eliminate the old If in the loop body
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   922
    dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con );
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   923
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   924
    hoisted = true;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   925
    C->set_major_progress();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   926
  } // end while
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   927
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   928
#ifndef PRODUCT
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   929
  // report that the loop predication has been actually performed
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   930
  // for this loop
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   931
  if (TraceLoopPredicate && hoisted) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   932
    tty->print("Loop Predication Performed:");
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   933
    loop->dump_head();
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   934
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   935
#endif
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   936
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   937
  return hoisted;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   938
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   939
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   940
//------------------------------loop_predication--------------------------------
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   941
// driver routine for loop predication optimization
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   942
bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   943
  bool hoisted = false;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   944
  // Recursively promote predicates
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   945
  if (_child) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   946
    hoisted = _child->loop_predication( phase);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   947
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   948
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   949
  // self
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   950
  if (!_irreducible && !tail()->is_top()) {
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   951
    hoisted |= phase->loop_predication_impl(this);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   952
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   953
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   954
  if (_next) { //sibling
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   955
    hoisted |= _next->loop_predication( phase);
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   956
  }
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   957
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   958
  return hoisted;
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   959
}
ff58f9a8e31c 7004535: Clone loop predicate during loop unswitch
kvn
parents:
diff changeset
   960