1648 if (rc == NULL || phase->type(rc) == Type::TOP) { 1649 if (n != top) { // Not already top? 1650 PhaseIterGVN *igvn = phase->is_IterGVN(); 1651 if (can_reshape && igvn != NULL) { 1652 igvn->_worklist.push(r); 1653 } 1654 set_req(j, top); // Nuke it down 1655 progress = this; // Record progress 1656 } 1657 } 1658 } 1659 1660 if (can_reshape && outcnt() == 0) { 1661 // set_req() above may kill outputs if Phi is referenced 1662 // only by itself on the dead (top) control path. 1663 return top; 1664 } 1665 1666 bool uncasted = false; 1667 Node* uin = unique_input(phase, false); 1668 if (uin == NULL) { 1669 uncasted = true; 1670 uin = unique_input(phase, true); 1671 } 1672 if (uin == top) { // Simplest case: no alive inputs. 1673 if (can_reshape) // IGVN transformation 1674 return top; 1675 else 1676 return NULL; // Identity will return TOP 1677 } else if (uin != NULL) { 1678 // Only one not-NULL unique input path is left. 1679 // Determine if this input is backedge of a loop. 1680 // (Skip new phis which have no uses and dead regions). 1681 if (outcnt() > 0 && r->in(0) != NULL) { 1682 // First, take the short cut when we know it is a loop and 1683 // the EntryControl data path is dead. 1684 // Loop node may have only one input because entry path 1685 // is removed in PhaseIdealLoop::Dominators(). 1686 assert(!r->is_Loop() || r->req() <= 3, "Loop node should have 3 or less inputs"); 1687 bool is_loop = (r->is_Loop() && r->req() == 3); 1688 // Then, check if there is a data loop when phi references itself directly 1689 // or through other data nodes. 1690 if (is_loop && !uin->eqv_uncast(in(LoopNode::EntryControl)) || 1691 !is_loop && is_unsafe_data_reference(uin)) { 1692 // Break this data loop to avoid creation of a dead loop. 1693 if (can_reshape) { 1694 return top; 1695 } else { 1696 // We can't return top if we are in Parse phase - cut inputs only 1697 // let Identity to handle the case. 1698 replace_edge(uin, top); 1699 return NULL; 1700 } 1701 } 1702 } 1703 1704 if (uncasted) { 1705 const Type* phi_type = bottom_type(); 1706 assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type"); 1707 int opcode; 1708 if (phi_type->isa_int()) { 1709 opcode = Op_CastII; 1710 } else { 1711 const Type* uin_type = phase->type(uin); 1712 if (phi_type->join(TypePtr::NOTNULL) == uin_type->join(TypePtr::NOTNULL)) { 1713 opcode = Op_CastPP; 1714 } else { 1715 opcode = Op_CheckCastPP; 1716 } 1717 } 1718 // Add a cast to carry the control dependency of the Phi that is 1719 // going away 1720 Node* cast = ConstraintCastNode::make_cast(opcode, r, uin, phi_type, true); 1721 cast = phase->transform(cast); 1722 // set all inputs to the new cast so the Phi is removed by Identity 1723 for (uint i = 1; i < req(); i++) { 1724 set_req(i, cast); 1725 } 1726 uin = cast; 1727 } 1728 1729 // One unique input. 1730 debug_only(Node* ident = Identity(phase)); 1731 // The unique input must eventually be detected by the Identity call. 1732 #ifdef ASSERT 1733 if (ident != uin && !ident->is_top()) { 1734 // print this output before failing assert 1735 r->dump(3); 1736 this->dump(3); 1737 ident->dump(); 1738 uin->dump(); 1739 } 1740 #endif 1741 assert(ident == uin || ident->is_top(), "Identity must clean this up"); 1742 return NULL; 1743 } 1744 | 1648 if (rc == NULL || phase->type(rc) == Type::TOP) { 1649 if (n != top) { // Not already top? 1650 PhaseIterGVN *igvn = phase->is_IterGVN(); 1651 if (can_reshape && igvn != NULL) { 1652 igvn->_worklist.push(r); 1653 } 1654 set_req(j, top); // Nuke it down 1655 progress = this; // Record progress 1656 } 1657 } 1658 } 1659 1660 if (can_reshape && outcnt() == 0) { 1661 // set_req() above may kill outputs if Phi is referenced 1662 // only by itself on the dead (top) control path. 1663 return top; 1664 } 1665 1666 bool uncasted = false; 1667 Node* uin = unique_input(phase, false); 1668 if (uin == NULL && can_reshape) { 1669 uncasted = true; 1670 uin = unique_input(phase, true); 1671 } 1672 if (uin == top) { // Simplest case: no alive inputs. 1673 if (can_reshape) // IGVN transformation 1674 return top; 1675 else 1676 return NULL; // Identity will return TOP 1677 } else if (uin != NULL) { 1678 // Only one not-NULL unique input path is left. 1679 // Determine if this input is backedge of a loop. 1680 // (Skip new phis which have no uses and dead regions). 1681 if (outcnt() > 0 && r->in(0) != NULL) { 1682 // First, take the short cut when we know it is a loop and 1683 // the EntryControl data path is dead. 1684 // Loop node may have only one input because entry path 1685 // is removed in PhaseIdealLoop::Dominators(). 1686 assert(!r->is_Loop() || r->req() <= 3, "Loop node should have 3 or less inputs"); 1687 bool is_loop = (r->is_Loop() && r->req() == 3); 1688 // Then, check if there is a data loop when phi references itself directly 1689 // or through other data nodes. 1690 if (is_loop && !uin->eqv_uncast(in(LoopNode::EntryControl)) || 1691 !is_loop && is_unsafe_data_reference(uin)) { 1692 // Break this data loop to avoid creation of a dead loop. 1693 if (can_reshape) { 1694 return top; 1695 } else { 1696 // We can't return top if we are in Parse phase - cut inputs only 1697 // let Identity to handle the case. 1698 replace_edge(uin, top); 1699 return NULL; 1700 } 1701 } 1702 } 1703 1704 if (uncasted) { 1705 // Wait until after parsing for the type information to propagate from the casts 1706 assert(can_reshape, "Invalid during parsing"); 1707 const Type* phi_type = bottom_type(); 1708 assert(phi_type->isa_int() || phi_type->isa_ptr(), "bad phi type"); 1709 int opcode; 1710 if (phi_type->isa_int()) { 1711 opcode = Op_CastII; 1712 } else { 1713 const Type* uin_type = phase->type(uin); 1714 if (phi_type->join(TypePtr::NOTNULL) == uin_type->join(TypePtr::NOTNULL)) { 1715 opcode = Op_CastPP; 1716 } else { 1717 opcode = Op_CheckCastPP; 1718 } 1719 } 1720 // Add a cast to carry the control dependency of the Phi that is 1721 // going away 1722 Node* cast = ConstraintCastNode::make_cast(opcode, r, uin, phi_type, true); 1723 cast = phase->transform(cast); 1724 // set all inputs to the new cast so the Phi is removed by Identity 1725 PhaseIterGVN* igvn = phase->is_IterGVN(); 1726 for (uint i = 1; i < req(); i++) { 1727 set_req_X(i, cast, igvn); 1728 } 1729 uin = cast; 1730 } 1731 1732 // One unique input. 1733 debug_only(Node* ident = Identity(phase)); 1734 // The unique input must eventually be detected by the Identity call. 1735 #ifdef ASSERT 1736 if (ident != uin && !ident->is_top()) { 1737 // print this output before failing assert 1738 r->dump(3); 1739 this->dump(3); 1740 ident->dump(); 1741 uin->dump(); 1742 } 1743 #endif 1744 assert(ident == uin || ident->is_top(), "Identity must clean this up"); 1745 return NULL; 1746 } 1747 |