< prev index next >

src/hotspot/share/opto/loopopts.cpp

Print this page

  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "gc/shared/barrierSet.hpp"
  26 #include "gc/shared/c2/barrierSetC2.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/callnode.hpp"
  31 #include "opto/castnode.hpp"
  32 #include "opto/connode.hpp"
  33 #include "opto/divnode.hpp"

  34 #include "opto/loopnode.hpp"
  35 #include "opto/matcher.hpp"
  36 #include "opto/movenode.hpp"
  37 #include "opto/mulnode.hpp"
  38 #include "opto/opaquenode.hpp"
  39 #include "opto/rootnode.hpp"
  40 #include "opto/subnode.hpp"
  41 #include "opto/subtypenode.hpp"
  42 #include "opto/superword.hpp"
  43 #include "opto/vectornode.hpp"
  44 #include "utilities/checkedCast.hpp"
  45 #include "utilities/macros.hpp"
  46 
  47 //=============================================================================
  48 //------------------------------split_thru_phi---------------------------------
  49 // Split Node 'n' through merge point if there is enough win.
  50 Node* PhaseIdealLoop::split_thru_phi(Node* n, Node* region, int policy) {
  51   if ((n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) ||
  52       (n->Opcode() == Op_ConvL2I && n->bottom_type() != TypeInt::INT)) {
  53     // ConvI2L/ConvL2I may have type information on it which is unsafe to push up
  54     // so disable this for now
  55     return nullptr;
  56   }
  57 
  58   // Splitting range check CastIIs through a loop induction Phi can
  59   // cause new Phis to be created that are left unrelated to the loop
  60   // induction Phi and prevent optimizations (vectorization)
  61   if (n->Opcode() == Op_CastII && region->is_CountedLoop() &&
  62       n->in(1) == region->as_CountedLoop()->phi()) {
  63     return nullptr;
  64   }
  65 






  66   if (cannot_split_division(n, region)) {
  67     return nullptr;
  68   }
  69 
  70   SplitThruPhiWins wins(region);
  71   assert(!n->is_CFG(), "");
  72   assert(region->is_Region(), "");
  73 
  74   const Type* type = n->bottom_type();
  75   const TypeOopPtr* t_oop = _igvn.type(n)->isa_oopptr();
  76   Node* phi;
  77   if (t_oop != nullptr && t_oop->is_known_instance_field()) {
  78     int iid    = t_oop->instance_id();
  79     int index  = C->get_alias_index(t_oop);
  80     int offset = t_oop->offset();
  81     phi = new PhiNode(region, type, nullptr, iid, index, offset);
  82   } else {
  83     phi = PhiNode::make_blank(region, n);
  84   }
  85   uint old_unique = C->unique();

 775       // CMOVE'd derived pointer?  It's a CMOVE'd derived base.  Thus
 776       // CMOVE'ing a derived pointer requires we also CMOVE the base.  If we
 777       // have a Phi for the base here that we convert to a CMOVE all is well
 778       // and good.  But if the base is dead, we'll not make a CMOVE.  Later
 779       // the allocator will have to produce a base by creating a CMOVE of the
 780       // relevant bases.  This puts the allocator in the business of
 781       // manufacturing expensive instructions, generally a bad plan.
 782       // Just Say No to Conditionally-Moved Derived Pointers.
 783       if (tp && tp->offset() != 0)
 784         return nullptr;
 785       cost++;
 786       break;
 787     }
 788     default:
 789       return nullptr;              // In particular, can't do memory or I/O
 790     }
 791     // Add in cost any speculative ops
 792     for (uint j = 1; j < region->req(); j++) {
 793       Node *proj = region->in(j);
 794       Node *inp = phi->in(j);




 795       if (get_ctrl(inp) == proj) { // Found local op
 796         cost++;
 797         // Check for a chain of dependent ops; these will all become
 798         // speculative in a CMOV.
 799         for (uint k = 1; k < inp->req(); k++)
 800           if (get_ctrl(inp->in(k)) == proj)
 801             cost += ConditionalMoveLimit; // Too much speculative goo
 802       }
 803     }
 804     // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
 805     // This will likely Split-If, a higher-payoff operation.
 806     for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
 807       Node* use = phi->fast_out(k);
 808       if (use->is_Cmp() || use->is_DecodeNarrowPtr() || use->is_EncodeNarrowPtr())
 809         cost += ConditionalMoveLimit;
 810       // Is there a use inside the loop?
 811       // Note: check only basic types since CMoveP is pinned.
 812       if (!used_inside_loop && is_java_primitive(bt)) {
 813         IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
 814         if (r_loop == u_loop || r_loop->is_member(u_loop)) {

1104             assert(get_loop(lca)->_nest < n_loop->_nest || get_loop(lca)->_head->as_Loop()->is_in_infinite_subgraph(), "must not be moved into inner loop");
1105 
1106             // Move store out of the loop
1107             _igvn.replace_node(hook, n->in(MemNode::Memory));
1108             _igvn.replace_input_of(n, 0, lca);
1109             set_ctrl_and_loop(n, lca);
1110 
1111             // Disconnect the phi now. An empty phi can confuse other
1112             // optimizations in this pass of loop opts..
1113             if (phi->in(LoopNode::LoopBackControl) == phi) {
1114               _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1115               n_loop->_body.yank(phi);
1116             }
1117           }
1118         }
1119       }
1120     }
1121   }
1122 }
1123 
















































1124 //------------------------------split_if_with_blocks_pre-----------------------
1125 // Do the real work in a non-recursive function.  Data nodes want to be
1126 // cloned in the pre-order so they can feed each other nicely.
1127 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1128   // Cloning these guys is unlikely to win
1129   int n_op = n->Opcode();
1130   if (n_op == Op_MergeMem) {
1131     return n;
1132   }
1133   if (n->is_Proj()) {
1134     return n;
1135   }






1136   // Do not clone-up CmpFXXX variations, as these are always
1137   // followed by a CmpI
1138   if (n->is_Cmp()) {
1139     return n;
1140   }
1141   // Attempt to use a conditional move instead of a phi/branch
1142   if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1143     Node *cmov = conditional_move( n );
1144     if (cmov) {
1145       return cmov;
1146     }
1147   }
1148   if (n->is_CFG() || n->is_LoadStore()) {
1149     return n;
1150   }
1151   if (n->is_Opaque1()) { // Opaque nodes cannot be mod'd
1152     if (!C->major_progress()) {   // If chance of no more loop opts...
1153       _igvn._worklist.push(n);  // maybe we'll remove them
1154     }
1155     return n;

1388 
1389   return true;
1390 }
1391 
1392 // Detect if the node is the inner strip-mined loop
1393 // Return: null if it's not the case, or the exit of outer strip-mined loop
1394 static Node* is_inner_of_stripmined_loop(const Node* out) {
1395   Node* out_le = nullptr;
1396 
1397   if (out->is_CountedLoopEnd()) {
1398       const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1399 
1400       if (loop != nullptr && loop->is_strip_mined()) {
1401         out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1402       }
1403   }
1404 
1405   return out_le;
1406 }
1407 


































































































1408 //------------------------------split_if_with_blocks_post----------------------
1409 // Do the real work in a non-recursive function.  CFG hackery wants to be
1410 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1411 // info.
1412 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1413 




1414   // Cloning Cmp through Phi's involves the split-if transform.
1415   // FastLock is not used by an If
1416   if (n->is_Cmp() && !n->is_FastLock()) {
1417     Node *n_ctrl = get_ctrl(n);
1418     // Determine if the Node has inputs from some local Phi.
1419     // Returns the block to clone thru.
1420     Node *n_blk = has_local_phi_input(n);
1421     if (n_blk != n_ctrl) {
1422       return;
1423     }
1424 
1425     if (!can_split_if(n_ctrl)) {
1426       return;
1427     }
1428 
1429     if (n->outcnt() != 1) {
1430       return; // Multiple bool's from 1 compare?
1431     }
1432     Node *bol = n->unique_out();
1433     assert(bol->is_Bool(), "expect a bool here");

1537           //    accesses would start to float, since we don't pin at that point.
1538           // 3. If we move from regular if: don't pin. All array accesses are already assumed to be pinned.
1539           bool pin_array_access_nodes =  n->Opcode() == Op_RangeCheck &&
1540                                          prevdom->in(0)->Opcode() != Op_RangeCheck;
1541           dominated_by(prevdom->as_IfProj(), n->as_If(), false, pin_array_access_nodes);
1542           DEBUG_ONLY( if (VerifyLoopOptimizations) { verify(); } );
1543           return;
1544         }
1545         prevdom = dom;
1546         dom = idom(prevdom);
1547       }
1548     }
1549   }
1550 
1551   try_sink_out_of_loop(n);
1552   if (C->failing()) {
1553     return;
1554   }
1555 
1556   try_move_store_after_loop(n);





1557 }
1558 
1559 // Transform:
1560 //
1561 // if (some_condition) {
1562 //   // body 1
1563 // } else {
1564 //   // body 2
1565 // }
1566 // if (some_condition) {
1567 //   // body 3
1568 // } else {
1569 //   // body 4
1570 // }
1571 //
1572 // into:
1573 //
1574 //
1575 // if (some_condition) {
1576 //   // body 1

2045   uint i;
2046   for (i = 1; i < phi->req(); i++) {
2047     Node* b = phi->in(i);
2048     if (b->is_Phi()) {
2049       _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2050     } else {
2051       assert(b->is_Bool() || b->is_OpaqueNotNull() || b->is_OpaqueInitializedAssertionPredicate(),
2052              "bool, non-null check with OpaqueNotNull or Initialized Assertion Predicate with its Opaque node");
2053     }
2054   }
2055   Node* n = phi->in(1);
2056   Node* sample_opaque = nullptr;
2057   Node *sample_bool = nullptr;
2058   if (n->is_OpaqueNotNull() || n->is_OpaqueInitializedAssertionPredicate()) {
2059     sample_opaque = n;
2060     sample_bool = n->in(1);
2061     assert(sample_bool->is_Bool(), "wrong type");
2062   } else {
2063     sample_bool = n;
2064   }
2065   Node *sample_cmp = sample_bool->in(1);








2066 
2067   // Make Phis to merge the Cmp's inputs.
2068   PhiNode *phi1 = new PhiNode(phi->in(0), Type::TOP);
2069   PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2070   for (i = 1; i < phi->req(); i++) {
2071     Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2072     Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2073     phi1->set_req(i, n1);
2074     phi2->set_req(i, n2);
2075     phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2076     phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2077   }
2078   // See if these Phis have been made before.
2079   // Register with optimizer
2080   Node *hit1 = _igvn.hash_find_insert(phi1);
2081   if (hit1) {                   // Hit, toss just made Phi
2082     _igvn.remove_dead_node(phi1); // Remove new phi
2083     assert(hit1->is_Phi(), "" );
2084     phi1 = (PhiNode*)hit1;      // Use existing phi
2085   } else {                      // Miss
2086     _igvn.register_new_node_with_optimizer(phi1);
2087   }
2088   Node *hit2 = _igvn.hash_find_insert(phi2);

  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "gc/shared/barrierSet.hpp"
  26 #include "gc/shared/c2/barrierSetC2.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "opto/addnode.hpp"
  30 #include "opto/callnode.hpp"
  31 #include "opto/castnode.hpp"
  32 #include "opto/connode.hpp"
  33 #include "opto/divnode.hpp"
  34 #include "opto/inlinetypenode.hpp"
  35 #include "opto/loopnode.hpp"
  36 #include "opto/matcher.hpp"
  37 #include "opto/movenode.hpp"
  38 #include "opto/mulnode.hpp"
  39 #include "opto/opaquenode.hpp"
  40 #include "opto/rootnode.hpp"
  41 #include "opto/subnode.hpp"
  42 #include "opto/subtypenode.hpp"
  43 #include "opto/superword.hpp"
  44 #include "opto/vectornode.hpp"
  45 #include "utilities/checkedCast.hpp"
  46 #include "utilities/macros.hpp"
  47 
  48 //=============================================================================
  49 //------------------------------split_thru_phi---------------------------------
  50 // Split Node 'n' through merge point if there is enough win.
  51 Node* PhaseIdealLoop::split_thru_phi(Node* n, Node* region, int policy) {
  52   if ((n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) ||
  53       (n->Opcode() == Op_ConvL2I && n->bottom_type() != TypeInt::INT)) {
  54     // ConvI2L/ConvL2I may have type information on it which is unsafe to push up
  55     // so disable this for now
  56     return nullptr;
  57   }
  58 
  59   // Splitting range check CastIIs through a loop induction Phi can
  60   // cause new Phis to be created that are left unrelated to the loop
  61   // induction Phi and prevent optimizations (vectorization)
  62   if (n->Opcode() == Op_CastII && region->is_CountedLoop() &&
  63       n->in(1) == region->as_CountedLoop()->phi()) {
  64     return nullptr;
  65   }
  66 
  67   // Inline types should not be split through Phis because they cannot be merged
  68   // through Phi nodes but each value input needs to be merged individually.
  69   if (n->is_InlineType()) {
  70     return nullptr;
  71   }
  72 
  73   if (cannot_split_division(n, region)) {
  74     return nullptr;
  75   }
  76 
  77   SplitThruPhiWins wins(region);
  78   assert(!n->is_CFG(), "");
  79   assert(region->is_Region(), "");
  80 
  81   const Type* type = n->bottom_type();
  82   const TypeOopPtr* t_oop = _igvn.type(n)->isa_oopptr();
  83   Node* phi;
  84   if (t_oop != nullptr && t_oop->is_known_instance_field()) {
  85     int iid    = t_oop->instance_id();
  86     int index  = C->get_alias_index(t_oop);
  87     int offset = t_oop->offset();
  88     phi = new PhiNode(region, type, nullptr, iid, index, offset);
  89   } else {
  90     phi = PhiNode::make_blank(region, n);
  91   }
  92   uint old_unique = C->unique();

 782       // CMOVE'd derived pointer?  It's a CMOVE'd derived base.  Thus
 783       // CMOVE'ing a derived pointer requires we also CMOVE the base.  If we
 784       // have a Phi for the base here that we convert to a CMOVE all is well
 785       // and good.  But if the base is dead, we'll not make a CMOVE.  Later
 786       // the allocator will have to produce a base by creating a CMOVE of the
 787       // relevant bases.  This puts the allocator in the business of
 788       // manufacturing expensive instructions, generally a bad plan.
 789       // Just Say No to Conditionally-Moved Derived Pointers.
 790       if (tp && tp->offset() != 0)
 791         return nullptr;
 792       cost++;
 793       break;
 794     }
 795     default:
 796       return nullptr;              // In particular, can't do memory or I/O
 797     }
 798     // Add in cost any speculative ops
 799     for (uint j = 1; j < region->req(); j++) {
 800       Node *proj = region->in(j);
 801       Node *inp = phi->in(j);
 802       if (inp->isa_InlineType()) {
 803         // TODO 8302217 This prevents PhiNode::push_inline_types_through
 804         return nullptr;
 805       }
 806       if (get_ctrl(inp) == proj) { // Found local op
 807         cost++;
 808         // Check for a chain of dependent ops; these will all become
 809         // speculative in a CMOV.
 810         for (uint k = 1; k < inp->req(); k++)
 811           if (get_ctrl(inp->in(k)) == proj)
 812             cost += ConditionalMoveLimit; // Too much speculative goo
 813       }
 814     }
 815     // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
 816     // This will likely Split-If, a higher-payoff operation.
 817     for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
 818       Node* use = phi->fast_out(k);
 819       if (use->is_Cmp() || use->is_DecodeNarrowPtr() || use->is_EncodeNarrowPtr())
 820         cost += ConditionalMoveLimit;
 821       // Is there a use inside the loop?
 822       // Note: check only basic types since CMoveP is pinned.
 823       if (!used_inside_loop && is_java_primitive(bt)) {
 824         IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
 825         if (r_loop == u_loop || r_loop->is_member(u_loop)) {

1115             assert(get_loop(lca)->_nest < n_loop->_nest || get_loop(lca)->_head->as_Loop()->is_in_infinite_subgraph(), "must not be moved into inner loop");
1116 
1117             // Move store out of the loop
1118             _igvn.replace_node(hook, n->in(MemNode::Memory));
1119             _igvn.replace_input_of(n, 0, lca);
1120             set_ctrl_and_loop(n, lca);
1121 
1122             // Disconnect the phi now. An empty phi can confuse other
1123             // optimizations in this pass of loop opts..
1124             if (phi->in(LoopNode::LoopBackControl) == phi) {
1125               _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1126               n_loop->_body.yank(phi);
1127             }
1128           }
1129         }
1130       }
1131     }
1132   }
1133 }
1134 
1135 // We can't use immutable memory for the flat array check because we are loading the mark word which is
1136 // mutable. Although the bits we are interested in are immutable (we check for markWord::unlocked_value),
1137 // we need to use raw memory to not break anti dependency analysis. Below code will attempt to still move
1138 // flat array checks out of loops, mainly to enable loop unswitching.
1139 void PhaseIdealLoop::move_flat_array_check_out_of_loop(Node* n) {
1140   // Skip checks for more than one array
1141   if (n->req() > 3) {
1142     return;
1143   }
1144   Node* mem = n->in(FlatArrayCheckNode::Memory);
1145   Node* array = n->in(FlatArrayCheckNode::ArrayOrKlass)->uncast();
1146   IdealLoopTree* check_loop = get_loop(get_ctrl(n));
1147   IdealLoopTree* ary_loop = get_loop(get_ctrl(array));
1148 
1149   // Check if array is loop invariant
1150   if (!check_loop->is_member(ary_loop)) {
1151     // Walk up memory graph from the check until we leave the loop
1152     VectorSet wq;
1153     wq.set(mem->_idx);
1154     while (check_loop->is_member(get_loop(ctrl_or_self(mem)))) {
1155       if (mem->is_Phi()) {
1156         mem = mem->in(1);
1157       } else if (mem->is_MergeMem()) {
1158         mem = mem->as_MergeMem()->memory_at(Compile::AliasIdxRaw);
1159       } else if (mem->is_Proj()) {
1160         mem = mem->in(0);
1161       } else if (mem->is_MemBar() || mem->is_SafePoint()) {
1162         mem = mem->in(TypeFunc::Memory);
1163       } else if (mem->is_Store() || mem->is_LoadStore() || mem->is_ClearArray()) {
1164         mem = mem->in(MemNode::Memory);
1165       } else {
1166 #ifdef ASSERT
1167         mem->dump();
1168 #endif
1169         ShouldNotReachHere();
1170       }
1171       if (wq.test_set(mem->_idx)) {
1172         return;
1173       }
1174     }
1175     // Replace memory input and re-compute ctrl to move the check out of the loop
1176     _igvn.replace_input_of(n, 1, mem);
1177     set_ctrl_and_loop(n, get_early_ctrl(n));
1178     Node* bol = n->unique_out();
1179     set_ctrl_and_loop(bol, get_early_ctrl(bol));
1180   }
1181 }
1182 
1183 //------------------------------split_if_with_blocks_pre-----------------------
1184 // Do the real work in a non-recursive function.  Data nodes want to be
1185 // cloned in the pre-order so they can feed each other nicely.
1186 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1187   // Cloning these guys is unlikely to win
1188   int n_op = n->Opcode();
1189   if (n_op == Op_MergeMem) {
1190     return n;
1191   }
1192   if (n->is_Proj()) {
1193     return n;
1194   }
1195 
1196   if (n->isa_FlatArrayCheck()) {
1197     move_flat_array_check_out_of_loop(n);
1198     return n;
1199   }
1200 
1201   // Do not clone-up CmpFXXX variations, as these are always
1202   // followed by a CmpI
1203   if (n->is_Cmp()) {
1204     return n;
1205   }
1206   // Attempt to use a conditional move instead of a phi/branch
1207   if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1208     Node *cmov = conditional_move( n );
1209     if (cmov) {
1210       return cmov;
1211     }
1212   }
1213   if (n->is_CFG() || n->is_LoadStore()) {
1214     return n;
1215   }
1216   if (n->is_Opaque1()) { // Opaque nodes cannot be mod'd
1217     if (!C->major_progress()) {   // If chance of no more loop opts...
1218       _igvn._worklist.push(n);  // maybe we'll remove them
1219     }
1220     return n;

1453 
1454   return true;
1455 }
1456 
1457 // Detect if the node is the inner strip-mined loop
1458 // Return: null if it's not the case, or the exit of outer strip-mined loop
1459 static Node* is_inner_of_stripmined_loop(const Node* out) {
1460   Node* out_le = nullptr;
1461 
1462   if (out->is_CountedLoopEnd()) {
1463       const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1464 
1465       if (loop != nullptr && loop->is_strip_mined()) {
1466         out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1467       }
1468   }
1469 
1470   return out_le;
1471 }
1472 
1473 bool PhaseIdealLoop::flat_array_element_type_check(Node *n) {
1474   // If the CmpP is a subtype check for a value that has just been
1475   // loaded from an array, the subtype check guarantees the value
1476   // can't be stored in a flat array and the load of the value
1477   // happens with a flat array check then: push the type check
1478   // through the phi of the flat array check. This needs special
1479   // logic because the subtype check's input is not a phi but a
1480   // LoadKlass that must first be cloned through the phi.
1481   if (n->Opcode() != Op_CmpP) {
1482     return false;
1483   }
1484 
1485   Node* klassptr = n->in(1);
1486   Node* klasscon = n->in(2);
1487 
1488   if (klassptr->is_DecodeNarrowPtr()) {
1489     klassptr = klassptr->in(1);
1490   }
1491 
1492   if (klassptr->Opcode() != Op_LoadKlass && klassptr->Opcode() != Op_LoadNKlass) {
1493     return false;
1494   }
1495 
1496   if (!klasscon->is_Con()) {
1497     return false;
1498   }
1499 
1500   Node* addr = klassptr->in(MemNode::Address);
1501 
1502   if (!addr->is_AddP()) {
1503     return false;
1504   }
1505 
1506   intptr_t offset;
1507   Node* obj = AddPNode::Ideal_base_and_offset(addr, &_igvn, offset);
1508 
1509   if (obj == nullptr) {
1510     return false;
1511   }
1512 
1513   assert(obj != nullptr && addr->in(AddPNode::Base) == addr->in(AddPNode::Address), "malformed AddP?");
1514   if (obj->Opcode() == Op_CastPP) {
1515     obj = obj->in(1);
1516   }
1517 
1518   if (!obj->is_Phi()) {
1519     return false;
1520   }
1521 
1522   Node* region = obj->in(0);
1523 
1524   Node* phi = PhiNode::make_blank(region, n->in(1));
1525   for (uint i = 1; i < region->req(); i++) {
1526     Node* in = obj->in(i);
1527     Node* ctrl = region->in(i);
1528     if (addr->in(AddPNode::Base) != obj) {
1529       Node* cast = addr->in(AddPNode::Base);
1530       assert(cast->Opcode() == Op_CastPP && cast->in(0) != nullptr, "inconsistent subgraph");
1531       Node* cast_clone = cast->clone();
1532       cast_clone->set_req(0, ctrl);
1533       cast_clone->set_req(1, in);
1534       register_new_node(cast_clone, ctrl);
1535       const Type* tcast = cast_clone->Value(&_igvn);
1536       _igvn.set_type(cast_clone, tcast);
1537       cast_clone->as_Type()->set_type(tcast);
1538       in = cast_clone;
1539     }
1540     Node* addr_clone = addr->clone();
1541     addr_clone->set_req(AddPNode::Base, in);
1542     addr_clone->set_req(AddPNode::Address, in);
1543     register_new_node(addr_clone, ctrl);
1544     _igvn.set_type(addr_clone, addr_clone->Value(&_igvn));
1545     Node* klassptr_clone = klassptr->clone();
1546     klassptr_clone->set_req(2, addr_clone);
1547     register_new_node(klassptr_clone, ctrl);
1548     _igvn.set_type(klassptr_clone, klassptr_clone->Value(&_igvn));
1549     if (klassptr != n->in(1)) {
1550       Node* decode = n->in(1);
1551       assert(decode->is_DecodeNarrowPtr(), "inconsistent subgraph");
1552       Node* decode_clone = decode->clone();
1553       decode_clone->set_req(1, klassptr_clone);
1554       register_new_node(decode_clone, ctrl);
1555       _igvn.set_type(decode_clone, decode_clone->Value(&_igvn));
1556       klassptr_clone = decode_clone;
1557     }
1558     phi->set_req(i, klassptr_clone);
1559   }
1560   register_new_node(phi, region);
1561   Node* orig = n->in(1);
1562   _igvn.replace_input_of(n, 1, phi);
1563   split_if_with_blocks_post(n);
1564   if (n->outcnt() != 0) {
1565     _igvn.replace_input_of(n, 1, orig);
1566     _igvn.remove_dead_node(phi);
1567   }
1568   return true;
1569 }
1570 
1571 //------------------------------split_if_with_blocks_post----------------------
1572 // Do the real work in a non-recursive function.  CFG hackery wants to be
1573 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1574 // info.
1575 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1576 
1577   if (flat_array_element_type_check(n)) {
1578     return;
1579   }
1580 
1581   // Cloning Cmp through Phi's involves the split-if transform.
1582   // FastLock is not used by an If
1583   if (n->is_Cmp() && !n->is_FastLock()) {
1584     Node *n_ctrl = get_ctrl(n);
1585     // Determine if the Node has inputs from some local Phi.
1586     // Returns the block to clone thru.
1587     Node *n_blk = has_local_phi_input(n);
1588     if (n_blk != n_ctrl) {
1589       return;
1590     }
1591 
1592     if (!can_split_if(n_ctrl)) {
1593       return;
1594     }
1595 
1596     if (n->outcnt() != 1) {
1597       return; // Multiple bool's from 1 compare?
1598     }
1599     Node *bol = n->unique_out();
1600     assert(bol->is_Bool(), "expect a bool here");

1704           //    accesses would start to float, since we don't pin at that point.
1705           // 3. If we move from regular if: don't pin. All array accesses are already assumed to be pinned.
1706           bool pin_array_access_nodes =  n->Opcode() == Op_RangeCheck &&
1707                                          prevdom->in(0)->Opcode() != Op_RangeCheck;
1708           dominated_by(prevdom->as_IfProj(), n->as_If(), false, pin_array_access_nodes);
1709           DEBUG_ONLY( if (VerifyLoopOptimizations) { verify(); } );
1710           return;
1711         }
1712         prevdom = dom;
1713         dom = idom(prevdom);
1714       }
1715     }
1716   }
1717 
1718   try_sink_out_of_loop(n);
1719   if (C->failing()) {
1720     return;
1721   }
1722 
1723   try_move_store_after_loop(n);
1724 
1725   // Remove multiple allocations of the same inline type
1726   if (n->is_InlineType()) {
1727     n->as_InlineType()->remove_redundant_allocations(this);
1728   }
1729 }
1730 
1731 // Transform:
1732 //
1733 // if (some_condition) {
1734 //   // body 1
1735 // } else {
1736 //   // body 2
1737 // }
1738 // if (some_condition) {
1739 //   // body 3
1740 // } else {
1741 //   // body 4
1742 // }
1743 //
1744 // into:
1745 //
1746 //
1747 // if (some_condition) {
1748 //   // body 1

2217   uint i;
2218   for (i = 1; i < phi->req(); i++) {
2219     Node* b = phi->in(i);
2220     if (b->is_Phi()) {
2221       _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2222     } else {
2223       assert(b->is_Bool() || b->is_OpaqueNotNull() || b->is_OpaqueInitializedAssertionPredicate(),
2224              "bool, non-null check with OpaqueNotNull or Initialized Assertion Predicate with its Opaque node");
2225     }
2226   }
2227   Node* n = phi->in(1);
2228   Node* sample_opaque = nullptr;
2229   Node *sample_bool = nullptr;
2230   if (n->is_OpaqueNotNull() || n->is_OpaqueInitializedAssertionPredicate()) {
2231     sample_opaque = n;
2232     sample_bool = n->in(1);
2233     assert(sample_bool->is_Bool(), "wrong type");
2234   } else {
2235     sample_bool = n;
2236   }
2237   Node* sample_cmp = sample_bool->in(1);
2238   const Type* t = Type::TOP;
2239   const TypePtr* at = nullptr;
2240   if (sample_cmp->is_FlatArrayCheck()) {
2241     // Left input of a FlatArrayCheckNode is memory, set the (adr) type of the phi accordingly
2242     assert(sample_cmp->in(1)->bottom_type() == Type::MEMORY, "unexpected input type");
2243     t = Type::MEMORY;
2244     at = TypeRawPtr::BOTTOM;
2245   }
2246 
2247   // Make Phis to merge the Cmp's inputs.
2248   PhiNode *phi1 = new PhiNode(phi->in(0), t, at);
2249   PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2250   for (i = 1; i < phi->req(); i++) {
2251     Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2252     Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2253     phi1->set_req(i, n1);
2254     phi2->set_req(i, n2);
2255     phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2256     phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2257   }
2258   // See if these Phis have been made before.
2259   // Register with optimizer
2260   Node *hit1 = _igvn.hash_find_insert(phi1);
2261   if (hit1) {                   // Hit, toss just made Phi
2262     _igvn.remove_dead_node(phi1); // Remove new phi
2263     assert(hit1->is_Phi(), "" );
2264     phi1 = (PhiNode*)hit1;      // Use existing phi
2265   } else {                      // Miss
2266     _igvn.register_new_node_with_optimizer(phi1);
2267   }
2268   Node *hit2 = _igvn.hash_find_insert(phi2);
< prev index next >