1134 // CmpPNode performs deep traversals if it compares oopptr. CmpP is not notified for changes far away.
1135 if (n->Opcode() == Op_CmpP && type(n->in(1))->isa_oopptr() && type(n->in(2))->isa_oopptr()) {
1136 // SubNode::Value
1137 // CmpPNode::sub
1138 // MemNode::detect_ptr_independence
1139 // MemNode::all_controls_dominate
1140 // We find all controls of a pointer load, and see if they dominate the control of
1141 // an allocation. If they all dominate, we know the allocation is after (independent)
1142 // of the pointer load, and we can say the pointers are different. For this we call
1143 // n->dominates(sub, nlist) to check if controls n of the pointer load dominate the
1144 // control sub of the allocation. The problems is that sometimes dominates answers
1145 // false conservatively, and later it can determine that it is indeed true. Loops with
1146 // Region heads can lead to giving up, whereas LoopNodes can be skipped easier, and
1147 // so the traversal becomes more powerful. This is difficult to remidy, we would have
1148 // to notify the CmpP of CFG updates. Luckily, we recompute CmpP::Value during CCP
1149 // after loop-opts, so that should take care of many of these cases.
1150 return false;
1151 }
1152 tty->cr();
1153 tty->print_cr("Missed Value optimization:");
1154 n->dump_bfs(1, nullptr, "");
1155 tty->print_cr("Current type:");
1156 told->dump_on(tty);
1157 tty->cr();
1158 tty->print_cr("Optimized type:");
1159 tnew->dump_on(tty);
1160 tty->cr();
1161 return true;
1162 }
1163 #endif
1164
1165 /**
1166 * Register a new node with the optimizer. Update the types array, the def-use
1167 * info. Put on worklist.
1168 */
1169 Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) {
1170 set_type_bottom(n);
1171 _worklist.push(n);
1172 if (orig != nullptr) C->copy_node_notes_to(n, orig);
1173 return n;
1174 }
1175
1176 //------------------------------transform--------------------------------------
1177 // Non-recursive: idealize Node 'n' with respect to its inputs and its value
1178 Node *PhaseIterGVN::transform( Node *n ) {
1179 if (_delay_transform) {
1180 // Register the node but don't optimize for now
1181 register_new_node_with_optimizer(n);
1182 return n;
1183 }
1184
1185 // If brand new node, make space in type array, and give it a type.
1186 ensure_type_or_null(n);
1187 if (type_or_null(n) == nullptr) {
1188 set_type_bottom(n);
1189 }
1190
1191 return transform_old(n);
1192 }
1193
1194 Node *PhaseIterGVN::transform_old(Node* n) {
1195 NOT_PRODUCT(set_transforms());
1196 // Remove 'n' from hash table in case it gets modified
1197 _table.hash_delete(n);
1198 #ifdef ASSERT
1199 if (is_verify_def_use()) {
1200 assert(!_table.find_index(n->_idx), "found duplicate entry in table");
1201 }
1202 #endif
1203
1204 // Allow Bool -> Cmp idealisation in late inlining intrinsics that return a bool
1205 if (n->is_Cmp()) {
1206 add_users_to_worklist(n);
1207 }
1208
1209 // Apply the Ideal call in a loop until it no longer applies
1210 Node* k = n;
1443
1444 // Smash all inputs to 'old', isolating him completely
1445 Node *temp = new Node(1);
1446 temp->init_req(0,nn); // Add a use to nn to prevent him from dying
1447 remove_dead_node( old );
1448 temp->del_req(0); // Yank bogus edge
1449 if (nn != nullptr && nn->outcnt() == 0) {
1450 _worklist.push(nn);
1451 }
1452 #ifndef PRODUCT
1453 if (is_verify_def_use()) {
1454 for ( int i = 0; i < _verify_window_size; i++ ) {
1455 if ( _verify_window[i] == old )
1456 _verify_window[i] = nn;
1457 }
1458 }
1459 #endif
1460 temp->destruct(this); // reuse the _idx of this little guy
1461 }
1462
1463 //------------------------------add_users_to_worklist--------------------------
1464 void PhaseIterGVN::add_users_to_worklist0(Node* n, Unique_Node_List& worklist) {
1465 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1466 worklist.push(n->fast_out(i)); // Push on worklist
1467 }
1468 }
1469
1470 // Return counted loop Phi if as a counted loop exit condition, cmp
1471 // compares the induction variable with n
1472 static PhiNode* countedloop_phi_from_cmp(CmpNode* cmp, Node* n) {
1473 for (DUIterator_Fast imax, i = cmp->fast_outs(imax); i < imax; i++) {
1474 Node* bol = cmp->fast_out(i);
1475 for (DUIterator_Fast i2max, i2 = bol->fast_outs(i2max); i2 < i2max; i2++) {
1476 Node* iff = bol->fast_out(i2);
1477 if (iff->is_BaseCountedLoopEnd()) {
1478 BaseCountedLoopEndNode* cle = iff->as_BaseCountedLoopEnd();
1479 if (cle->limit() == n) {
1480 PhiNode* phi = cle->phi();
1481 if (phi != nullptr) {
1482 return phi;
1498 add_users_of_use_to_worklist(n, use, worklist);
1499 }
1500 }
1501
1502 void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist) {
1503 if(use->is_Multi() || // Multi-definer? Push projs on worklist
1504 use->is_Store() ) // Enable store/load same address
1505 add_users_to_worklist0(use, worklist);
1506
1507 // If we changed the receiver type to a call, we need to revisit
1508 // the Catch following the call. It's looking for a non-null
1509 // receiver to know when to enable the regular fall-through path
1510 // in addition to the NullPtrException path.
1511 if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) {
1512 Node* p = use->as_CallDynamicJava()->proj_out_or_null(TypeFunc::Control);
1513 if (p != nullptr) {
1514 add_users_to_worklist0(p, worklist);
1515 }
1516 }
1517
1518 uint use_op = use->Opcode();
1519 if(use->is_Cmp()) { // Enable CMP/BOOL optimization
1520 add_users_to_worklist0(use, worklist); // Put Bool on worklist
1521 if (use->outcnt() > 0) {
1522 Node* bol = use->raw_out(0);
1523 if (bol->outcnt() > 0) {
1524 Node* iff = bol->raw_out(0);
1525 if (iff->outcnt() == 2) {
1526 // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the
1527 // phi merging either 0 or 1 onto the worklist
1528 Node* ifproj0 = iff->raw_out(0);
1529 Node* ifproj1 = iff->raw_out(1);
1530 if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) {
1531 Node* region0 = ifproj0->raw_out(0);
1532 Node* region1 = ifproj1->raw_out(0);
1533 if( region0 == region1 )
1534 add_users_to_worklist0(region0, worklist);
1535 }
1536 }
1537 }
1595 assert(n == in2, "only in2 modified");
1596 // Find all CastII with input in1.
1597 for (DUIterator_Fast jmax, j = in1->fast_outs(jmax); j < jmax; j++) {
1598 Node* castii = in1->fast_out(j);
1599 if (castii->is_CastII() && castii->as_CastII()->carry_dependency()) {
1600 // Find If.
1601 if (castii->in(0) != nullptr && castii->in(0)->in(0) != nullptr && castii->in(0)->in(0)->is_If()) {
1602 Node* ifnode = castii->in(0)->in(0);
1603 // Check that if connects to the cmp
1604 if (ifnode->in(1) != nullptr && ifnode->in(1)->is_Bool() && ifnode->in(1)->in(1) == cmp) {
1605 worklist.push(castii);
1606 }
1607 }
1608 }
1609 }
1610 }
1611 }
1612 }
1613 }
1614
1615 // If changed Cast input, notify down for Phi, Sub, and Xor - all do "uncast"
1616 // Patterns:
1617 // ConstraintCast+ -> Sub
1618 // ConstraintCast+ -> Phi
1619 // ConstraintCast+ -> Xor
1620 if (use->is_ConstraintCast()) {
1621 auto push_the_uses_to_worklist = [&](Node* n){
1622 if (n->is_Phi() || n->is_Sub() || n->Opcode() == Op_XorI || n->Opcode() == Op_XorL) {
1623 worklist.push(n);
1624 }
1625 };
1626 auto is_boundary = [](Node* n){ return !n->is_ConstraintCast(); };
1627 use->visit_uses(push_the_uses_to_worklist, is_boundary);
1628 }
1629 // If changed LShift inputs, check RShift users for useless sign-ext
1630 if (use_op == Op_LShiftI || use_op == Op_LShiftL) {
1631 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1632 Node* u = use->fast_out(i2);
1633 if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL)
1634 worklist.push(u);
1678 // If the ValidLengthTest input changes then the fallthrough path out of the AllocateArray may have become dead.
1679 // CatchNode::Value() is responsible for killing that path. The CatchNode has to be explicitly enqueued for igvn
1680 // to guarantee the change is not missed.
1681 if (use_op == Op_AllocateArray && n == use->in(AllocateNode::ValidLengthTest)) {
1682 Node* p = use->as_AllocateArray()->proj_out_or_null(TypeFunc::Control);
1683 if (p != nullptr) {
1684 add_users_to_worklist0(p, worklist);
1685 }
1686 }
1687
1688 if (use_op == Op_Initialize) {
1689 Node* imem = use->as_Initialize()->proj_out_or_null(TypeFunc::Memory);
1690 if (imem != nullptr) add_users_to_worklist0(imem, worklist);
1691 }
1692 // Loading the java mirror from a Klass requires two loads and the type
1693 // of the mirror load depends on the type of 'n'. See LoadNode::Value().
1694 // LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
1695 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1696 bool has_load_barrier_nodes = bs->has_load_barrier_nodes();
1697
1698 if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
1699 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1700 Node* u = use->fast_out(i2);
1701 const Type* ut = u->bottom_type();
1702 if (u->Opcode() == Op_LoadP && ut->isa_instptr()) {
1703 if (has_load_barrier_nodes) {
1704 // Search for load barriers behind the load
1705 for (DUIterator_Fast i3max, i3 = u->fast_outs(i3max); i3 < i3max; i3++) {
1706 Node* b = u->fast_out(i3);
1707 if (bs->is_gc_barrier_node(b)) {
1708 worklist.push(b);
1709 }
1710 }
1711 }
1712 worklist.push(u);
1713 }
1714 }
1715 }
1716 if (use->Opcode() == Op_OpaqueZeroTripGuard) {
1717 assert(use->outcnt() <= 1, "OpaqueZeroTripGuard can't be shared");
1718 if (use->outcnt() == 1) {
1719 Node* cmp = use->unique_out();
1720 worklist.push(cmp);
1721 }
1722 }
1723 if (use->Opcode() == Op_AddX) {
1724 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1725 Node* u = use->fast_out(i2);
1726 if (u->Opcode() == Op_CastX2P) {
1727 worklist.push(u);
1728 }
1729 }
1730 }
1731 }
1732
1733 /**
1734 * Remove the speculative part of all types that we know of
1735 */
1783 //------------------------------PhaseCCP---------------------------------------
1784 // Conditional Constant Propagation, ala Wegman & Zadeck
1785 PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) {
1786 NOT_PRODUCT( clear_constants(); )
1787 assert( _worklist.size() == 0, "" );
1788 analyze();
1789 }
1790
1791 #ifndef PRODUCT
1792 //------------------------------~PhaseCCP--------------------------------------
1793 PhaseCCP::~PhaseCCP() {
1794 inc_invokes();
1795 _total_constants += count_constants();
1796 }
1797 #endif
1798
1799
1800 #ifdef ASSERT
1801 void PhaseCCP::verify_type(Node* n, const Type* tnew, const Type* told) {
1802 if (tnew->meet(told) != tnew->remove_speculative()) {
1803 n->dump(1);
1804 tty->print("told = "); told->dump(); tty->cr();
1805 tty->print("tnew = "); tnew->dump(); tty->cr();
1806 fatal("Not monotonic");
1807 }
1808 assert(!told->isa_int() || !tnew->isa_int() || told->is_int()->_widen <= tnew->is_int()->_widen, "widen increases");
1809 assert(!told->isa_long() || !tnew->isa_long() || told->is_long()->_widen <= tnew->is_long()->_widen, "widen increases");
1810 }
1811 #endif //ASSERT
1812
1813 // In this analysis, all types are initially set to TOP. We iteratively call Value() on all nodes of the graph until
1814 // we reach a fixed-point (i.e. no types change anymore). We start with a list that only contains the root node. Each time
1815 // a new type is set, we push all uses of that node back to the worklist (in some cases, we also push grandchildren
1816 // or nodes even further down back to the worklist because their type could change as a result of the current type
1817 // change).
1818 void PhaseCCP::analyze() {
1819 // Initialize all types to TOP, optimistic analysis
1820 for (uint i = 0; i < C->unique(); i++) {
1821 _types.map(i, Type::TOP);
1822 }
1823
1905 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1906 Node* use = n->fast_out(i);
1907 push_if_not_bottom_type(worklist, use);
1908 push_more_uses(worklist, n, use);
1909 }
1910 }
1911
1912 void PhaseCCP::push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const {
1913 if (n->bottom_type() != type(n)) {
1914 worklist.push(n);
1915 }
1916 }
1917
1918 // For some nodes, we need to propagate the type change to grandchildren or even further down.
1919 // Add them back to the worklist.
1920 void PhaseCCP::push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const {
1921 push_phis(worklist, use);
1922 push_catch(worklist, use);
1923 push_cmpu(worklist, use);
1924 push_counted_loop_phi(worklist, parent, use);
1925 push_loadp(worklist, use);
1926 push_and(worklist, parent, use);
1927 push_cast_ii(worklist, parent, use);
1928 push_opaque_zero_trip_guard(worklist, use);
1929 }
1930
1931
1932 // We must recheck Phis too if use is a Region.
1933 void PhaseCCP::push_phis(Unique_Node_List& worklist, const Node* use) const {
1934 if (use->is_Region()) {
1935 for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
1936 push_if_not_bottom_type(worklist, use->fast_out(i));
1937 }
1938 }
1939 }
1940
1941 // If we changed the receiver type to a call, we need to revisit the Catch node following the call. It's looking for a
1942 // non-null receiver to know when to enable the regular fall-through path in addition to the NullPtrException path.
1943 // Same is true if the type of a ValidLengthTest input to an AllocateArrayNode changes.
1944 void PhaseCCP::push_catch(Unique_Node_List& worklist, const Node* use) {
1967 if (cmpu_opcode == Op_CmpU || cmpu_opcode == Op_CmpU3) {
1968 // Got a CmpU or CmpU3 which might need the new type information from node n.
1969 push_if_not_bottom_type(worklist, cmpu);
1970 }
1971 }
1972 }
1973 }
1974
1975 // If n is used in a counted loop exit condition, then the type of the counted loop's Phi depends on the type of 'n'.
1976 // Seem PhiNode::Value().
1977 void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {
1978 uint use_op = use->Opcode();
1979 if (use_op == Op_CmpI || use_op == Op_CmpL) {
1980 PhiNode* phi = countedloop_phi_from_cmp(use->as_Cmp(), parent);
1981 if (phi != nullptr) {
1982 worklist.push(phi);
1983 }
1984 }
1985 }
1986
1987 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
1988 // See LoadNode::Value().
1989 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
1990 BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
1991 bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
1992
1993 if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
1994 for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
1995 Node* loadp = use->fast_out(i);
1996 const Type* ut = loadp->bottom_type();
1997 if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
1998 if (has_load_barrier_nodes) {
1999 // Search for load barriers behind the load
2000 push_load_barrier(worklist, barrier_set, loadp);
2001 }
2002 worklist.push(loadp);
2003 }
2004 }
2005 }
2006 }
|
1134 // CmpPNode performs deep traversals if it compares oopptr. CmpP is not notified for changes far away.
1135 if (n->Opcode() == Op_CmpP && type(n->in(1))->isa_oopptr() && type(n->in(2))->isa_oopptr()) {
1136 // SubNode::Value
1137 // CmpPNode::sub
1138 // MemNode::detect_ptr_independence
1139 // MemNode::all_controls_dominate
1140 // We find all controls of a pointer load, and see if they dominate the control of
1141 // an allocation. If they all dominate, we know the allocation is after (independent)
1142 // of the pointer load, and we can say the pointers are different. For this we call
1143 // n->dominates(sub, nlist) to check if controls n of the pointer load dominate the
1144 // control sub of the allocation. The problems is that sometimes dominates answers
1145 // false conservatively, and later it can determine that it is indeed true. Loops with
1146 // Region heads can lead to giving up, whereas LoopNodes can be skipped easier, and
1147 // so the traversal becomes more powerful. This is difficult to remidy, we would have
1148 // to notify the CmpP of CFG updates. Luckily, we recompute CmpP::Value during CCP
1149 // after loop-opts, so that should take care of many of these cases.
1150 return false;
1151 }
1152 tty->cr();
1153 tty->print_cr("Missed Value optimization:");
1154 n->dump_bfs(3, nullptr, "");
1155 tty->print_cr("Current type:");
1156 told->dump_on(tty);
1157 tty->cr();
1158 tty->print_cr("Optimized type:");
1159 tnew->dump_on(tty);
1160 tty->cr();
1161 return true;
1162 }
1163 #endif
1164
1165 /**
1166 * Register a new node with the optimizer. Update the types array, the def-use
1167 * info. Put on worklist.
1168 */
1169 Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) {
1170 set_type_bottom(n);
1171 _worklist.push(n);
1172 if (orig != nullptr) C->copy_node_notes_to(n, orig);
1173 return n;
1174 }
1175
1176 //------------------------------transform--------------------------------------
1177 // Non-recursive: idealize Node 'n' with respect to its inputs and its value
1178 Node *PhaseIterGVN::transform( Node *n ) {
1179 // If brand new node, make space in type array, and give it a type.
1180 ensure_type_or_null(n);
1181 if (type_or_null(n) == nullptr) {
1182 set_type_bottom(n);
1183 }
1184
1185 if (_delay_transform) {
1186 // Add the node to the worklist but don't optimize for now
1187 _worklist.push(n);
1188 return n;
1189 }
1190
1191 return transform_old(n);
1192 }
1193
1194 Node *PhaseIterGVN::transform_old(Node* n) {
1195 NOT_PRODUCT(set_transforms());
1196 // Remove 'n' from hash table in case it gets modified
1197 _table.hash_delete(n);
1198 #ifdef ASSERT
1199 if (is_verify_def_use()) {
1200 assert(!_table.find_index(n->_idx), "found duplicate entry in table");
1201 }
1202 #endif
1203
1204 // Allow Bool -> Cmp idealisation in late inlining intrinsics that return a bool
1205 if (n->is_Cmp()) {
1206 add_users_to_worklist(n);
1207 }
1208
1209 // Apply the Ideal call in a loop until it no longer applies
1210 Node* k = n;
1443
1444 // Smash all inputs to 'old', isolating him completely
1445 Node *temp = new Node(1);
1446 temp->init_req(0,nn); // Add a use to nn to prevent him from dying
1447 remove_dead_node( old );
1448 temp->del_req(0); // Yank bogus edge
1449 if (nn != nullptr && nn->outcnt() == 0) {
1450 _worklist.push(nn);
1451 }
1452 #ifndef PRODUCT
1453 if (is_verify_def_use()) {
1454 for ( int i = 0; i < _verify_window_size; i++ ) {
1455 if ( _verify_window[i] == old )
1456 _verify_window[i] = nn;
1457 }
1458 }
1459 #endif
1460 temp->destruct(this); // reuse the _idx of this little guy
1461 }
1462
1463 void PhaseIterGVN::replace_in_uses(Node* n, Node* m) {
1464 assert(n != nullptr, "sanity");
1465 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1466 Node* u = n->fast_out(i);
1467 if (u != n) {
1468 rehash_node_delayed(u);
1469 int nb = u->replace_edge(n, m);
1470 --i, imax -= nb;
1471 }
1472 }
1473 assert(n->outcnt() == 0, "all uses must be deleted");
1474 }
1475
1476 //------------------------------add_users_to_worklist--------------------------
1477 void PhaseIterGVN::add_users_to_worklist0(Node* n, Unique_Node_List& worklist) {
1478 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1479 worklist.push(n->fast_out(i)); // Push on worklist
1480 }
1481 }
1482
1483 // Return counted loop Phi if as a counted loop exit condition, cmp
1484 // compares the induction variable with n
1485 static PhiNode* countedloop_phi_from_cmp(CmpNode* cmp, Node* n) {
1486 for (DUIterator_Fast imax, i = cmp->fast_outs(imax); i < imax; i++) {
1487 Node* bol = cmp->fast_out(i);
1488 for (DUIterator_Fast i2max, i2 = bol->fast_outs(i2max); i2 < i2max; i2++) {
1489 Node* iff = bol->fast_out(i2);
1490 if (iff->is_BaseCountedLoopEnd()) {
1491 BaseCountedLoopEndNode* cle = iff->as_BaseCountedLoopEnd();
1492 if (cle->limit() == n) {
1493 PhiNode* phi = cle->phi();
1494 if (phi != nullptr) {
1495 return phi;
1511 add_users_of_use_to_worklist(n, use, worklist);
1512 }
1513 }
1514
1515 void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist) {
1516 if(use->is_Multi() || // Multi-definer? Push projs on worklist
1517 use->is_Store() ) // Enable store/load same address
1518 add_users_to_worklist0(use, worklist);
1519
1520 // If we changed the receiver type to a call, we need to revisit
1521 // the Catch following the call. It's looking for a non-null
1522 // receiver to know when to enable the regular fall-through path
1523 // in addition to the NullPtrException path.
1524 if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) {
1525 Node* p = use->as_CallDynamicJava()->proj_out_or_null(TypeFunc::Control);
1526 if (p != nullptr) {
1527 add_users_to_worklist0(p, worklist);
1528 }
1529 }
1530
1531 // AndLNode::Ideal folds GraphKit::mark_word_test patterns. Give it a chance to run.
1532 if (n->is_Load() && use->is_Phi()) {
1533 for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
1534 Node* u = use->fast_out(i);
1535 if (u->Opcode() == Op_AndL) {
1536 worklist.push(u);
1537 }
1538 }
1539 }
1540
1541 uint use_op = use->Opcode();
1542 if(use->is_Cmp()) { // Enable CMP/BOOL optimization
1543 add_users_to_worklist0(use, worklist); // Put Bool on worklist
1544 if (use->outcnt() > 0) {
1545 Node* bol = use->raw_out(0);
1546 if (bol->outcnt() > 0) {
1547 Node* iff = bol->raw_out(0);
1548 if (iff->outcnt() == 2) {
1549 // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the
1550 // phi merging either 0 or 1 onto the worklist
1551 Node* ifproj0 = iff->raw_out(0);
1552 Node* ifproj1 = iff->raw_out(1);
1553 if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) {
1554 Node* region0 = ifproj0->raw_out(0);
1555 Node* region1 = ifproj1->raw_out(0);
1556 if( region0 == region1 )
1557 add_users_to_worklist0(region0, worklist);
1558 }
1559 }
1560 }
1618 assert(n == in2, "only in2 modified");
1619 // Find all CastII with input in1.
1620 for (DUIterator_Fast jmax, j = in1->fast_outs(jmax); j < jmax; j++) {
1621 Node* castii = in1->fast_out(j);
1622 if (castii->is_CastII() && castii->as_CastII()->carry_dependency()) {
1623 // Find If.
1624 if (castii->in(0) != nullptr && castii->in(0)->in(0) != nullptr && castii->in(0)->in(0)->is_If()) {
1625 Node* ifnode = castii->in(0)->in(0);
1626 // Check that if connects to the cmp
1627 if (ifnode->in(1) != nullptr && ifnode->in(1)->is_Bool() && ifnode->in(1)->in(1) == cmp) {
1628 worklist.push(castii);
1629 }
1630 }
1631 }
1632 }
1633 }
1634 }
1635 }
1636 }
1637
1638 // Inline type nodes can have other inline types as users. If an input gets
1639 // updated, make sure that inline type users get a chance for optimization.
1640 if (use->is_InlineType()) {
1641 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1642 Node* u = use->fast_out(i2);
1643 if (u->is_InlineType())
1644 worklist.push(u);
1645 }
1646 }
1647 // If changed Cast input, notify down for Phi, Sub, and Xor - all do "uncast"
1648 // Patterns:
1649 // ConstraintCast+ -> Sub
1650 // ConstraintCast+ -> Phi
1651 // ConstraintCast+ -> Xor
1652 if (use->is_ConstraintCast()) {
1653 auto push_the_uses_to_worklist = [&](Node* n){
1654 if (n->is_Phi() || n->is_Sub() || n->Opcode() == Op_XorI || n->Opcode() == Op_XorL) {
1655 worklist.push(n);
1656 }
1657 };
1658 auto is_boundary = [](Node* n){ return !n->is_ConstraintCast(); };
1659 use->visit_uses(push_the_uses_to_worklist, is_boundary);
1660 }
1661 // If changed LShift inputs, check RShift users for useless sign-ext
1662 if (use_op == Op_LShiftI || use_op == Op_LShiftL) {
1663 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1664 Node* u = use->fast_out(i2);
1665 if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL)
1666 worklist.push(u);
1710 // If the ValidLengthTest input changes then the fallthrough path out of the AllocateArray may have become dead.
1711 // CatchNode::Value() is responsible for killing that path. The CatchNode has to be explicitly enqueued for igvn
1712 // to guarantee the change is not missed.
1713 if (use_op == Op_AllocateArray && n == use->in(AllocateNode::ValidLengthTest)) {
1714 Node* p = use->as_AllocateArray()->proj_out_or_null(TypeFunc::Control);
1715 if (p != nullptr) {
1716 add_users_to_worklist0(p, worklist);
1717 }
1718 }
1719
1720 if (use_op == Op_Initialize) {
1721 Node* imem = use->as_Initialize()->proj_out_or_null(TypeFunc::Memory);
1722 if (imem != nullptr) add_users_to_worklist0(imem, worklist);
1723 }
1724 // Loading the java mirror from a Klass requires two loads and the type
1725 // of the mirror load depends on the type of 'n'. See LoadNode::Value().
1726 // LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
1727 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1728 bool has_load_barrier_nodes = bs->has_load_barrier_nodes();
1729
1730 if (use_op == Op_CastP2X) {
1731 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1732 Node* u = use->fast_out(i2);
1733 if (u->Opcode() == Op_AndX) {
1734 worklist.push(u);
1735 }
1736 }
1737 }
1738 if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
1739 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1740 Node* u = use->fast_out(i2);
1741 const Type* ut = u->bottom_type();
1742 if (u->Opcode() == Op_LoadP && ut->isa_instptr()) {
1743 if (has_load_barrier_nodes) {
1744 // Search for load barriers behind the load
1745 for (DUIterator_Fast i3max, i3 = u->fast_outs(i3max); i3 < i3max; i3++) {
1746 Node* b = u->fast_out(i3);
1747 if (bs->is_gc_barrier_node(b)) {
1748 worklist.push(b);
1749 }
1750 }
1751 }
1752 worklist.push(u);
1753 }
1754 }
1755 }
1756 // Give CallStaticJavaNode::remove_useless_allocation a chance to run
1757 if (use->is_Region()) {
1758 Node* c = use;
1759 do {
1760 c = c->unique_ctrl_out_or_null();
1761 } while (c != nullptr && c->is_Region());
1762 if (c != nullptr && c->is_CallStaticJava() && c->as_CallStaticJava()->uncommon_trap_request() != 0) {
1763 worklist.push(c);
1764 }
1765 }
1766 if (use->Opcode() == Op_OpaqueZeroTripGuard) {
1767 assert(use->outcnt() <= 1, "OpaqueZeroTripGuard can't be shared");
1768 if (use->outcnt() == 1) {
1769 Node* cmp = use->unique_out();
1770 worklist.push(cmp);
1771 }
1772 }
1773 if (use->Opcode() == Op_AddX) {
1774 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1775 Node* u = use->fast_out(i2);
1776 if (u->Opcode() == Op_CastX2P) {
1777 worklist.push(u);
1778 }
1779 }
1780 }
1781 }
1782
1783 /**
1784 * Remove the speculative part of all types that we know of
1785 */
1833 //------------------------------PhaseCCP---------------------------------------
1834 // Conditional Constant Propagation, ala Wegman & Zadeck
1835 PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) {
1836 NOT_PRODUCT( clear_constants(); )
1837 assert( _worklist.size() == 0, "" );
1838 analyze();
1839 }
1840
1841 #ifndef PRODUCT
1842 //------------------------------~PhaseCCP--------------------------------------
1843 PhaseCCP::~PhaseCCP() {
1844 inc_invokes();
1845 _total_constants += count_constants();
1846 }
1847 #endif
1848
1849
1850 #ifdef ASSERT
1851 void PhaseCCP::verify_type(Node* n, const Type* tnew, const Type* told) {
1852 if (tnew->meet(told) != tnew->remove_speculative()) {
1853 n->dump(3);
1854 tty->print("told = "); told->dump(); tty->cr();
1855 tty->print("tnew = "); tnew->dump(); tty->cr();
1856 fatal("Not monotonic");
1857 }
1858 assert(!told->isa_int() || !tnew->isa_int() || told->is_int()->_widen <= tnew->is_int()->_widen, "widen increases");
1859 assert(!told->isa_long() || !tnew->isa_long() || told->is_long()->_widen <= tnew->is_long()->_widen, "widen increases");
1860 }
1861 #endif //ASSERT
1862
1863 // In this analysis, all types are initially set to TOP. We iteratively call Value() on all nodes of the graph until
1864 // we reach a fixed-point (i.e. no types change anymore). We start with a list that only contains the root node. Each time
1865 // a new type is set, we push all uses of that node back to the worklist (in some cases, we also push grandchildren
1866 // or nodes even further down back to the worklist because their type could change as a result of the current type
1867 // change).
1868 void PhaseCCP::analyze() {
1869 // Initialize all types to TOP, optimistic analysis
1870 for (uint i = 0; i < C->unique(); i++) {
1871 _types.map(i, Type::TOP);
1872 }
1873
1955 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
1956 Node* use = n->fast_out(i);
1957 push_if_not_bottom_type(worklist, use);
1958 push_more_uses(worklist, n, use);
1959 }
1960 }
1961
1962 void PhaseCCP::push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const {
1963 if (n->bottom_type() != type(n)) {
1964 worklist.push(n);
1965 }
1966 }
1967
1968 // For some nodes, we need to propagate the type change to grandchildren or even further down.
1969 // Add them back to the worklist.
1970 void PhaseCCP::push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const {
1971 push_phis(worklist, use);
1972 push_catch(worklist, use);
1973 push_cmpu(worklist, use);
1974 push_counted_loop_phi(worklist, parent, use);
1975 push_cast(worklist, use);
1976 push_loadp(worklist, use);
1977 push_and(worklist, parent, use);
1978 push_cast_ii(worklist, parent, use);
1979 push_opaque_zero_trip_guard(worklist, use);
1980 }
1981
1982
1983 // We must recheck Phis too if use is a Region.
1984 void PhaseCCP::push_phis(Unique_Node_List& worklist, const Node* use) const {
1985 if (use->is_Region()) {
1986 for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
1987 push_if_not_bottom_type(worklist, use->fast_out(i));
1988 }
1989 }
1990 }
1991
1992 // If we changed the receiver type to a call, we need to revisit the Catch node following the call. It's looking for a
1993 // non-null receiver to know when to enable the regular fall-through path in addition to the NullPtrException path.
1994 // Same is true if the type of a ValidLengthTest input to an AllocateArrayNode changes.
1995 void PhaseCCP::push_catch(Unique_Node_List& worklist, const Node* use) {
2018 if (cmpu_opcode == Op_CmpU || cmpu_opcode == Op_CmpU3) {
2019 // Got a CmpU or CmpU3 which might need the new type information from node n.
2020 push_if_not_bottom_type(worklist, cmpu);
2021 }
2022 }
2023 }
2024 }
2025
2026 // If n is used in a counted loop exit condition, then the type of the counted loop's Phi depends on the type of 'n'.
2027 // Seem PhiNode::Value().
2028 void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {
2029 uint use_op = use->Opcode();
2030 if (use_op == Op_CmpI || use_op == Op_CmpL) {
2031 PhiNode* phi = countedloop_phi_from_cmp(use->as_Cmp(), parent);
2032 if (phi != nullptr) {
2033 worklist.push(phi);
2034 }
2035 }
2036 }
2037
2038 void PhaseCCP::push_cast(Unique_Node_List& worklist, const Node* use) {
2039 uint use_op = use->Opcode();
2040 if (use_op == Op_CastP2X) {
2041 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2042 Node* u = use->fast_out(i2);
2043 if (u->Opcode() == Op_AndX) {
2044 worklist.push(u);
2045 }
2046 }
2047 }
2048 }
2049
2050 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
2051 // See LoadNode::Value().
2052 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
2053 BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
2054 bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
2055
2056 if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
2057 for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
2058 Node* loadp = use->fast_out(i);
2059 const Type* ut = loadp->bottom_type();
2060 if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
2061 if (has_load_barrier_nodes) {
2062 // Search for load barriers behind the load
2063 push_load_barrier(worklist, barrier_set, loadp);
2064 }
2065 worklist.push(loadp);
2066 }
2067 }
2068 }
2069 }
|