< 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();

1099             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");
1100 
1101             // Move store out of the loop
1102             _igvn.replace_node(hook, n->in(MemNode::Memory));
1103             _igvn.replace_input_of(n, 0, lca);
1104             set_ctrl_and_loop(n, lca);
1105 
1106             // Disconnect the phi now. An empty phi can confuse other
1107             // optimizations in this pass of loop opts..
1108             if (phi->in(LoopNode::LoopBackControl) == phi) {
1109               _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1110               n_loop->_body.yank(phi);
1111             }
1112           }
1113         }
1114       }
1115     }
1116   }
1117 }
1118 
















































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






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

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








































































































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




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

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





1564 }
1565 
1566 // Transform:
1567 //
1568 // if (some_condition) {
1569 //   // body 1
1570 // } else {
1571 //   // body 2
1572 // }
1573 // if (some_condition) {
1574 //   // body 3
1575 // } else {
1576 //   // body 4
1577 // }
1578 //
1579 // into:
1580 //
1581 //
1582 // if (some_condition) {
1583 //   // body 1

2058   uint i;
2059   for (i = 1; i < phi->req(); i++) {
2060     Node* b = phi->in(i);
2061     if (b->is_Phi()) {
2062       _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2063     } else {
2064       assert(b->is_Bool() || b->is_OpaqueConstantBool() || b->is_OpaqueInitializedAssertionPredicate(),
2065              "bool, non-null check with OpaqueConstantBool or Initialized Assertion Predicate with its Opaque node");
2066     }
2067   }
2068   Node* n = phi->in(1);
2069   Node* sample_opaque = nullptr;
2070   Node *sample_bool = nullptr;
2071   if (n->is_OpaqueConstantBool() || n->is_OpaqueInitializedAssertionPredicate()) {
2072     sample_opaque = n;
2073     sample_bool = n->in(1);
2074     assert(sample_bool->is_Bool(), "wrong type");
2075   } else {
2076     sample_bool = n;
2077   }
2078   Node *sample_cmp = sample_bool->in(1);








2079 
2080   // Make Phis to merge the Cmp's inputs.
2081   PhiNode *phi1 = new PhiNode(phi->in(0), Type::TOP);
2082   PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2083   for (i = 1; i < phi->req(); i++) {
2084     Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2085     Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2086     phi1->set_req(i, n1);
2087     phi2->set_req(i, n2);
2088     phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2089     phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2090   }
2091   // See if these Phis have been made before.
2092   // Register with optimizer
2093   Node *hit1 = _igvn.hash_find_insert(phi1);
2094   if (hit1) {                   // Hit, toss just made Phi
2095     _igvn.remove_dead_node(phi1, PhaseIterGVN::NodeOrigin::Speculative); // Remove new phi
2096     assert(hit1->is_Phi(), "" );
2097     phi1 = (PhiNode*)hit1;      // Use existing phi
2098   } else {                      // Miss
2099     _igvn.register_new_node_with_optimizer(phi1);
2100   }
2101   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();

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

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

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

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