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/castnode.hpp"
34 #include "opto/divnode.hpp"
35 #include "opto/loopnode.hpp"
36 #include "opto/matcher.hpp"
37 #include "opto/mulnode.hpp"
38 #include "opto/movenode.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/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 int wins = 0;
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();
743 // CMOVE'd derived pointer? It's a CMOVE'd derived base. Thus
744 // CMOVE'ing a derived pointer requires we also CMOVE the base. If we
745 // have a Phi for the base here that we convert to a CMOVE all is well
746 // and good. But if the base is dead, we'll not make a CMOVE. Later
747 // the allocator will have to produce a base by creating a CMOVE of the
748 // relevant bases. This puts the allocator in the business of
749 // manufacturing expensive instructions, generally a bad plan.
750 // Just Say No to Conditionally-Moved Derived Pointers.
751 if (tp && tp->offset() != 0)
752 return nullptr;
753 cost++;
754 break;
755 }
756 default:
757 return nullptr; // In particular, can't do memory or I/O
758 }
759 // Add in cost any speculative ops
760 for (uint j = 1; j < region->req(); j++) {
761 Node *proj = region->in(j);
762 Node *inp = phi->in(j);
763 if (get_ctrl(inp) == proj) { // Found local op
764 cost++;
765 // Check for a chain of dependent ops; these will all become
766 // speculative in a CMOV.
767 for (uint k = 1; k < inp->req(); k++)
768 if (get_ctrl(inp->in(k)) == proj)
769 cost += ConditionalMoveLimit; // Too much speculative goo
770 }
771 }
772 // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
773 // This will likely Split-If, a higher-payoff operation.
774 for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
775 Node* use = phi->fast_out(k);
776 if (use->is_Cmp() || use->is_DecodeNarrowPtr() || use->is_EncodeNarrowPtr())
777 cost += ConditionalMoveLimit;
778 // Is there a use inside the loop?
779 // Note: check only basic types since CMoveP is pinned.
780 if (!used_inside_loop && is_java_primitive(bt)) {
781 IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
782 if (r_loop == u_loop || r_loop->is_member(u_loop)) {
1072 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");
1073
1074 // Move store out of the loop
1075 _igvn.replace_node(hook, n->in(MemNode::Memory));
1076 _igvn.replace_input_of(n, 0, lca);
1077 set_ctrl_and_loop(n, lca);
1078
1079 // Disconnect the phi now. An empty phi can confuse other
1080 // optimizations in this pass of loop opts..
1081 if (phi->in(LoopNode::LoopBackControl) == phi) {
1082 _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1083 n_loop->_body.yank(phi);
1084 }
1085 }
1086 }
1087 }
1088 }
1089 }
1090 }
1091
1092 //------------------------------split_if_with_blocks_pre-----------------------
1093 // Do the real work in a non-recursive function. Data nodes want to be
1094 // cloned in the pre-order so they can feed each other nicely.
1095 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1096 // Cloning these guys is unlikely to win
1097 int n_op = n->Opcode();
1098 if (n_op == Op_MergeMem) {
1099 return n;
1100 }
1101 if (n->is_Proj()) {
1102 return n;
1103 }
1104 // Do not clone-up CmpFXXX variations, as these are always
1105 // followed by a CmpI
1106 if (n->is_Cmp()) {
1107 return n;
1108 }
1109 // Attempt to use a conditional move instead of a phi/branch
1110 if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1111 Node *cmov = conditional_move( n );
1112 if (cmov) {
1113 return cmov;
1114 }
1115 }
1116 if (n->is_CFG() || n->is_LoadStore()) {
1117 return n;
1118 }
1119 if (n->is_Opaque1()) { // Opaque nodes cannot be mod'd
1120 if (!C->major_progress()) { // If chance of no more loop opts...
1121 _igvn._worklist.push(n); // maybe we'll remove them
1122 }
1123 return n;
1359
1360 return true;
1361 }
1362
1363 // Detect if the node is the inner strip-mined loop
1364 // Return: null if it's not the case, or the exit of outer strip-mined loop
1365 static Node* is_inner_of_stripmined_loop(const Node* out) {
1366 Node* out_le = nullptr;
1367
1368 if (out->is_CountedLoopEnd()) {
1369 const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1370
1371 if (loop != nullptr && loop->is_strip_mined()) {
1372 out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1373 }
1374 }
1375
1376 return out_le;
1377 }
1378
1379 //------------------------------split_if_with_blocks_post----------------------
1380 // Do the real work in a non-recursive function. CFG hackery wants to be
1381 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1382 // info.
1383 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1384
1385 // Cloning Cmp through Phi's involves the split-if transform.
1386 // FastLock is not used by an If
1387 if (n->is_Cmp() && !n->is_FastLock()) {
1388 Node *n_ctrl = get_ctrl(n);
1389 // Determine if the Node has inputs from some local Phi.
1390 // Returns the block to clone thru.
1391 Node *n_blk = has_local_phi_input(n);
1392 if (n_blk != n_ctrl) {
1393 return;
1394 }
1395
1396 if (!can_split_if(n_ctrl)) {
1397 return;
1398 }
1399
1400 if (n->outcnt() != 1) {
1401 return; // Multiple bool's from 1 compare?
1402 }
1403 Node *bol = n->unique_out();
1404 assert(bol->is_Bool(), "expect a bool here");
1515 // accesses would start to float, since we don't pin at that point.
1516 // 3. If we move from regular if: don't pin. All array accesses are already assumed to be pinned.
1517 bool pin_array_access_nodes = n->Opcode() == Op_RangeCheck &&
1518 prevdom->in(0)->Opcode() != Op_RangeCheck;
1519 dominated_by(prevdom->as_IfProj(), n->as_If(), false, pin_array_access_nodes);
1520 DEBUG_ONLY( if (VerifyLoopOptimizations) { verify(); } );
1521 return;
1522 }
1523 prevdom = dom;
1524 dom = idom(prevdom);
1525 }
1526 }
1527 }
1528
1529 try_sink_out_of_loop(n);
1530 if (C->failing()) {
1531 return;
1532 }
1533
1534 try_move_store_after_loop(n);
1535 }
1536
1537 // Transform:
1538 //
1539 // if (some_condition) {
1540 // // body 1
1541 // } else {
1542 // // body 2
1543 // }
1544 // if (some_condition) {
1545 // // body 3
1546 // } else {
1547 // // body 4
1548 // }
1549 //
1550 // into:
1551 //
1552 //
1553 // if (some_condition) {
1554 // // body 1
2006 uint i;
2007 for (i = 1; i < phi->req(); i++) {
2008 Node* b = phi->in(i);
2009 if (b->is_Phi()) {
2010 _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2011 } else {
2012 assert(b->is_Bool() || b->is_OpaqueNotNull() || b->is_OpaqueInitializedAssertionPredicate(),
2013 "bool, non-null check with OpaqueNotNull or Initialized Assertion Predicate with its Opaque node");
2014 }
2015 }
2016 Node* n = phi->in(1);
2017 Node* sample_opaque = nullptr;
2018 Node *sample_bool = nullptr;
2019 if (n->is_OpaqueNotNull() || n->is_OpaqueInitializedAssertionPredicate()) {
2020 sample_opaque = n;
2021 sample_bool = n->in(1);
2022 assert(sample_bool->is_Bool(), "wrong type");
2023 } else {
2024 sample_bool = n;
2025 }
2026 Node *sample_cmp = sample_bool->in(1);
2027
2028 // Make Phis to merge the Cmp's inputs.
2029 PhiNode *phi1 = new PhiNode(phi->in(0), Type::TOP);
2030 PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2031 for (i = 1; i < phi->req(); i++) {
2032 Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2033 Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2034 phi1->set_req(i, n1);
2035 phi2->set_req(i, n2);
2036 phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2037 phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2038 }
2039 // See if these Phis have been made before.
2040 // Register with optimizer
2041 Node *hit1 = _igvn.hash_find_insert(phi1);
2042 if (hit1) { // Hit, toss just made Phi
2043 _igvn.remove_dead_node(phi1); // Remove new phi
2044 assert(hit1->is_Phi(), "" );
2045 phi1 = (PhiNode*)hit1; // Use existing phi
2046 } else { // Miss
2047 _igvn.register_new_node_with_optimizer(phi1);
2048 }
2049 Node *hit2 = _igvn.hash_find_insert(phi2);
|
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/castnode.hpp"
34 #include "opto/divnode.hpp"
35 #include "opto/inlinetypenode.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 "opto/superword.hpp"
45 #include "opto/vectornode.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 int wins = 0;
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();
750 // CMOVE'd derived pointer? It's a CMOVE'd derived base. Thus
751 // CMOVE'ing a derived pointer requires we also CMOVE the base. If we
752 // have a Phi for the base here that we convert to a CMOVE all is well
753 // and good. But if the base is dead, we'll not make a CMOVE. Later
754 // the allocator will have to produce a base by creating a CMOVE of the
755 // relevant bases. This puts the allocator in the business of
756 // manufacturing expensive instructions, generally a bad plan.
757 // Just Say No to Conditionally-Moved Derived Pointers.
758 if (tp && tp->offset() != 0)
759 return nullptr;
760 cost++;
761 break;
762 }
763 default:
764 return nullptr; // In particular, can't do memory or I/O
765 }
766 // Add in cost any speculative ops
767 for (uint j = 1; j < region->req(); j++) {
768 Node *proj = region->in(j);
769 Node *inp = phi->in(j);
770 if (inp->isa_InlineType()) {
771 // TODO 8302217 This prevents PhiNode::push_inline_types_through
772 return nullptr;
773 }
774 if (get_ctrl(inp) == proj) { // Found local op
775 cost++;
776 // Check for a chain of dependent ops; these will all become
777 // speculative in a CMOV.
778 for (uint k = 1; k < inp->req(); k++)
779 if (get_ctrl(inp->in(k)) == proj)
780 cost += ConditionalMoveLimit; // Too much speculative goo
781 }
782 }
783 // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
784 // This will likely Split-If, a higher-payoff operation.
785 for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
786 Node* use = phi->fast_out(k);
787 if (use->is_Cmp() || use->is_DecodeNarrowPtr() || use->is_EncodeNarrowPtr())
788 cost += ConditionalMoveLimit;
789 // Is there a use inside the loop?
790 // Note: check only basic types since CMoveP is pinned.
791 if (!used_inside_loop && is_java_primitive(bt)) {
792 IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
793 if (r_loop == u_loop || r_loop->is_member(u_loop)) {
1083 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");
1084
1085 // Move store out of the loop
1086 _igvn.replace_node(hook, n->in(MemNode::Memory));
1087 _igvn.replace_input_of(n, 0, lca);
1088 set_ctrl_and_loop(n, lca);
1089
1090 // Disconnect the phi now. An empty phi can confuse other
1091 // optimizations in this pass of loop opts..
1092 if (phi->in(LoopNode::LoopBackControl) == phi) {
1093 _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1094 n_loop->_body.yank(phi);
1095 }
1096 }
1097 }
1098 }
1099 }
1100 }
1101 }
1102
1103 // We can't use immutable memory for the flat array check because we are loading the mark word which is
1104 // mutable. Although the bits we are interested in are immutable (we check for markWord::unlocked_value),
1105 // we need to use raw memory to not break anti dependency analysis. Below code will attempt to still move
1106 // flat array checks out of loops, mainly to enable loop unswitching.
1107 void PhaseIdealLoop::move_flat_array_check_out_of_loop(Node* n) {
1108 // Skip checks for more than one array
1109 if (n->req() > 3) {
1110 return;
1111 }
1112 Node* mem = n->in(FlatArrayCheckNode::Memory);
1113 Node* array = n->in(FlatArrayCheckNode::ArrayOrKlass)->uncast();
1114 IdealLoopTree* check_loop = get_loop(get_ctrl(n));
1115 IdealLoopTree* ary_loop = get_loop(get_ctrl(array));
1116
1117 // Check if array is loop invariant
1118 if (!check_loop->is_member(ary_loop)) {
1119 // Walk up memory graph from the check until we leave the loop
1120 VectorSet wq;
1121 wq.set(mem->_idx);
1122 while (check_loop->is_member(get_loop(ctrl_or_self(mem)))) {
1123 if (mem->is_Phi()) {
1124 mem = mem->in(1);
1125 } else if (mem->is_MergeMem()) {
1126 mem = mem->as_MergeMem()->memory_at(Compile::AliasIdxRaw);
1127 } else if (mem->is_Proj()) {
1128 mem = mem->in(0);
1129 } else if (mem->is_MemBar() || mem->is_SafePoint()) {
1130 mem = mem->in(TypeFunc::Memory);
1131 } else if (mem->is_Store() || mem->is_LoadStore() || mem->is_ClearArray()) {
1132 mem = mem->in(MemNode::Memory);
1133 } else {
1134 #ifdef ASSERT
1135 mem->dump();
1136 #endif
1137 ShouldNotReachHere();
1138 }
1139 if (wq.test_set(mem->_idx)) {
1140 return;
1141 }
1142 }
1143 // Replace memory input and re-compute ctrl to move the check out of the loop
1144 _igvn.replace_input_of(n, 1, mem);
1145 set_ctrl_and_loop(n, get_early_ctrl(n));
1146 Node* bol = n->unique_out();
1147 set_ctrl_and_loop(bol, get_early_ctrl(bol));
1148 }
1149 }
1150
1151 //------------------------------split_if_with_blocks_pre-----------------------
1152 // Do the real work in a non-recursive function. Data nodes want to be
1153 // cloned in the pre-order so they can feed each other nicely.
1154 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1155 // Cloning these guys is unlikely to win
1156 int n_op = n->Opcode();
1157 if (n_op == Op_MergeMem) {
1158 return n;
1159 }
1160 if (n->is_Proj()) {
1161 return n;
1162 }
1163
1164 if (n->isa_FlatArrayCheck()) {
1165 move_flat_array_check_out_of_loop(n);
1166 return n;
1167 }
1168
1169 // Do not clone-up CmpFXXX variations, as these are always
1170 // followed by a CmpI
1171 if (n->is_Cmp()) {
1172 return n;
1173 }
1174 // Attempt to use a conditional move instead of a phi/branch
1175 if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1176 Node *cmov = conditional_move( n );
1177 if (cmov) {
1178 return cmov;
1179 }
1180 }
1181 if (n->is_CFG() || n->is_LoadStore()) {
1182 return n;
1183 }
1184 if (n->is_Opaque1()) { // Opaque nodes cannot be mod'd
1185 if (!C->major_progress()) { // If chance of no more loop opts...
1186 _igvn._worklist.push(n); // maybe we'll remove them
1187 }
1188 return n;
1424
1425 return true;
1426 }
1427
1428 // Detect if the node is the inner strip-mined loop
1429 // Return: null if it's not the case, or the exit of outer strip-mined loop
1430 static Node* is_inner_of_stripmined_loop(const Node* out) {
1431 Node* out_le = nullptr;
1432
1433 if (out->is_CountedLoopEnd()) {
1434 const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1435
1436 if (loop != nullptr && loop->is_strip_mined()) {
1437 out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1438 }
1439 }
1440
1441 return out_le;
1442 }
1443
1444 bool PhaseIdealLoop::flat_array_element_type_check(Node *n) {
1445 // If the CmpP is a subtype check for a value that has just been
1446 // loaded from an array, the subtype check guarantees the value
1447 // can't be stored in a flat array and the load of the value
1448 // happens with a flat array check then: push the type check
1449 // through the phi of the flat array check. This needs special
1450 // logic because the subtype check's input is not a phi but a
1451 // LoadKlass that must first be cloned through the phi.
1452 if (n->Opcode() != Op_CmpP) {
1453 return false;
1454 }
1455
1456 Node* klassptr = n->in(1);
1457 Node* klasscon = n->in(2);
1458
1459 if (klassptr->is_DecodeNarrowPtr()) {
1460 klassptr = klassptr->in(1);
1461 }
1462
1463 if (klassptr->Opcode() != Op_LoadKlass && klassptr->Opcode() != Op_LoadNKlass) {
1464 return false;
1465 }
1466
1467 if (!klasscon->is_Con()) {
1468 return false;
1469 }
1470
1471 Node* addr = klassptr->in(MemNode::Address);
1472
1473 if (!addr->is_AddP()) {
1474 return false;
1475 }
1476
1477 intptr_t offset;
1478 Node* obj = AddPNode::Ideal_base_and_offset(addr, &_igvn, offset);
1479
1480 if (obj == nullptr) {
1481 return false;
1482 }
1483
1484 assert(obj != nullptr && addr->in(AddPNode::Base) == addr->in(AddPNode::Address), "malformed AddP?");
1485 if (obj->Opcode() == Op_CastPP) {
1486 obj = obj->in(1);
1487 }
1488
1489 if (!obj->is_Phi()) {
1490 return false;
1491 }
1492
1493 Node* region = obj->in(0);
1494
1495 Node* phi = PhiNode::make_blank(region, n->in(1));
1496 for (uint i = 1; i < region->req(); i++) {
1497 Node* in = obj->in(i);
1498 Node* ctrl = region->in(i);
1499 if (addr->in(AddPNode::Base) != obj) {
1500 Node* cast = addr->in(AddPNode::Base);
1501 assert(cast->Opcode() == Op_CastPP && cast->in(0) != nullptr, "inconsistent subgraph");
1502 Node* cast_clone = cast->clone();
1503 cast_clone->set_req(0, ctrl);
1504 cast_clone->set_req(1, in);
1505 register_new_node(cast_clone, ctrl);
1506 const Type* tcast = cast_clone->Value(&_igvn);
1507 _igvn.set_type(cast_clone, tcast);
1508 cast_clone->as_Type()->set_type(tcast);
1509 in = cast_clone;
1510 }
1511 Node* addr_clone = addr->clone();
1512 addr_clone->set_req(AddPNode::Base, in);
1513 addr_clone->set_req(AddPNode::Address, in);
1514 register_new_node(addr_clone, ctrl);
1515 _igvn.set_type(addr_clone, addr_clone->Value(&_igvn));
1516 Node* klassptr_clone = klassptr->clone();
1517 klassptr_clone->set_req(2, addr_clone);
1518 register_new_node(klassptr_clone, ctrl);
1519 _igvn.set_type(klassptr_clone, klassptr_clone->Value(&_igvn));
1520 if (klassptr != n->in(1)) {
1521 Node* decode = n->in(1);
1522 assert(decode->is_DecodeNarrowPtr(), "inconsistent subgraph");
1523 Node* decode_clone = decode->clone();
1524 decode_clone->set_req(1, klassptr_clone);
1525 register_new_node(decode_clone, ctrl);
1526 _igvn.set_type(decode_clone, decode_clone->Value(&_igvn));
1527 klassptr_clone = decode_clone;
1528 }
1529 phi->set_req(i, klassptr_clone);
1530 }
1531 register_new_node(phi, region);
1532 Node* orig = n->in(1);
1533 _igvn.replace_input_of(n, 1, phi);
1534 split_if_with_blocks_post(n);
1535 if (n->outcnt() != 0) {
1536 _igvn.replace_input_of(n, 1, orig);
1537 _igvn.remove_dead_node(phi);
1538 }
1539 return true;
1540 }
1541
1542 //------------------------------split_if_with_blocks_post----------------------
1543 // Do the real work in a non-recursive function. CFG hackery wants to be
1544 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1545 // info.
1546 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1547
1548 if (flat_array_element_type_check(n)) {
1549 return;
1550 }
1551
1552 // Cloning Cmp through Phi's involves the split-if transform.
1553 // FastLock is not used by an If
1554 if (n->is_Cmp() && !n->is_FastLock()) {
1555 Node *n_ctrl = get_ctrl(n);
1556 // Determine if the Node has inputs from some local Phi.
1557 // Returns the block to clone thru.
1558 Node *n_blk = has_local_phi_input(n);
1559 if (n_blk != n_ctrl) {
1560 return;
1561 }
1562
1563 if (!can_split_if(n_ctrl)) {
1564 return;
1565 }
1566
1567 if (n->outcnt() != 1) {
1568 return; // Multiple bool's from 1 compare?
1569 }
1570 Node *bol = n->unique_out();
1571 assert(bol->is_Bool(), "expect a bool here");
1682 // accesses would start to float, since we don't pin at that point.
1683 // 3. If we move from regular if: don't pin. All array accesses are already assumed to be pinned.
1684 bool pin_array_access_nodes = n->Opcode() == Op_RangeCheck &&
1685 prevdom->in(0)->Opcode() != Op_RangeCheck;
1686 dominated_by(prevdom->as_IfProj(), n->as_If(), false, pin_array_access_nodes);
1687 DEBUG_ONLY( if (VerifyLoopOptimizations) { verify(); } );
1688 return;
1689 }
1690 prevdom = dom;
1691 dom = idom(prevdom);
1692 }
1693 }
1694 }
1695
1696 try_sink_out_of_loop(n);
1697 if (C->failing()) {
1698 return;
1699 }
1700
1701 try_move_store_after_loop(n);
1702
1703 // Remove multiple allocations of the same inline type
1704 if (n->is_InlineType()) {
1705 n->as_InlineType()->remove_redundant_allocations(this);
1706 }
1707 }
1708
1709 // Transform:
1710 //
1711 // if (some_condition) {
1712 // // body 1
1713 // } else {
1714 // // body 2
1715 // }
1716 // if (some_condition) {
1717 // // body 3
1718 // } else {
1719 // // body 4
1720 // }
1721 //
1722 // into:
1723 //
1724 //
1725 // if (some_condition) {
1726 // // body 1
2178 uint i;
2179 for (i = 1; i < phi->req(); i++) {
2180 Node* b = phi->in(i);
2181 if (b->is_Phi()) {
2182 _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2183 } else {
2184 assert(b->is_Bool() || b->is_OpaqueNotNull() || b->is_OpaqueInitializedAssertionPredicate(),
2185 "bool, non-null check with OpaqueNotNull or Initialized Assertion Predicate with its Opaque node");
2186 }
2187 }
2188 Node* n = phi->in(1);
2189 Node* sample_opaque = nullptr;
2190 Node *sample_bool = nullptr;
2191 if (n->is_OpaqueNotNull() || n->is_OpaqueInitializedAssertionPredicate()) {
2192 sample_opaque = n;
2193 sample_bool = n->in(1);
2194 assert(sample_bool->is_Bool(), "wrong type");
2195 } else {
2196 sample_bool = n;
2197 }
2198 Node* sample_cmp = sample_bool->in(1);
2199 const Type* t = Type::TOP;
2200 const TypePtr* at = nullptr;
2201 if (sample_cmp->is_FlatArrayCheck()) {
2202 // Left input of a FlatArrayCheckNode is memory, set the (adr) type of the phi accordingly
2203 assert(sample_cmp->in(1)->bottom_type() == Type::MEMORY, "unexpected input type");
2204 t = Type::MEMORY;
2205 at = TypeRawPtr::BOTTOM;
2206 }
2207
2208 // Make Phis to merge the Cmp's inputs.
2209 PhiNode *phi1 = new PhiNode(phi->in(0), t, at);
2210 PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2211 for (i = 1; i < phi->req(); i++) {
2212 Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2213 Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2214 phi1->set_req(i, n1);
2215 phi2->set_req(i, n2);
2216 phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2217 phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2218 }
2219 // See if these Phis have been made before.
2220 // Register with optimizer
2221 Node *hit1 = _igvn.hash_find_insert(phi1);
2222 if (hit1) { // Hit, toss just made Phi
2223 _igvn.remove_dead_node(phi1); // Remove new phi
2224 assert(hit1->is_Phi(), "" );
2225 phi1 = (PhiNode*)hit1; // Use existing phi
2226 } else { // Miss
2227 _igvn.register_new_node_with_optimizer(phi1);
2228 }
2229 Node *hit2 = _igvn.hash_find_insert(phi2);
|