< prev index next >

src/hotspot/share/opto/loopopts.cpp

Print this page

  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 "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "memory/allocation.inline.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/castnode.hpp"
  35 #include "opto/divnode.hpp"

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






  64   // Bail out if 'n' is a Div or Mod node whose zero check was removed earlier (i.e. control is NULL) and its divisor is an induction variable
  65   // phi p of a trip-counted (integer) loop whose inputs could be zero (include zero in their type range). p could have a more precise type
  66   // range that does not necessarily include all values of its inputs. Since each of these inputs will be a divisor of the newly cloned nodes
  67   // of 'n', we need to bail out of one of these divisors could be zero (zero in its type range).
  68   if ((n->Opcode() == Op_DivI || n->Opcode() == Op_ModI) && n->in(0) == NULL
  69       && region->is_CountedLoop() && n->in(2) == region->as_CountedLoop()->phi()) {
  70     Node* phi = region->as_CountedLoop()->phi();
  71     for (uint i = 1; i < phi->req(); i++) {
  72       if (_igvn.type(phi->in(i))->filter_speculative(TypeInt::ZERO) != Type::TOP) {
  73         // Zero could be a possible value but we already removed the zero check. Bail out to avoid a possible division by zero at a later point.
  74         return NULL;
  75       }
  76     }
  77   }
  78 
  79   int wins = 0;
  80   assert(!n->is_CFG(), "");
  81   assert(region->is_Region(), "");
  82 
  83   const Type* type = n->bottom_type();

 977             assert(get_loop(lca)->_nest < n_loop->_nest || lca->in(0)->Opcode() == Op_NeverBranch, "must not be moved into inner loop");
 978 
 979             // Move store out of the loop
 980             _igvn.replace_node(hook, n->in(MemNode::Memory));
 981             _igvn.replace_input_of(n, 0, lca);
 982             set_ctrl_and_loop(n, lca);
 983 
 984             // Disconnect the phi now. An empty phi can confuse other
 985             // optimizations in this pass of loop opts..
 986             if (phi->in(LoopNode::LoopBackControl) == phi) {
 987               _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
 988               n_loop->_body.yank(phi);
 989             }
 990           }
 991         }
 992       }
 993     }
 994   }
 995 }
 996 

















































 997 //------------------------------split_if_with_blocks_pre-----------------------
 998 // Do the real work in a non-recursive function.  Data nodes want to be
 999 // cloned in the pre-order so they can feed each other nicely.
1000 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1001   // Cloning these guys is unlikely to win
1002   int n_op = n->Opcode();
1003   if (n_op == Op_MergeMem) {
1004     return n;
1005   }
1006   if (n->is_Proj()) {
1007     return n;
1008   }






1009   // Do not clone-up CmpFXXX variations, as these are always
1010   // followed by a CmpI
1011   if (n->is_Cmp()) {
1012     return n;
1013   }
1014   // Attempt to use a conditional move instead of a phi/branch
1015   if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1016     Node *cmov = conditional_move( n );
1017     if (cmov) {
1018       return cmov;
1019     }
1020   }
1021   if (n->is_CFG() || n->is_LoadStore()) {
1022     return n;
1023   }
1024   if (n->is_Opaque1() ||     // Opaque nodes cannot be mod'd
1025       n_op == Op_Opaque2) {
1026     if (!C->major_progress()) {   // If chance of no more loop opts...
1027       _igvn._worklist.push(n);  // maybe we'll remove them
1028     }

1262 
1263   return true;
1264 }
1265 
1266 // Detect if the node is the inner strip-mined loop
1267 // Return: NULL if it's not the case, or the exit of outer strip-mined loop
1268 static Node* is_inner_of_stripmined_loop(const Node* out) {
1269   Node* out_le = NULL;
1270 
1271   if (out->is_CountedLoopEnd()) {
1272       const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1273 
1274       if (loop != NULL && loop->is_strip_mined()) {
1275         out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1276       }
1277   }
1278 
1279   return out_le;
1280 }
1281 
































































































1282 //------------------------------split_if_with_blocks_post----------------------
1283 // Do the real work in a non-recursive function.  CFG hackery wants to be
1284 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1285 // info.
1286 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1287 




1288   // Cloning Cmp through Phi's involves the split-if transform.
1289   // FastLock is not used by an If
1290   if (n->is_Cmp() && !n->is_FastLock()) {
1291     Node *n_ctrl = get_ctrl(n);
1292     // Determine if the Node has inputs from some local Phi.
1293     // Returns the block to clone thru.
1294     Node *n_blk = has_local_phi_input(n);
1295     if (n_blk != n_ctrl) {
1296       return;
1297     }
1298 
1299     if (!can_split_if(n_ctrl)) {
1300       return;
1301     }
1302 
1303     if (n->outcnt() != 1) {
1304       return; // Multiple bool's from 1 compare?
1305     }
1306     Node *bol = n->unique_out();
1307     assert(bol->is_Bool(), "expect a bool here");

1403           }
1404           // Replace the dominated test with an obvious true or false.
1405           // Place it on the IGVN worklist for later cleanup.
1406           C->set_major_progress();
1407           dominated_by(prevdom->as_IfProj(), n->as_If(), false, true);
1408 #ifndef PRODUCT
1409           if( VerifyLoopOptimizations ) verify();
1410 #endif
1411           return;
1412         }
1413         prevdom = dom;
1414         dom = idom(prevdom);
1415       }
1416     }
1417   }
1418 
1419   try_sink_out_of_loop(n);
1420 
1421   try_move_store_after_loop(n);
1422 





1423   // Check for Opaque2's who's loop has disappeared - who's input is in the
1424   // same loop nest as their output.  Remove 'em, they are no longer useful.
1425   if( n_op == Op_Opaque2 &&
1426       n->in(1) != NULL &&
1427       get_loop(get_ctrl(n)) == get_loop(get_ctrl(n->in(1))) ) {
1428     _igvn.replace_node( n, n->in(1) );
1429   }
1430 }
1431 
1432 // Tranform:
1433 //
1434 // if (some_condition) {
1435 //   // body 1
1436 // } else {
1437 //   // body 2
1438 // }
1439 // if (some_condition) {
1440 //   // body 3
1441 // } else {
1442 //   // body 4

1842   uint i;
1843   for (i = 1; i < phi->req(); i++) {
1844     Node *b = phi->in(i);
1845     if (b->is_Phi()) {
1846       _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi(), loop));
1847     } else {
1848       assert(b->is_Bool() || b->Opcode() == Op_Opaque4, "");
1849     }
1850   }
1851 
1852   Node* n = phi->in(1);
1853   Node* sample_opaque = NULL;
1854   Node *sample_bool = NULL;
1855   if (n->Opcode() == Op_Opaque4) {
1856     sample_opaque = n;
1857     sample_bool = n->in(1);
1858     assert(sample_bool->is_Bool(), "wrong type");
1859   } else {
1860     sample_bool = n;
1861   }
1862   Node *sample_cmp = sample_bool->in(1);








1863 
1864   // Make Phis to merge the Cmp's inputs.
1865   PhiNode *phi1 = new PhiNode(phi->in(0), Type::TOP);
1866   PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
1867   for (i = 1; i < phi->req(); i++) {
1868     Node *n1 = sample_opaque == NULL ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
1869     Node *n2 = sample_opaque == NULL ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
1870     phi1->set_req(i, n1);
1871     phi2->set_req(i, n2);
1872     phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
1873     phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
1874   }
1875   // See if these Phis have been made before.
1876   // Register with optimizer
1877   Node *hit1 = _igvn.hash_find_insert(phi1);
1878   if (hit1) {                   // Hit, toss just made Phi
1879     _igvn.remove_dead_node(phi1); // Remove new phi
1880     assert(hit1->is_Phi(), "" );
1881     phi1 = (PhiNode*)hit1;      // Use existing phi
1882   } else {                      // Miss
1883     _igvn.register_new_node_with_optimizer(phi1);
1884   }
1885   Node *hit2 = _igvn.hash_find_insert(phi2);

  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 "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/c2/barrierSetC2.hpp"
  28 #include "memory/allocation.inline.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/castnode.hpp"
  35 #include "opto/divnode.hpp"
  36 #include "opto/inlinetypenode.hpp"
  37 #include "opto/loopnode.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/mulnode.hpp"
  40 #include "opto/movenode.hpp"
  41 #include "opto/opaquenode.hpp"
  42 #include "opto/rootnode.hpp"
  43 #include "opto/subnode.hpp"
  44 #include "opto/subtypenode.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     // ConvI2L may have type information on it which is unsafe to push up
  53     // so disable this for now
  54     return NULL;
  55   }
  56 
  57   // Splitting range check CastIIs through a loop induction Phi can
  58   // cause new Phis to be created that are left unrelated to the loop
  59   // induction Phi and prevent optimizations (vectorization)
  60   if (n->Opcode() == Op_CastII && region->is_CountedLoop() &&
  61       n->in(1) == region->as_CountedLoop()->phi()) {
  62     return NULL;
  63   }
  64 
  65   // Inline types should not be split through Phis because they cannot be merged
  66   // through Phi nodes but each value input needs to be merged individually.
  67   if (n->is_InlineType()) {
  68     return NULL;
  69   }
  70 
  71   // Bail out if 'n' is a Div or Mod node whose zero check was removed earlier (i.e. control is NULL) and its divisor is an induction variable
  72   // phi p of a trip-counted (integer) loop whose inputs could be zero (include zero in their type range). p could have a more precise type
  73   // range that does not necessarily include all values of its inputs. Since each of these inputs will be a divisor of the newly cloned nodes
  74   // of 'n', we need to bail out of one of these divisors could be zero (zero in its type range).
  75   if ((n->Opcode() == Op_DivI || n->Opcode() == Op_ModI) && n->in(0) == NULL
  76       && region->is_CountedLoop() && n->in(2) == region->as_CountedLoop()->phi()) {
  77     Node* phi = region->as_CountedLoop()->phi();
  78     for (uint i = 1; i < phi->req(); i++) {
  79       if (_igvn.type(phi->in(i))->filter_speculative(TypeInt::ZERO) != Type::TOP) {
  80         // Zero could be a possible value but we already removed the zero check. Bail out to avoid a possible division by zero at a later point.
  81         return NULL;
  82       }
  83     }
  84   }
  85 
  86   int wins = 0;
  87   assert(!n->is_CFG(), "");
  88   assert(region->is_Region(), "");
  89 
  90   const Type* type = n->bottom_type();

 984             assert(get_loop(lca)->_nest < n_loop->_nest || lca->in(0)->Opcode() == Op_NeverBranch, "must not be moved into inner loop");
 985 
 986             // Move store out of the loop
 987             _igvn.replace_node(hook, n->in(MemNode::Memory));
 988             _igvn.replace_input_of(n, 0, lca);
 989             set_ctrl_and_loop(n, lca);
 990 
 991             // Disconnect the phi now. An empty phi can confuse other
 992             // optimizations in this pass of loop opts..
 993             if (phi->in(LoopNode::LoopBackControl) == phi) {
 994               _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
 995               n_loop->_body.yank(phi);
 996             }
 997           }
 998         }
 999       }
1000     }
1001   }
1002 }
1003 
1004 // If UseArrayMarkWordCheck is enabled, we can't use immutable memory for the flat array check
1005 // because we are loading the mark word which is mutable. Although the bits we are interested in
1006 // are immutable (we check for markWord::unlocked_value), we need to use raw memory to not break
1007 // anti dependency analysis. Below code will attempt to still move flat array checks out of loops,
1008 // mainly to enable loop unswitching.
1009 void PhaseIdealLoop::move_flat_array_check_out_of_loop(Node* n) {
1010   // Skip checks for more than one array
1011   if (n->req() > 3) {
1012     return;
1013   }
1014   Node* mem = n->in(FlatArrayCheckNode::Memory);
1015   Node* array = n->in(FlatArrayCheckNode::ArrayOrKlass)->uncast();
1016   IdealLoopTree* check_loop = get_loop(get_ctrl(n));
1017   IdealLoopTree* ary_loop = get_loop(get_ctrl(array));
1018 
1019   // Check if array is loop invariant
1020   if (!check_loop->is_member(ary_loop)) {
1021     // Walk up memory graph from the check until we leave the loop
1022     VectorSet wq;
1023     wq.set(mem->_idx);
1024     while (check_loop->is_member(get_loop(ctrl_or_self(mem)))) {
1025       if (mem->is_Phi()) {
1026         mem = mem->in(1);
1027       } else if (mem->is_MergeMem()) {
1028         mem = mem->as_MergeMem()->memory_at(Compile::AliasIdxRaw);
1029       } else if (mem->is_Proj()) {
1030         mem = mem->in(0);
1031       } else if (mem->is_MemBar() || mem->is_SafePoint()) {
1032         mem = mem->in(TypeFunc::Memory);
1033       } else if (mem->is_Store() || mem->is_LoadStore() || mem->is_ClearArray()) {
1034         mem = mem->in(MemNode::Memory);
1035       } else {
1036 #ifdef ASSERT
1037         mem->dump();
1038 #endif
1039         ShouldNotReachHere();
1040       }
1041       if (wq.test_set(mem->_idx)) {
1042         return;
1043       }
1044     }
1045     // Replace memory input and re-compute ctrl to move the check out of the loop
1046     _igvn.replace_input_of(n, 1, mem);
1047     set_ctrl_and_loop(n, get_early_ctrl(n));
1048     Node* bol = n->unique_out();
1049     set_ctrl_and_loop(bol, get_early_ctrl(bol));
1050   }
1051 }
1052 
1053 //------------------------------split_if_with_blocks_pre-----------------------
1054 // Do the real work in a non-recursive function.  Data nodes want to be
1055 // cloned in the pre-order so they can feed each other nicely.
1056 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1057   // Cloning these guys is unlikely to win
1058   int n_op = n->Opcode();
1059   if (n_op == Op_MergeMem) {
1060     return n;
1061   }
1062   if (n->is_Proj()) {
1063     return n;
1064   }
1065 
1066   if (UseArrayMarkWordCheck && n->isa_FlatArrayCheck()) {
1067     move_flat_array_check_out_of_loop(n);
1068     return n;
1069   }
1070 
1071   // Do not clone-up CmpFXXX variations, as these are always
1072   // followed by a CmpI
1073   if (n->is_Cmp()) {
1074     return n;
1075   }
1076   // Attempt to use a conditional move instead of a phi/branch
1077   if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1078     Node *cmov = conditional_move( n );
1079     if (cmov) {
1080       return cmov;
1081     }
1082   }
1083   if (n->is_CFG() || n->is_LoadStore()) {
1084     return n;
1085   }
1086   if (n->is_Opaque1() ||     // Opaque nodes cannot be mod'd
1087       n_op == Op_Opaque2) {
1088     if (!C->major_progress()) {   // If chance of no more loop opts...
1089       _igvn._worklist.push(n);  // maybe we'll remove them
1090     }

1324 
1325   return true;
1326 }
1327 
1328 // Detect if the node is the inner strip-mined loop
1329 // Return: NULL if it's not the case, or the exit of outer strip-mined loop
1330 static Node* is_inner_of_stripmined_loop(const Node* out) {
1331   Node* out_le = NULL;
1332 
1333   if (out->is_CountedLoopEnd()) {
1334       const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1335 
1336       if (loop != NULL && loop->is_strip_mined()) {
1337         out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1338       }
1339   }
1340 
1341   return out_le;
1342 }
1343 
1344 bool PhaseIdealLoop::flatten_array_element_type_check(Node *n) {
1345   // If the CmpP is a subtype check for a value that has just been
1346   // loaded from an array, the subtype check guarantees the value
1347   // can't be stored in a flattened array and the load of the value
1348   // happens with a flattened array check then: push the type check
1349   // through the phi of the flattened array check. This needs special
1350   // logic because the subtype check's input is not a phi but a
1351   // LoadKlass that must first be cloned through the phi.
1352   if (n->Opcode() != Op_CmpP) {
1353     return false;
1354   }
1355 
1356   Node* klassptr = n->in(1);
1357   Node* klasscon = n->in(2);
1358 
1359   if (klassptr->is_DecodeNarrowPtr()) {
1360     klassptr = klassptr->in(1);
1361   }
1362 
1363   if (klassptr->Opcode() != Op_LoadKlass && klassptr->Opcode() != Op_LoadNKlass) {
1364     return false;
1365   }
1366 
1367   if (!klasscon->is_Con()) {
1368     return false;
1369   }
1370 
1371   Node* addr = klassptr->in(MemNode::Address);
1372 
1373   if (!addr->is_AddP()) {
1374     return false;
1375   }
1376 
1377   intptr_t offset;
1378   Node* obj = AddPNode::Ideal_base_and_offset(addr, &_igvn, offset);
1379 
1380   if (obj == NULL) {
1381     return false;
1382   }
1383 
1384   assert(obj != NULL && addr->in(AddPNode::Base) == addr->in(AddPNode::Address), "malformed AddP?");
1385   if (obj->Opcode() == Op_CastPP) {
1386     obj = obj->in(1);
1387   }
1388 
1389   if (!obj->is_Phi()) {
1390     return false;
1391   }
1392 
1393   Node* region = obj->in(0);
1394 
1395   Node* phi = PhiNode::make_blank(region, n->in(1));
1396   for (uint i = 1; i < region->req(); i++) {
1397     Node* in = obj->in(i);
1398     Node* ctrl = region->in(i);
1399     if (addr->in(AddPNode::Base) != obj) {
1400       Node* cast = addr->in(AddPNode::Base);
1401       assert(cast->Opcode() == Op_CastPP && cast->in(0) != NULL, "inconsistent subgraph");
1402       Node* cast_clone = cast->clone();
1403       cast_clone->set_req(0, ctrl);
1404       cast_clone->set_req(1, in);
1405       register_new_node(cast_clone, ctrl);
1406       _igvn.set_type(cast_clone, cast_clone->Value(&_igvn));
1407       in = cast_clone;
1408     }
1409     Node* addr_clone = addr->clone();
1410     addr_clone->set_req(AddPNode::Base, in);
1411     addr_clone->set_req(AddPNode::Address, in);
1412     register_new_node(addr_clone, ctrl);
1413     _igvn.set_type(addr_clone, addr_clone->Value(&_igvn));
1414     Node* klassptr_clone = klassptr->clone();
1415     klassptr_clone->set_req(2, addr_clone);
1416     register_new_node(klassptr_clone, ctrl);
1417     _igvn.set_type(klassptr_clone, klassptr_clone->Value(&_igvn));
1418     if (klassptr != n->in(1)) {
1419       Node* decode = n->in(1);
1420       assert(decode->is_DecodeNarrowPtr(), "inconsistent subgraph");
1421       Node* decode_clone = decode->clone();
1422       decode_clone->set_req(1, klassptr_clone);
1423       register_new_node(decode_clone, ctrl);
1424       _igvn.set_type(decode_clone, decode_clone->Value(&_igvn));
1425       klassptr_clone = decode_clone;
1426     }
1427     phi->set_req(i, klassptr_clone);
1428   }
1429   register_new_node(phi, region);
1430   Node* orig = n->in(1);
1431   _igvn.replace_input_of(n, 1, phi);
1432   split_if_with_blocks_post(n);
1433   if (n->outcnt() != 0) {
1434     _igvn.replace_input_of(n, 1, orig);
1435     _igvn.remove_dead_node(phi);
1436   }
1437   return true;
1438 }
1439 
1440 //------------------------------split_if_with_blocks_post----------------------
1441 // Do the real work in a non-recursive function.  CFG hackery wants to be
1442 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1443 // info.
1444 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1445 
1446   if (flatten_array_element_type_check(n)) {
1447     return;
1448   }
1449 
1450   // Cloning Cmp through Phi's involves the split-if transform.
1451   // FastLock is not used by an If
1452   if (n->is_Cmp() && !n->is_FastLock()) {
1453     Node *n_ctrl = get_ctrl(n);
1454     // Determine if the Node has inputs from some local Phi.
1455     // Returns the block to clone thru.
1456     Node *n_blk = has_local_phi_input(n);
1457     if (n_blk != n_ctrl) {
1458       return;
1459     }
1460 
1461     if (!can_split_if(n_ctrl)) {
1462       return;
1463     }
1464 
1465     if (n->outcnt() != 1) {
1466       return; // Multiple bool's from 1 compare?
1467     }
1468     Node *bol = n->unique_out();
1469     assert(bol->is_Bool(), "expect a bool here");

1565           }
1566           // Replace the dominated test with an obvious true or false.
1567           // Place it on the IGVN worklist for later cleanup.
1568           C->set_major_progress();
1569           dominated_by(prevdom->as_IfProj(), n->as_If(), false, true);
1570 #ifndef PRODUCT
1571           if( VerifyLoopOptimizations ) verify();
1572 #endif
1573           return;
1574         }
1575         prevdom = dom;
1576         dom = idom(prevdom);
1577       }
1578     }
1579   }
1580 
1581   try_sink_out_of_loop(n);
1582 
1583   try_move_store_after_loop(n);
1584 
1585   // Remove multiple allocations of the same inline type
1586   if (n->is_InlineType()) {
1587     n->as_InlineType()->remove_redundant_allocations(&_igvn, this);
1588   }
1589 
1590   // Check for Opaque2's who's loop has disappeared - who's input is in the
1591   // same loop nest as their output.  Remove 'em, they are no longer useful.
1592   if( n_op == Op_Opaque2 &&
1593       n->in(1) != NULL &&
1594       get_loop(get_ctrl(n)) == get_loop(get_ctrl(n->in(1))) ) {
1595     _igvn.replace_node( n, n->in(1) );
1596   }
1597 }
1598 
1599 // Tranform:
1600 //
1601 // if (some_condition) {
1602 //   // body 1
1603 // } else {
1604 //   // body 2
1605 // }
1606 // if (some_condition) {
1607 //   // body 3
1608 // } else {
1609 //   // body 4

2009   uint i;
2010   for (i = 1; i < phi->req(); i++) {
2011     Node *b = phi->in(i);
2012     if (b->is_Phi()) {
2013       _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi(), loop));
2014     } else {
2015       assert(b->is_Bool() || b->Opcode() == Op_Opaque4, "");
2016     }
2017   }
2018 
2019   Node* n = phi->in(1);
2020   Node* sample_opaque = NULL;
2021   Node *sample_bool = NULL;
2022   if (n->Opcode() == Op_Opaque4) {
2023     sample_opaque = n;
2024     sample_bool = n->in(1);
2025     assert(sample_bool->is_Bool(), "wrong type");
2026   } else {
2027     sample_bool = n;
2028   }
2029   Node* sample_cmp = sample_bool->in(1);
2030   const Type* t = Type::TOP;
2031   const TypePtr* at = NULL;
2032   if (sample_cmp->is_FlatArrayCheck()) {
2033     // Left input of a FlatArrayCheckNode is memory, set the (adr) type of the phi accordingly
2034     assert(sample_cmp->in(1)->bottom_type() == Type::MEMORY, "unexpected input type");
2035     t = Type::MEMORY;
2036     at = TypeRawPtr::BOTTOM;
2037   }
2038 
2039   // Make Phis to merge the Cmp's inputs.
2040   PhiNode *phi1 = new PhiNode(phi->in(0), t, at);
2041   PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2042   for (i = 1; i < phi->req(); i++) {
2043     Node *n1 = sample_opaque == NULL ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2044     Node *n2 = sample_opaque == NULL ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2045     phi1->set_req(i, n1);
2046     phi2->set_req(i, n2);
2047     phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2048     phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2049   }
2050   // See if these Phis have been made before.
2051   // Register with optimizer
2052   Node *hit1 = _igvn.hash_find_insert(phi1);
2053   if (hit1) {                   // Hit, toss just made Phi
2054     _igvn.remove_dead_node(phi1); // Remove new phi
2055     assert(hit1->is_Phi(), "" );
2056     phi1 = (PhiNode*)hit1;      // Use existing phi
2057   } else {                      // Miss
2058     _igvn.register_new_node_with_optimizer(phi1);
2059   }
2060   Node *hit2 = _igvn.hash_find_insert(phi2);
< prev index next >