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

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

















































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






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

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
































































































1289 //------------------------------split_if_with_blocks_post----------------------
1290 // Do the real work in a non-recursive function.  CFG hackery wants to be
1291 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1292 // info.
1293 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1294 




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

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





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

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








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

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

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

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

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