14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "gc/shared/barrierSet.hpp"
26 #include "gc/shared/c2/barrierSetC2.hpp"
27 #include "memory/allocation.inline.hpp"
28 #include "memory/resourceArea.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/callnode.hpp"
31 #include "opto/castnode.hpp"
32 #include "opto/connode.hpp"
33 #include "opto/divnode.hpp"
34 #include "opto/loopnode.hpp"
35 #include "opto/matcher.hpp"
36 #include "opto/movenode.hpp"
37 #include "opto/mulnode.hpp"
38 #include "opto/opaquenode.hpp"
39 #include "opto/rootnode.hpp"
40 #include "opto/subnode.hpp"
41 #include "opto/subtypenode.hpp"
42 #include "opto/superword.hpp"
43 #include "opto/vectornode.hpp"
44 #include "utilities/checkedCast.hpp"
45 #include "utilities/macros.hpp"
46
47 //=============================================================================
48 //------------------------------split_thru_phi---------------------------------
49 // Split Node 'n' through merge point if there is enough win.
50 Node* PhaseIdealLoop::split_thru_phi(Node* n, Node* region, int policy) {
51 if ((n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) ||
52 (n->Opcode() == Op_ConvL2I && n->bottom_type() != TypeInt::INT)) {
53 // ConvI2L/ConvL2I may have type information on it which is unsafe to push up
54 // so disable this for now
55 return nullptr;
56 }
57
58 // Splitting range check CastIIs through a loop induction Phi can
59 // cause new Phis to be created that are left unrelated to the loop
60 // induction Phi and prevent optimizations (vectorization)
61 if (n->Opcode() == Op_CastII && region->is_CountedLoop() &&
62 n->in(1) == region->as_CountedLoop()->phi()) {
63 return nullptr;
64 }
65
66 if (cannot_split_division(n, region)) {
67 return nullptr;
68 }
69
70 SplitThruPhiWins wins(region);
71 assert(!n->is_CFG(), "");
72 assert(region->is_Region(), "");
73
74 const Type* type = n->bottom_type();
75 const TypeOopPtr* t_oop = _igvn.type(n)->isa_oopptr();
76 Node* phi;
77 if (t_oop != nullptr && t_oop->is_known_instance_field()) {
78 int iid = t_oop->instance_id();
79 int index = C->get_alias_index(t_oop);
80 int offset = t_oop->offset();
81 phi = new PhiNode(region, type, nullptr, iid, index, offset);
82 } else {
83 phi = PhiNode::make_blank(region, n);
84 }
85 uint old_unique = C->unique();
775 // CMOVE'd derived pointer? It's a CMOVE'd derived base. Thus
776 // CMOVE'ing a derived pointer requires we also CMOVE the base. If we
777 // have a Phi for the base here that we convert to a CMOVE all is well
778 // and good. But if the base is dead, we'll not make a CMOVE. Later
779 // the allocator will have to produce a base by creating a CMOVE of the
780 // relevant bases. This puts the allocator in the business of
781 // manufacturing expensive instructions, generally a bad plan.
782 // Just Say No to Conditionally-Moved Derived Pointers.
783 if (tp && tp->offset() != 0)
784 return nullptr;
785 cost++;
786 break;
787 }
788 default:
789 return nullptr; // In particular, can't do memory or I/O
790 }
791 // Add in cost any speculative ops
792 for (uint j = 1; j < region->req(); j++) {
793 Node *proj = region->in(j);
794 Node *inp = phi->in(j);
795 if (get_ctrl(inp) == proj) { // Found local op
796 cost++;
797 // Check for a chain of dependent ops; these will all become
798 // speculative in a CMOV.
799 for (uint k = 1; k < inp->req(); k++)
800 if (get_ctrl(inp->in(k)) == proj)
801 cost += ConditionalMoveLimit; // Too much speculative goo
802 }
803 }
804 // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
805 // This will likely Split-If, a higher-payoff operation.
806 for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
807 Node* use = phi->fast_out(k);
808 if (use->is_Cmp() || use->is_DecodeNarrowPtr() || use->is_EncodeNarrowPtr())
809 cost += ConditionalMoveLimit;
810 // Is there a use inside the loop?
811 // Note: check only basic types since CMoveP is pinned.
812 if (!used_inside_loop && is_java_primitive(bt)) {
813 IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
814 if (r_loop == u_loop || r_loop->is_member(u_loop)) {
1100 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");
1101
1102 // Move store out of the loop
1103 _igvn.replace_node(hook, n->in(MemNode::Memory));
1104 _igvn.replace_input_of(n, 0, lca);
1105 set_ctrl_and_loop(n, lca);
1106
1107 // Disconnect the phi now. An empty phi can confuse other
1108 // optimizations in this pass of loop opts..
1109 if (phi->in(LoopNode::LoopBackControl) == phi) {
1110 _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1111 n_loop->_body.yank(phi);
1112 }
1113 }
1114 }
1115 }
1116 }
1117 }
1118 }
1119
1120 //------------------------------split_if_with_blocks_pre-----------------------
1121 // Do the real work in a non-recursive function. Data nodes want to be
1122 // cloned in the pre-order so they can feed each other nicely.
1123 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1124 // Cloning these guys is unlikely to win
1125 int n_op = n->Opcode();
1126 if (n_op == Op_MergeMem) {
1127 return n;
1128 }
1129 if (n->is_Proj()) {
1130 return n;
1131 }
1132 // Do not clone-up CmpFXXX variations, as these are always
1133 // followed by a CmpI
1134 if (n->is_Cmp()) {
1135 return n;
1136 }
1137 // Attempt to use a conditional move instead of a phi/branch
1138 if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1139 Node *cmov = conditional_move( n );
1140 if (cmov) {
1141 return cmov;
1142 }
1143 }
1144 if (n->is_CFG() || n->is_LoadStore()) {
1145 return n;
1146 }
1147 if (n->is_Opaque1()) { // Opaque nodes cannot be mod'd
1148 if (!C->major_progress()) { // If chance of no more loop opts...
1149 _igvn._worklist.push(n); // maybe we'll remove them
1150 }
1151 return n;
1384
1385 return true;
1386 }
1387
1388 // Detect if the node is the inner strip-mined loop
1389 // Return: null if it's not the case, or the exit of outer strip-mined loop
1390 static Node* is_inner_of_stripmined_loop(const Node* out) {
1391 Node* out_le = nullptr;
1392
1393 if (out->is_CountedLoopEnd()) {
1394 const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1395
1396 if (loop != nullptr && loop->is_strip_mined()) {
1397 out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1398 }
1399 }
1400
1401 return out_le;
1402 }
1403
1404 //------------------------------split_if_with_blocks_post----------------------
1405 // Do the real work in a non-recursive function. CFG hackery wants to be
1406 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1407 // info.
1408 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1409
1410 // Cloning Cmp through Phi's involves the split-if transform.
1411 // FastLock is not used by an If
1412 if (n->is_Cmp() && !n->is_FastLock()) {
1413 Node *n_ctrl = get_ctrl(n);
1414 // Determine if the Node has inputs from some local Phi.
1415 // Returns the block to clone thru.
1416 Node *n_blk = has_local_phi_input(n);
1417 if (n_blk != n_ctrl) {
1418 return;
1419 }
1420
1421 if (!can_split_if(n_ctrl)) {
1422 return;
1423 }
1424
1425 if (n->outcnt() != 1) {
1426 return; // Multiple bool's from 1 compare?
1427 }
1428 Node *bol = n->unique_out();
1429 assert(bol->is_Bool(), "expect a bool here");
1533 // accesses would start to float, since we don't pin at that point.
1534 // 3. If we move from regular if: don't pin. All array accesses are already assumed to be pinned.
1535 bool pin_array_access_nodes = n->Opcode() == Op_RangeCheck &&
1536 prevdom->in(0)->Opcode() != Op_RangeCheck;
1537 dominated_by(prevdom->as_IfProj(), n->as_If(), false, pin_array_access_nodes);
1538 DEBUG_ONLY( if (VerifyLoopOptimizations) { verify(); } );
1539 return;
1540 }
1541 prevdom = dom;
1542 dom = idom(prevdom);
1543 }
1544 }
1545 }
1546
1547 try_sink_out_of_loop(n);
1548 if (C->failing()) {
1549 return;
1550 }
1551
1552 try_move_store_after_loop(n);
1553 }
1554
1555 // Transform:
1556 //
1557 // if (some_condition) {
1558 // // body 1
1559 // } else {
1560 // // body 2
1561 // }
1562 // if (some_condition) {
1563 // // body 3
1564 // } else {
1565 // // body 4
1566 // }
1567 //
1568 // into:
1569 //
1570 //
1571 // if (some_condition) {
1572 // // body 1
2041 uint i;
2042 for (i = 1; i < phi->req(); i++) {
2043 Node* b = phi->in(i);
2044 if (b->is_Phi()) {
2045 _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2046 } else {
2047 assert(b->is_Bool() || b->is_OpaqueNotNull() || b->is_OpaqueInitializedAssertionPredicate(),
2048 "bool, non-null check with OpaqueNotNull or Initialized Assertion Predicate with its Opaque node");
2049 }
2050 }
2051 Node* n = phi->in(1);
2052 Node* sample_opaque = nullptr;
2053 Node *sample_bool = nullptr;
2054 if (n->is_OpaqueNotNull() || n->is_OpaqueInitializedAssertionPredicate()) {
2055 sample_opaque = n;
2056 sample_bool = n->in(1);
2057 assert(sample_bool->is_Bool(), "wrong type");
2058 } else {
2059 sample_bool = n;
2060 }
2061 Node *sample_cmp = sample_bool->in(1);
2062
2063 // Make Phis to merge the Cmp's inputs.
2064 PhiNode *phi1 = new PhiNode(phi->in(0), Type::TOP);
2065 PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2066 for (i = 1; i < phi->req(); i++) {
2067 Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2068 Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2069 phi1->set_req(i, n1);
2070 phi2->set_req(i, n2);
2071 phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2072 phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2073 }
2074 // See if these Phis have been made before.
2075 // Register with optimizer
2076 Node *hit1 = _igvn.hash_find_insert(phi1);
2077 if (hit1) { // Hit, toss just made Phi
2078 _igvn.remove_dead_node(phi1); // Remove new phi
2079 assert(hit1->is_Phi(), "" );
2080 phi1 = (PhiNode*)hit1; // Use existing phi
2081 } else { // Miss
2082 _igvn.register_new_node_with_optimizer(phi1);
2083 }
2084 Node *hit2 = _igvn.hash_find_insert(phi2);
|
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "gc/shared/barrierSet.hpp"
26 #include "gc/shared/c2/barrierSetC2.hpp"
27 #include "memory/allocation.inline.hpp"
28 #include "memory/resourceArea.hpp"
29 #include "opto/addnode.hpp"
30 #include "opto/callnode.hpp"
31 #include "opto/castnode.hpp"
32 #include "opto/connode.hpp"
33 #include "opto/divnode.hpp"
34 #include "opto/inlinetypenode.hpp"
35 #include "opto/loopnode.hpp"
36 #include "opto/matcher.hpp"
37 #include "opto/movenode.hpp"
38 #include "opto/mulnode.hpp"
39 #include "opto/opaquenode.hpp"
40 #include "opto/rootnode.hpp"
41 #include "opto/subnode.hpp"
42 #include "opto/subtypenode.hpp"
43 #include "opto/superword.hpp"
44 #include "opto/vectornode.hpp"
45 #include "utilities/checkedCast.hpp"
46 #include "utilities/macros.hpp"
47
48 //=============================================================================
49 //------------------------------split_thru_phi---------------------------------
50 // Split Node 'n' through merge point if there is enough win.
51 Node* PhaseIdealLoop::split_thru_phi(Node* n, Node* region, int policy) {
52 if ((n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) ||
53 (n->Opcode() == Op_ConvL2I && n->bottom_type() != TypeInt::INT)) {
54 // ConvI2L/ConvL2I may have type information on it which is unsafe to push up
55 // so disable this for now
56 return nullptr;
57 }
58
59 // Splitting range check CastIIs through a loop induction Phi can
60 // cause new Phis to be created that are left unrelated to the loop
61 // induction Phi and prevent optimizations (vectorization)
62 if (n->Opcode() == Op_CastII && region->is_CountedLoop() &&
63 n->in(1) == region->as_CountedLoop()->phi()) {
64 return nullptr;
65 }
66
67 // Inline types should not be split through Phis because they cannot be merged
68 // through Phi nodes but each value input needs to be merged individually.
69 if (n->is_InlineType()) {
70 return nullptr;
71 }
72
73 if (cannot_split_division(n, region)) {
74 return nullptr;
75 }
76
77 SplitThruPhiWins wins(region);
78 assert(!n->is_CFG(), "");
79 assert(region->is_Region(), "");
80
81 const Type* type = n->bottom_type();
82 const TypeOopPtr* t_oop = _igvn.type(n)->isa_oopptr();
83 Node* phi;
84 if (t_oop != nullptr && t_oop->is_known_instance_field()) {
85 int iid = t_oop->instance_id();
86 int index = C->get_alias_index(t_oop);
87 int offset = t_oop->offset();
88 phi = new PhiNode(region, type, nullptr, iid, index, offset);
89 } else {
90 phi = PhiNode::make_blank(region, n);
91 }
92 uint old_unique = C->unique();
782 // CMOVE'd derived pointer? It's a CMOVE'd derived base. Thus
783 // CMOVE'ing a derived pointer requires we also CMOVE the base. If we
784 // have a Phi for the base here that we convert to a CMOVE all is well
785 // and good. But if the base is dead, we'll not make a CMOVE. Later
786 // the allocator will have to produce a base by creating a CMOVE of the
787 // relevant bases. This puts the allocator in the business of
788 // manufacturing expensive instructions, generally a bad plan.
789 // Just Say No to Conditionally-Moved Derived Pointers.
790 if (tp && tp->offset() != 0)
791 return nullptr;
792 cost++;
793 break;
794 }
795 default:
796 return nullptr; // In particular, can't do memory or I/O
797 }
798 // Add in cost any speculative ops
799 for (uint j = 1; j < region->req(); j++) {
800 Node *proj = region->in(j);
801 Node *inp = phi->in(j);
802 if (inp->isa_InlineType()) {
803 // TODO 8302217 This prevents PhiNode::push_inline_types_through
804 return nullptr;
805 }
806 if (get_ctrl(inp) == proj) { // Found local op
807 cost++;
808 // Check for a chain of dependent ops; these will all become
809 // speculative in a CMOV.
810 for (uint k = 1; k < inp->req(); k++)
811 if (get_ctrl(inp->in(k)) == proj)
812 cost += ConditionalMoveLimit; // Too much speculative goo
813 }
814 }
815 // See if the Phi is used by a Cmp or Narrow oop Decode/Encode.
816 // This will likely Split-If, a higher-payoff operation.
817 for (DUIterator_Fast kmax, k = phi->fast_outs(kmax); k < kmax; k++) {
818 Node* use = phi->fast_out(k);
819 if (use->is_Cmp() || use->is_DecodeNarrowPtr() || use->is_EncodeNarrowPtr())
820 cost += ConditionalMoveLimit;
821 // Is there a use inside the loop?
822 // Note: check only basic types since CMoveP is pinned.
823 if (!used_inside_loop && is_java_primitive(bt)) {
824 IdealLoopTree* u_loop = get_loop(has_ctrl(use) ? get_ctrl(use) : use);
825 if (r_loop == u_loop || r_loop->is_member(u_loop)) {
1111 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");
1112
1113 // Move store out of the loop
1114 _igvn.replace_node(hook, n->in(MemNode::Memory));
1115 _igvn.replace_input_of(n, 0, lca);
1116 set_ctrl_and_loop(n, lca);
1117
1118 // Disconnect the phi now. An empty phi can confuse other
1119 // optimizations in this pass of loop opts..
1120 if (phi->in(LoopNode::LoopBackControl) == phi) {
1121 _igvn.replace_node(phi, phi->in(LoopNode::EntryControl));
1122 n_loop->_body.yank(phi);
1123 }
1124 }
1125 }
1126 }
1127 }
1128 }
1129 }
1130
1131 // We can't use immutable memory for the flat array check because we are loading the mark word which is
1132 // mutable. Although the bits we are interested in are immutable (we check for markWord::unlocked_value),
1133 // we need to use raw memory to not break anti dependency analysis. Below code will attempt to still move
1134 // flat array checks out of loops, mainly to enable loop unswitching.
1135 void PhaseIdealLoop::move_flat_array_check_out_of_loop(Node* n) {
1136 // Skip checks for more than one array
1137 if (n->req() > 3) {
1138 return;
1139 }
1140 Node* mem = n->in(FlatArrayCheckNode::Memory);
1141 Node* array = n->in(FlatArrayCheckNode::ArrayOrKlass)->uncast();
1142 IdealLoopTree* check_loop = get_loop(get_ctrl(n));
1143 IdealLoopTree* ary_loop = get_loop(get_ctrl(array));
1144
1145 // Check if array is loop invariant
1146 if (!check_loop->is_member(ary_loop)) {
1147 // Walk up memory graph from the check until we leave the loop
1148 VectorSet wq;
1149 wq.set(mem->_idx);
1150 while (check_loop->is_member(get_loop(ctrl_or_self(mem)))) {
1151 if (mem->is_Phi()) {
1152 mem = mem->in(1);
1153 } else if (mem->is_MergeMem()) {
1154 mem = mem->as_MergeMem()->memory_at(Compile::AliasIdxRaw);
1155 } else if (mem->is_Proj()) {
1156 mem = mem->in(0);
1157 } else if (mem->is_MemBar() || mem->is_SafePoint()) {
1158 mem = mem->in(TypeFunc::Memory);
1159 } else if (mem->is_Store() || mem->is_LoadStore() || mem->is_ClearArray()) {
1160 mem = mem->in(MemNode::Memory);
1161 } else {
1162 #ifdef ASSERT
1163 mem->dump();
1164 #endif
1165 ShouldNotReachHere();
1166 }
1167 if (wq.test_set(mem->_idx)) {
1168 return;
1169 }
1170 }
1171 // Replace memory input and re-compute ctrl to move the check out of the loop
1172 _igvn.replace_input_of(n, 1, mem);
1173 set_ctrl_and_loop(n, get_early_ctrl(n));
1174 Node* bol = n->unique_out();
1175 set_ctrl_and_loop(bol, get_early_ctrl(bol));
1176 }
1177 }
1178
1179 //------------------------------split_if_with_blocks_pre-----------------------
1180 // Do the real work in a non-recursive function. Data nodes want to be
1181 // cloned in the pre-order so they can feed each other nicely.
1182 Node *PhaseIdealLoop::split_if_with_blocks_pre( Node *n ) {
1183 // Cloning these guys is unlikely to win
1184 int n_op = n->Opcode();
1185 if (n_op == Op_MergeMem) {
1186 return n;
1187 }
1188 if (n->is_Proj()) {
1189 return n;
1190 }
1191
1192 if (n->isa_FlatArrayCheck()) {
1193 move_flat_array_check_out_of_loop(n);
1194 return n;
1195 }
1196
1197 // Do not clone-up CmpFXXX variations, as these are always
1198 // followed by a CmpI
1199 if (n->is_Cmp()) {
1200 return n;
1201 }
1202 // Attempt to use a conditional move instead of a phi/branch
1203 if (ConditionalMoveLimit > 0 && n_op == Op_Region) {
1204 Node *cmov = conditional_move( n );
1205 if (cmov) {
1206 return cmov;
1207 }
1208 }
1209 if (n->is_CFG() || n->is_LoadStore()) {
1210 return n;
1211 }
1212 if (n->is_Opaque1()) { // Opaque nodes cannot be mod'd
1213 if (!C->major_progress()) { // If chance of no more loop opts...
1214 _igvn._worklist.push(n); // maybe we'll remove them
1215 }
1216 return n;
1449
1450 return true;
1451 }
1452
1453 // Detect if the node is the inner strip-mined loop
1454 // Return: null if it's not the case, or the exit of outer strip-mined loop
1455 static Node* is_inner_of_stripmined_loop(const Node* out) {
1456 Node* out_le = nullptr;
1457
1458 if (out->is_CountedLoopEnd()) {
1459 const CountedLoopNode* loop = out->as_CountedLoopEnd()->loopnode();
1460
1461 if (loop != nullptr && loop->is_strip_mined()) {
1462 out_le = loop->in(LoopNode::EntryControl)->as_OuterStripMinedLoop()->outer_loop_exit();
1463 }
1464 }
1465
1466 return out_le;
1467 }
1468
1469 bool PhaseIdealLoop::flat_array_element_type_check(Node *n) {
1470 // If the CmpP is a subtype check for a value that has just been
1471 // loaded from an array, the subtype check guarantees the value
1472 // can't be stored in a flat array and the load of the value
1473 // happens with a flat array check then: push the type check
1474 // through the phi of the flat array check. This needs special
1475 // logic because the subtype check's input is not a phi but a
1476 // LoadKlass that must first be cloned through the phi.
1477 if (n->Opcode() != Op_CmpP) {
1478 return false;
1479 }
1480
1481 Node* klassptr = n->in(1);
1482 Node* klasscon = n->in(2);
1483
1484 if (klassptr->is_DecodeNarrowPtr()) {
1485 klassptr = klassptr->in(1);
1486 }
1487
1488 if (klassptr->Opcode() != Op_LoadKlass && klassptr->Opcode() != Op_LoadNKlass) {
1489 return false;
1490 }
1491
1492 if (!klasscon->is_Con()) {
1493 return false;
1494 }
1495
1496 Node* addr = klassptr->in(MemNode::Address);
1497
1498 if (!addr->is_AddP()) {
1499 return false;
1500 }
1501
1502 intptr_t offset;
1503 Node* obj = AddPNode::Ideal_base_and_offset(addr, &_igvn, offset);
1504
1505 if (obj == nullptr) {
1506 return false;
1507 }
1508
1509 assert(obj != nullptr && addr->in(AddPNode::Base) == addr->in(AddPNode::Address), "malformed AddP?");
1510 if (obj->Opcode() == Op_CastPP) {
1511 obj = obj->in(1);
1512 }
1513
1514 if (!obj->is_Phi()) {
1515 return false;
1516 }
1517
1518 Node* region = obj->in(0);
1519
1520 Node* phi = PhiNode::make_blank(region, n->in(1));
1521 for (uint i = 1; i < region->req(); i++) {
1522 Node* in = obj->in(i);
1523 Node* ctrl = region->in(i);
1524 if (addr->in(AddPNode::Base) != obj) {
1525 Node* cast = addr->in(AddPNode::Base);
1526 assert(cast->Opcode() == Op_CastPP && cast->in(0) != nullptr, "inconsistent subgraph");
1527 Node* cast_clone = cast->clone();
1528 cast_clone->set_req(0, ctrl);
1529 cast_clone->set_req(1, in);
1530 register_new_node(cast_clone, ctrl);
1531 const Type* tcast = cast_clone->Value(&_igvn);
1532 _igvn.set_type(cast_clone, tcast);
1533 cast_clone->as_Type()->set_type(tcast);
1534 in = cast_clone;
1535 }
1536 Node* addr_clone = addr->clone();
1537 addr_clone->set_req(AddPNode::Base, in);
1538 addr_clone->set_req(AddPNode::Address, in);
1539 register_new_node(addr_clone, ctrl);
1540 _igvn.set_type(addr_clone, addr_clone->Value(&_igvn));
1541 Node* klassptr_clone = klassptr->clone();
1542 klassptr_clone->set_req(2, addr_clone);
1543 register_new_node(klassptr_clone, ctrl);
1544 _igvn.set_type(klassptr_clone, klassptr_clone->Value(&_igvn));
1545 if (klassptr != n->in(1)) {
1546 Node* decode = n->in(1);
1547 assert(decode->is_DecodeNarrowPtr(), "inconsistent subgraph");
1548 Node* decode_clone = decode->clone();
1549 decode_clone->set_req(1, klassptr_clone);
1550 register_new_node(decode_clone, ctrl);
1551 _igvn.set_type(decode_clone, decode_clone->Value(&_igvn));
1552 klassptr_clone = decode_clone;
1553 }
1554 phi->set_req(i, klassptr_clone);
1555 }
1556 register_new_node(phi, region);
1557 Node* orig = n->in(1);
1558 _igvn.replace_input_of(n, 1, phi);
1559 split_if_with_blocks_post(n);
1560 if (n->outcnt() != 0) {
1561 _igvn.replace_input_of(n, 1, orig);
1562 _igvn.remove_dead_node(phi);
1563 }
1564 return true;
1565 }
1566
1567 //------------------------------split_if_with_blocks_post----------------------
1568 // Do the real work in a non-recursive function. CFG hackery wants to be
1569 // in the post-order, so it can dirty the I-DOM info and not use the dirtied
1570 // info.
1571 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) {
1572
1573 if (flat_array_element_type_check(n)) {
1574 return;
1575 }
1576
1577 // Cloning Cmp through Phi's involves the split-if transform.
1578 // FastLock is not used by an If
1579 if (n->is_Cmp() && !n->is_FastLock()) {
1580 Node *n_ctrl = get_ctrl(n);
1581 // Determine if the Node has inputs from some local Phi.
1582 // Returns the block to clone thru.
1583 Node *n_blk = has_local_phi_input(n);
1584 if (n_blk != n_ctrl) {
1585 return;
1586 }
1587
1588 if (!can_split_if(n_ctrl)) {
1589 return;
1590 }
1591
1592 if (n->outcnt() != 1) {
1593 return; // Multiple bool's from 1 compare?
1594 }
1595 Node *bol = n->unique_out();
1596 assert(bol->is_Bool(), "expect a bool here");
1700 // accesses would start to float, since we don't pin at that point.
1701 // 3. If we move from regular if: don't pin. All array accesses are already assumed to be pinned.
1702 bool pin_array_access_nodes = n->Opcode() == Op_RangeCheck &&
1703 prevdom->in(0)->Opcode() != Op_RangeCheck;
1704 dominated_by(prevdom->as_IfProj(), n->as_If(), false, pin_array_access_nodes);
1705 DEBUG_ONLY( if (VerifyLoopOptimizations) { verify(); } );
1706 return;
1707 }
1708 prevdom = dom;
1709 dom = idom(prevdom);
1710 }
1711 }
1712 }
1713
1714 try_sink_out_of_loop(n);
1715 if (C->failing()) {
1716 return;
1717 }
1718
1719 try_move_store_after_loop(n);
1720
1721 // Remove multiple allocations of the same inline type
1722 if (n->is_InlineType()) {
1723 n->as_InlineType()->remove_redundant_allocations(this);
1724 }
1725 }
1726
1727 // Transform:
1728 //
1729 // if (some_condition) {
1730 // // body 1
1731 // } else {
1732 // // body 2
1733 // }
1734 // if (some_condition) {
1735 // // body 3
1736 // } else {
1737 // // body 4
1738 // }
1739 //
1740 // into:
1741 //
1742 //
1743 // if (some_condition) {
1744 // // body 1
2213 uint i;
2214 for (i = 1; i < phi->req(); i++) {
2215 Node* b = phi->in(i);
2216 if (b->is_Phi()) {
2217 _igvn.replace_input_of(phi, i, clone_iff(b->as_Phi()));
2218 } else {
2219 assert(b->is_Bool() || b->is_OpaqueNotNull() || b->is_OpaqueInitializedAssertionPredicate(),
2220 "bool, non-null check with OpaqueNotNull or Initialized Assertion Predicate with its Opaque node");
2221 }
2222 }
2223 Node* n = phi->in(1);
2224 Node* sample_opaque = nullptr;
2225 Node *sample_bool = nullptr;
2226 if (n->is_OpaqueNotNull() || n->is_OpaqueInitializedAssertionPredicate()) {
2227 sample_opaque = n;
2228 sample_bool = n->in(1);
2229 assert(sample_bool->is_Bool(), "wrong type");
2230 } else {
2231 sample_bool = n;
2232 }
2233 Node* sample_cmp = sample_bool->in(1);
2234 const Type* t = Type::TOP;
2235 const TypePtr* at = nullptr;
2236 if (sample_cmp->is_FlatArrayCheck()) {
2237 // Left input of a FlatArrayCheckNode is memory, set the (adr) type of the phi accordingly
2238 assert(sample_cmp->in(1)->bottom_type() == Type::MEMORY, "unexpected input type");
2239 t = Type::MEMORY;
2240 at = TypeRawPtr::BOTTOM;
2241 }
2242
2243 // Make Phis to merge the Cmp's inputs.
2244 PhiNode *phi1 = new PhiNode(phi->in(0), t, at);
2245 PhiNode *phi2 = new PhiNode(phi->in(0), Type::TOP);
2246 for (i = 1; i < phi->req(); i++) {
2247 Node *n1 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(1) : phi->in(i)->in(1)->in(1)->in(1);
2248 Node *n2 = sample_opaque == nullptr ? phi->in(i)->in(1)->in(2) : phi->in(i)->in(1)->in(1)->in(2);
2249 phi1->set_req(i, n1);
2250 phi2->set_req(i, n2);
2251 phi1->set_type(phi1->type()->meet_speculative(n1->bottom_type()));
2252 phi2->set_type(phi2->type()->meet_speculative(n2->bottom_type()));
2253 }
2254 // See if these Phis have been made before.
2255 // Register with optimizer
2256 Node *hit1 = _igvn.hash_find_insert(phi1);
2257 if (hit1) { // Hit, toss just made Phi
2258 _igvn.remove_dead_node(phi1); // Remove new phi
2259 assert(hit1->is_Phi(), "" );
2260 phi1 = (PhiNode*)hit1; // Use existing phi
2261 } else { // Miss
2262 _igvn.register_new_node_with_optimizer(phi1);
2263 }
2264 Node *hit2 = _igvn.hash_find_insert(phi2);
|