645 if( check_phi_clipping( phi, min, min_idx, max, max_idx, val, val_idx ) ) {
646 IfNode *top_if;
647 IfNode *bot_if;
648 if( check_if_clipping( this, bot_if, top_if ) ) {
649 // Control pattern checks, now verify compares
650 Node *top_in = NULL; // value being compared against
651 Node *bot_in = NULL;
652 if( check_compare_clipping( true, bot_if, min, bot_in ) &&
653 check_compare_clipping( false, top_if, max, top_in ) ) {
654 if( bot_in == top_in ) {
655 PhaseIterGVN *gvn = phase->is_IterGVN();
656 assert( gvn != NULL, "Only had DefUse info in IterGVN");
657 // Only remaining check is that bot_in == top_in == (Phi's val + mods)
658
659 // Check for the ConvF2INode
660 ConvF2INode *convf2i;
661 if( check_convf2i_clipping( phi, val_idx, convf2i, min, max ) &&
662 convf2i->in(1) == bot_in ) {
663 // Matched pattern, including LShiftI; RShiftI, replace with integer compares
664 // max test
665 Node *cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, min ));
666 Node *boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::lt ));
667 IfNode *iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( top_if->in(0), boo, PROB_UNLIKELY_MAG(5), top_if->_fcnt ));
668 Node *if_min= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));
669 Node *ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));
670 // min test
671 cmp = gvn->register_new_node_with_optimizer(new (phase->C) CmpINode( convf2i, max ));
672 boo = gvn->register_new_node_with_optimizer(new (phase->C) BoolNode( cmp, BoolTest::gt ));
673 iff = (IfNode*)gvn->register_new_node_with_optimizer(new (phase->C) IfNode( ifF, boo, PROB_UNLIKELY_MAG(5), bot_if->_fcnt ));
674 Node *if_max= gvn->register_new_node_with_optimizer(new (phase->C) IfTrueNode (iff));
675 ifF = gvn->register_new_node_with_optimizer(new (phase->C) IfFalseNode(iff));
676 // update input edges to region node
677 set_req_X( min_idx, if_min, gvn );
678 set_req_X( max_idx, if_max, gvn );
679 set_req_X( val_idx, ifF, gvn );
680 // remove unnecessary 'LShiftI; RShiftI' idiom
681 gvn->hash_delete(phi);
682 phi->set_req_X( val_idx, convf2i, gvn );
683 gvn->hash_find_insert(phi);
684 // Return transformed region node
685 return this;
686 }
687 }
688 }
689 }
690 }
691 }
692 }
693
694 return NULL;
695 }
714 //=============================================================================
715 // note that these functions assume that the _adr_type field is flattened
716 uint PhiNode::hash() const {
717 const Type* at = _adr_type;
718 return TypeNode::hash() + (at ? at->hash() : 0);
719 }
720 uint PhiNode::cmp( const Node &n ) const {
721 return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;
722 }
723 static inline
724 const TypePtr* flatten_phi_adr_type(const TypePtr* at) {
725 if (at == NULL || at == TypePtr::BOTTOM) return at;
726 return Compile::current()->alias_type(at)->adr_type();
727 }
728
729 //----------------------------make---------------------------------------------
730 // create a new phi with edges matching r and set (initially) to x
731 PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {
732 uint preds = r->req(); // Number of predecessor paths
733 assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");
734 PhiNode* p = new (Compile::current()) PhiNode(r, t, at);
735 for (uint j = 1; j < preds; j++) {
736 // Fill in all inputs, except those which the region does not yet have
737 if (r->in(j) != NULL)
738 p->init_req(j, x);
739 }
740 return p;
741 }
742 PhiNode* PhiNode::make(Node* r, Node* x) {
743 const Type* t = x->bottom_type();
744 const TypePtr* at = NULL;
745 if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());
746 return make(r, x, t, at);
747 }
748 PhiNode* PhiNode::make_blank(Node* r, Node* x) {
749 const Type* t = x->bottom_type();
750 const TypePtr* at = NULL;
751 if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());
752 return new (Compile::current()) PhiNode(r, t, at);
753 }
754
755
756 //------------------------slice_memory-----------------------------------------
757 // create a new phi with narrowed memory type
758 PhiNode* PhiNode::slice_memory(const TypePtr* adr_type) const {
759 PhiNode* mem = (PhiNode*) clone();
760 *(const TypePtr**)&mem->_adr_type = adr_type;
761 // convert self-loops, or else we get a bad graph
762 for (uint i = 1; i < req(); i++) {
763 if ((const Node*)in(i) == this) mem->set_req(i, mem);
764 }
765 mem->verify_adr_type();
766 return mem;
767 }
768
769 //------------------------split_out_instance-----------------------------------
770 // Split out an instance type from a bottom phi.
771 PhiNode* PhiNode::split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const {
772 const TypeOopPtr *t_oop = at->isa_oopptr();
1241 flipped = 1-flipped; // Test is vs 1 instead of 0!
1242 }
1243
1244 // Check for setting zero/one opposite expected
1245 if( tzero == TypeInt::ZERO ) {
1246 if( tone == TypeInt::ONE ) {
1247 } else return NULL;
1248 } else if( tzero == TypeInt::ONE ) {
1249 if( tone == TypeInt::ZERO ) {
1250 flipped = 1-flipped;
1251 } else return NULL;
1252 } else return NULL;
1253
1254 // Check for boolean test backwards
1255 if( b->_test._test == BoolTest::ne ) {
1256 } else if( b->_test._test == BoolTest::eq ) {
1257 flipped = 1-flipped;
1258 } else return NULL;
1259
1260 // Build int->bool conversion
1261 Node *n = new (phase->C) Conv2BNode( cmp->in(1) );
1262 if( flipped )
1263 n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
1264
1265 return n;
1266 }
1267
1268 //------------------------------is_cond_add------------------------------------
1269 // Check for simple conditional add pattern: "(P < Q) ? X+Y : X;"
1270 // To be profitable the control flow has to disappear; there can be no other
1271 // values merging here. We replace the test-and-branch with:
1272 // "(sgn(P-Q))&Y) + X". Basically, convert "(P < Q)" into 0 or -1 by
1273 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1274 // Then convert Y to 0-or-Y and finally add.
1275 // This is a key transform for SpecJava _201_compress.
1276 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1277 assert(true_path !=0, "only diamond shape graph expected");
1278
1279 // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1280 // phi->region->if_proj->ifnode->bool->cmp
1281 RegionNode *region = (RegionNode*)phi->in(0);
1282 Node *iff = region->in(1)->in(0);
1283 BoolNode* b = iff->in(1)->as_Bool();
1303 int op = n1->Opcode();
1304 if( op != Op_AddI // Need zero as additive identity
1305 /*&&op != Op_SubI &&
1306 op != Op_AddP &&
1307 op != Op_XorI &&
1308 op != Op_OrI*/ )
1309 return NULL;
1310
1311 Node *x = n2;
1312 Node *y = NULL;
1313 if( x == n1->in(1) ) {
1314 y = n1->in(2);
1315 } else if( x == n1->in(2) ) {
1316 y = n1->in(1);
1317 } else return NULL;
1318
1319 // Not so profitable if compare and add are constants
1320 if( q->is_Con() && phase->type(q) != TypeInt::ZERO && y->is_Con() )
1321 return NULL;
1322
1323 Node *cmplt = phase->transform( new (phase->C) CmpLTMaskNode(p,q) );
1324 Node *j_and = phase->transform( new (phase->C) AndINode(cmplt,y) );
1325 return new (phase->C) AddINode(j_and,x);
1326 }
1327
1328 //------------------------------is_absolute------------------------------------
1329 // Check for absolute value.
1330 static Node* is_absolute( PhaseGVN *phase, PhiNode *phi_root, int true_path) {
1331 assert(true_path !=0, "only diamond shape graph expected");
1332
1333 int cmp_zero_idx = 0; // Index of compare input where to look for zero
1334 int phi_x_idx = 0; // Index of phi input where to find naked x
1335
1336 // ABS ends with the merge of 2 control flow paths.
1337 // Find the false path from the true path. With only 2 inputs, 3 - x works nicely.
1338 int false_path = 3 - true_path;
1339
1340 // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1341 // phi->region->if_proj->ifnode->bool->cmp
1342 BoolNode *bol = phi_root->in(0)->in(1)->in(0)->in(1)->as_Bool();
1343
1344 // Check bool sense
1345 switch( bol->_test._test ) {
1367 } else if( phase->type(cmp->in(3 - cmp_zero_idx)) == tzero ) {
1368 // The test is inverted, we should invert the result...
1369 x = cmp->in(cmp_zero_idx);
1370 flip = true;
1371 } else {
1372 return NULL;
1373 }
1374
1375 // Next get the 2 pieces being selected, one is the original value
1376 // and the other is the negated value.
1377 if( phi_root->in(phi_x_idx) != x ) return NULL;
1378
1379 // Check other phi input for subtract node
1380 Node *sub = phi_root->in(3 - phi_x_idx);
1381
1382 // Allow only Sub(0,X) and fail out for all others; Neg is not OK
1383 if( tzero == TypeF::ZERO ) {
1384 if( sub->Opcode() != Op_SubF ||
1385 sub->in(2) != x ||
1386 phase->type(sub->in(1)) != tzero ) return NULL;
1387 x = new (phase->C) AbsFNode(x);
1388 if (flip) {
1389 x = new (phase->C) SubFNode(sub->in(1), phase->transform(x));
1390 }
1391 } else {
1392 if( sub->Opcode() != Op_SubD ||
1393 sub->in(2) != x ||
1394 phase->type(sub->in(1)) != tzero ) return NULL;
1395 x = new (phase->C) AbsDNode(x);
1396 if (flip) {
1397 x = new (phase->C) SubDNode(sub->in(1), phase->transform(x));
1398 }
1399 }
1400
1401 return x;
1402 }
1403
1404 //------------------------------split_once-------------------------------------
1405 // Helper for split_flow_path
1406 static void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) {
1407 igvn->hash_delete(n); // Remove from hash before hacking edges
1408
1409 uint j = 1;
1410 for (uint i = phi->req()-1; i > 0; i--) {
1411 if (phi->in(i) == val) { // Found a path with val?
1412 // Add to NEW Region/Phi, no DU info
1413 newn->set_req( j++, n->in(i) );
1414 // Remove from OLD Region/Phi
1415 n->del_req(i);
1416 }
1417 }
1452
1453 for( ; i < phi->req(); i++ ){ // Count occurrences of constant
1454 Node *n = phi->in(i);
1455 if( !n ) return NULL;
1456 if( phase->type(n) == Type::TOP ) return NULL;
1457 if( phi->in(i) == val ) {
1458 hit++;
1459 if (PhaseIdealLoop::find_predicate(r->in(i)) != NULL) {
1460 return NULL; // don't split loop entry path
1461 }
1462 }
1463 }
1464
1465 if( hit <= 1 || // Make sure we find 2 or more
1466 hit == phi->req()-1 ) // and not ALL the same value
1467 return NULL;
1468
1469 // Now start splitting out the flow paths that merge the same value.
1470 // Split first the RegionNode.
1471 PhaseIterGVN *igvn = phase->is_IterGVN();
1472 RegionNode *newr = new (phase->C) RegionNode(hit+1);
1473 split_once(igvn, phi, val, r, newr);
1474
1475 // Now split all other Phis than this one
1476 for (DUIterator_Fast kmax, k = r->fast_outs(kmax); k < kmax; k++) {
1477 Node* phi2 = r->fast_out(k);
1478 if( phi2->is_Phi() && phi2->as_Phi() != phi ) {
1479 PhiNode *newphi = PhiNode::make_blank(newr, phi2);
1480 split_once(igvn, phi, val, phi2, newphi);
1481 }
1482 }
1483
1484 // Clean up this guy
1485 igvn->hash_delete(phi);
1486 for( i = phi->req()-1; i > 0; i-- ) {
1487 if( phi->in(i) == val ) {
1488 phi->del_req(i);
1489 }
1490 }
1491 phi->add_req(val);
1492
1764 }
1765 Node* base = NULL;
1766 if (doit) {
1767 // Check for neighboring AddP nodes in a tree.
1768 // If they have a base, use that it.
1769 for (DUIterator_Fast kmax, k = this->fast_outs(kmax); k < kmax; k++) {
1770 Node* u = this->fast_out(k);
1771 if (u->is_AddP()) {
1772 Node* base2 = u->in(AddPNode::Base);
1773 if (base2 != NULL && !base2->is_top()) {
1774 if (base == NULL)
1775 base = base2;
1776 else if (base != base2)
1777 { doit = false; break; }
1778 }
1779 }
1780 }
1781 }
1782 if (doit) {
1783 if (base == NULL) {
1784 base = new (phase->C) PhiNode(in(0), type, NULL);
1785 for (uint i = 1; i < req(); i++) {
1786 base->init_req(i, in(i)->in(AddPNode::Base));
1787 }
1788 phase->is_IterGVN()->register_new_node_with_optimizer(base);
1789 }
1790 return new (phase->C) AddPNode(base, base, y);
1791 }
1792 }
1793 }
1794
1795 // Split phis through memory merges, so that the memory merges will go away.
1796 // Piggy-back this transformation on the search for a unique input....
1797 // It will be as if the merged memory is the unique value of the phi.
1798 // (Do not attempt this optimization unless parsing is complete.
1799 // It would make the parser's memory-merge logic sick.)
1800 // (MergeMemNode is not dead_loop_safe - need to check for dead loop.)
1801 if (progress == NULL && can_reshape && type() == Type::MEMORY) {
1802 // see if this phi should be sliced
1803 uint merge_width = 0;
1804 bool saw_self = false;
1805 for( uint i=1; i<req(); ++i ) {// For all paths in
1806 Node *ii = in(i);
1807 if (ii->is_MergeMem()) {
1808 MergeMemNode* n = ii->as_MergeMem();
1809 merge_width = MAX2(merge_width, n->req());
1810 saw_self = saw_self || phase->eqv(n->base_memory(), this);
1847 } else {
1848 // We know that at least one MergeMem->base_memory() == this
1849 // (saw_self == true). If all other inputs also references this phi
1850 // (directly or through data nodes) - it is dead loop.
1851 bool saw_safe_input = false;
1852 for (uint j = 1; j < req(); ++j) {
1853 Node *n = in(j);
1854 if (n->is_MergeMem() && n->as_MergeMem()->base_memory() == this)
1855 continue; // skip known cases
1856 if (!is_unsafe_data_reference(n)) {
1857 saw_safe_input = true; // found safe input
1858 break;
1859 }
1860 }
1861 if (!saw_safe_input)
1862 return top; // all inputs reference back to this phi - dead loop
1863
1864 // Phi(...MergeMem(m0, m1:AT1, m2:AT2)...) into
1865 // MergeMem(Phi(...m0...), Phi:AT1(...m1...), Phi:AT2(...m2...))
1866 PhaseIterGVN *igvn = phase->is_IterGVN();
1867 Node* hook = new (phase->C) Node(1);
1868 PhiNode* new_base = (PhiNode*) clone();
1869 // Must eagerly register phis, since they participate in loops.
1870 if (igvn) {
1871 igvn->register_new_node_with_optimizer(new_base);
1872 hook->add_req(new_base);
1873 }
1874 MergeMemNode* result = MergeMemNode::make(phase->C, new_base);
1875 for (uint i = 1; i < req(); ++i) {
1876 Node *ii = in(i);
1877 if (ii->is_MergeMem()) {
1878 MergeMemNode* n = ii->as_MergeMem();
1879 for (MergeMemStream mms(result, n); mms.next_non_empty2(); ) {
1880 // If we have not seen this slice yet, make a phi for it.
1881 bool made_new_phi = false;
1882 if (mms.is_empty()) {
1883 Node* new_phi = new_base->slice_memory(mms.adr_type(phase->C));
1884 made_new_phi = true;
1885 if (igvn) {
1886 igvn->register_new_node_with_optimizer(new_phi);
1887 hook->add_req(new_phi);
1944 if (ii->is_DecodeNarrowPtr() && ii->bottom_type() == bottom_type()) {
1945 // Do optimization if a non dead path exist.
1946 if (ii->in(1)->bottom_type() != Type::TOP) {
1947 has_decodeN = true;
1948 is_decodeN = ii->is_DecodeN();
1949 }
1950 } else if (!ii->is_Phi()) {
1951 may_push = false;
1952 }
1953 }
1954
1955 if (has_decodeN && may_push) {
1956 PhaseIterGVN *igvn = phase->is_IterGVN();
1957 // Make narrow type for new phi.
1958 const Type* narrow_t;
1959 if (is_decodeN) {
1960 narrow_t = TypeNarrowOop::make(this->bottom_type()->is_ptr());
1961 } else {
1962 narrow_t = TypeNarrowKlass::make(this->bottom_type()->is_ptr());
1963 }
1964 PhiNode* new_phi = new (phase->C) PhiNode(r, narrow_t);
1965 uint orig_cnt = req();
1966 for (uint i=1; i<req(); ++i) {// For all paths in
1967 Node *ii = in(i);
1968 Node* new_ii = NULL;
1969 if (ii->is_DecodeNarrowPtr()) {
1970 assert(ii->bottom_type() == bottom_type(), "sanity");
1971 new_ii = ii->in(1);
1972 } else {
1973 assert(ii->is_Phi(), "sanity");
1974 if (ii->as_Phi() == this) {
1975 new_ii = new_phi;
1976 } else {
1977 if (is_decodeN) {
1978 new_ii = new (phase->C) EncodePNode(ii, narrow_t);
1979 } else {
1980 new_ii = new (phase->C) EncodePKlassNode(ii, narrow_t);
1981 }
1982 igvn->register_new_node_with_optimizer(new_ii);
1983 }
1984 }
1985 new_phi->set_req(i, new_ii);
1986 }
1987 igvn->register_new_node_with_optimizer(new_phi, this);
1988 if (is_decodeN) {
1989 progress = new (phase->C) DecodeNNode(new_phi, bottom_type());
1990 } else {
1991 progress = new (phase->C) DecodeNKlassNode(new_phi, bottom_type());
1992 }
1993 }
1994 }
1995 #endif
1996
1997 return progress; // Return any progress
1998 }
1999
2000 //------------------------------is_tripcount-----------------------------------
2001 bool PhiNode::is_tripcount() const {
2002 return (in(0) != NULL && in(0)->is_CountedLoop() &&
2003 in(0)->as_CountedLoop()->phi() == this);
2004 }
2005
2006 //------------------------------out_RegMask------------------------------------
2007 const RegMask &PhiNode::in_RegMask(uint i) const {
2008 return i ? out_RegMask() : RegMask::Empty;
2009 }
2010
2011 const RegMask &PhiNode::out_RegMask() const {
|
645 if( check_phi_clipping( phi, min, min_idx, max, max_idx, val, val_idx ) ) {
646 IfNode *top_if;
647 IfNode *bot_if;
648 if( check_if_clipping( this, bot_if, top_if ) ) {
649 // Control pattern checks, now verify compares
650 Node *top_in = NULL; // value being compared against
651 Node *bot_in = NULL;
652 if( check_compare_clipping( true, bot_if, min, bot_in ) &&
653 check_compare_clipping( false, top_if, max, top_in ) ) {
654 if( bot_in == top_in ) {
655 PhaseIterGVN *gvn = phase->is_IterGVN();
656 assert( gvn != NULL, "Only had DefUse info in IterGVN");
657 // Only remaining check is that bot_in == top_in == (Phi's val + mods)
658
659 // Check for the ConvF2INode
660 ConvF2INode *convf2i;
661 if( check_convf2i_clipping( phi, val_idx, convf2i, min, max ) &&
662 convf2i->in(1) == bot_in ) {
663 // Matched pattern, including LShiftI; RShiftI, replace with integer compares
664 // max test
665 Node *cmp = gvn->register_new_node_with_optimizer(new CmpINode( convf2i, min ));
666 Node *boo = gvn->register_new_node_with_optimizer(new BoolNode( cmp, BoolTest::lt ));
667 IfNode *iff = (IfNode*)gvn->register_new_node_with_optimizer(new IfNode( top_if->in(0), boo, PROB_UNLIKELY_MAG(5), top_if->_fcnt ));
668 Node *if_min= gvn->register_new_node_with_optimizer(new IfTrueNode (iff));
669 Node *ifF = gvn->register_new_node_with_optimizer(new IfFalseNode(iff));
670 // min test
671 cmp = gvn->register_new_node_with_optimizer(new CmpINode( convf2i, max ));
672 boo = gvn->register_new_node_with_optimizer(new BoolNode( cmp, BoolTest::gt ));
673 iff = (IfNode*)gvn->register_new_node_with_optimizer(new IfNode( ifF, boo, PROB_UNLIKELY_MAG(5), bot_if->_fcnt ));
674 Node *if_max= gvn->register_new_node_with_optimizer(new IfTrueNode (iff));
675 ifF = gvn->register_new_node_with_optimizer(new IfFalseNode(iff));
676 // update input edges to region node
677 set_req_X( min_idx, if_min, gvn );
678 set_req_X( max_idx, if_max, gvn );
679 set_req_X( val_idx, ifF, gvn );
680 // remove unnecessary 'LShiftI; RShiftI' idiom
681 gvn->hash_delete(phi);
682 phi->set_req_X( val_idx, convf2i, gvn );
683 gvn->hash_find_insert(phi);
684 // Return transformed region node
685 return this;
686 }
687 }
688 }
689 }
690 }
691 }
692 }
693
694 return NULL;
695 }
714 //=============================================================================
715 // note that these functions assume that the _adr_type field is flattened
716 uint PhiNode::hash() const {
717 const Type* at = _adr_type;
718 return TypeNode::hash() + (at ? at->hash() : 0);
719 }
720 uint PhiNode::cmp( const Node &n ) const {
721 return TypeNode::cmp(n) && _adr_type == ((PhiNode&)n)._adr_type;
722 }
723 static inline
724 const TypePtr* flatten_phi_adr_type(const TypePtr* at) {
725 if (at == NULL || at == TypePtr::BOTTOM) return at;
726 return Compile::current()->alias_type(at)->adr_type();
727 }
728
729 //----------------------------make---------------------------------------------
730 // create a new phi with edges matching r and set (initially) to x
731 PhiNode* PhiNode::make(Node* r, Node* x, const Type *t, const TypePtr* at) {
732 uint preds = r->req(); // Number of predecessor paths
733 assert(t != Type::MEMORY || at == flatten_phi_adr_type(at), "flatten at");
734 PhiNode* p = new PhiNode(r, t, at);
735 for (uint j = 1; j < preds; j++) {
736 // Fill in all inputs, except those which the region does not yet have
737 if (r->in(j) != NULL)
738 p->init_req(j, x);
739 }
740 return p;
741 }
742 PhiNode* PhiNode::make(Node* r, Node* x) {
743 const Type* t = x->bottom_type();
744 const TypePtr* at = NULL;
745 if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());
746 return make(r, x, t, at);
747 }
748 PhiNode* PhiNode::make_blank(Node* r, Node* x) {
749 const Type* t = x->bottom_type();
750 const TypePtr* at = NULL;
751 if (t == Type::MEMORY) at = flatten_phi_adr_type(x->adr_type());
752 return new PhiNode(r, t, at);
753 }
754
755
756 //------------------------slice_memory-----------------------------------------
757 // create a new phi with narrowed memory type
758 PhiNode* PhiNode::slice_memory(const TypePtr* adr_type) const {
759 PhiNode* mem = (PhiNode*) clone();
760 *(const TypePtr**)&mem->_adr_type = adr_type;
761 // convert self-loops, or else we get a bad graph
762 for (uint i = 1; i < req(); i++) {
763 if ((const Node*)in(i) == this) mem->set_req(i, mem);
764 }
765 mem->verify_adr_type();
766 return mem;
767 }
768
769 //------------------------split_out_instance-----------------------------------
770 // Split out an instance type from a bottom phi.
771 PhiNode* PhiNode::split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const {
772 const TypeOopPtr *t_oop = at->isa_oopptr();
1241 flipped = 1-flipped; // Test is vs 1 instead of 0!
1242 }
1243
1244 // Check for setting zero/one opposite expected
1245 if( tzero == TypeInt::ZERO ) {
1246 if( tone == TypeInt::ONE ) {
1247 } else return NULL;
1248 } else if( tzero == TypeInt::ONE ) {
1249 if( tone == TypeInt::ZERO ) {
1250 flipped = 1-flipped;
1251 } else return NULL;
1252 } else return NULL;
1253
1254 // Check for boolean test backwards
1255 if( b->_test._test == BoolTest::ne ) {
1256 } else if( b->_test._test == BoolTest::eq ) {
1257 flipped = 1-flipped;
1258 } else return NULL;
1259
1260 // Build int->bool conversion
1261 Node *n = new Conv2BNode( cmp->in(1) );
1262 if( flipped )
1263 n = new XorINode( phase->transform(n), phase->intcon(1) );
1264
1265 return n;
1266 }
1267
1268 //------------------------------is_cond_add------------------------------------
1269 // Check for simple conditional add pattern: "(P < Q) ? X+Y : X;"
1270 // To be profitable the control flow has to disappear; there can be no other
1271 // values merging here. We replace the test-and-branch with:
1272 // "(sgn(P-Q))&Y) + X". Basically, convert "(P < Q)" into 0 or -1 by
1273 // moving the carry bit from (P-Q) into a register with 'sbb EAX,EAX'.
1274 // Then convert Y to 0-or-Y and finally add.
1275 // This is a key transform for SpecJava _201_compress.
1276 static Node* is_cond_add(PhaseGVN *phase, PhiNode *phi, int true_path) {
1277 assert(true_path !=0, "only diamond shape graph expected");
1278
1279 // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1280 // phi->region->if_proj->ifnode->bool->cmp
1281 RegionNode *region = (RegionNode*)phi->in(0);
1282 Node *iff = region->in(1)->in(0);
1283 BoolNode* b = iff->in(1)->as_Bool();
1303 int op = n1->Opcode();
1304 if( op != Op_AddI // Need zero as additive identity
1305 /*&&op != Op_SubI &&
1306 op != Op_AddP &&
1307 op != Op_XorI &&
1308 op != Op_OrI*/ )
1309 return NULL;
1310
1311 Node *x = n2;
1312 Node *y = NULL;
1313 if( x == n1->in(1) ) {
1314 y = n1->in(2);
1315 } else if( x == n1->in(2) ) {
1316 y = n1->in(1);
1317 } else return NULL;
1318
1319 // Not so profitable if compare and add are constants
1320 if( q->is_Con() && phase->type(q) != TypeInt::ZERO && y->is_Con() )
1321 return NULL;
1322
1323 Node *cmplt = phase->transform( new CmpLTMaskNode(p,q) );
1324 Node *j_and = phase->transform( new AndINode(cmplt,y) );
1325 return new AddINode(j_and,x);
1326 }
1327
1328 //------------------------------is_absolute------------------------------------
1329 // Check for absolute value.
1330 static Node* is_absolute( PhaseGVN *phase, PhiNode *phi_root, int true_path) {
1331 assert(true_path !=0, "only diamond shape graph expected");
1332
1333 int cmp_zero_idx = 0; // Index of compare input where to look for zero
1334 int phi_x_idx = 0; // Index of phi input where to find naked x
1335
1336 // ABS ends with the merge of 2 control flow paths.
1337 // Find the false path from the true path. With only 2 inputs, 3 - x works nicely.
1338 int false_path = 3 - true_path;
1339
1340 // is_diamond_phi() has guaranteed the correctness of the nodes sequence:
1341 // phi->region->if_proj->ifnode->bool->cmp
1342 BoolNode *bol = phi_root->in(0)->in(1)->in(0)->in(1)->as_Bool();
1343
1344 // Check bool sense
1345 switch( bol->_test._test ) {
1367 } else if( phase->type(cmp->in(3 - cmp_zero_idx)) == tzero ) {
1368 // The test is inverted, we should invert the result...
1369 x = cmp->in(cmp_zero_idx);
1370 flip = true;
1371 } else {
1372 return NULL;
1373 }
1374
1375 // Next get the 2 pieces being selected, one is the original value
1376 // and the other is the negated value.
1377 if( phi_root->in(phi_x_idx) != x ) return NULL;
1378
1379 // Check other phi input for subtract node
1380 Node *sub = phi_root->in(3 - phi_x_idx);
1381
1382 // Allow only Sub(0,X) and fail out for all others; Neg is not OK
1383 if( tzero == TypeF::ZERO ) {
1384 if( sub->Opcode() != Op_SubF ||
1385 sub->in(2) != x ||
1386 phase->type(sub->in(1)) != tzero ) return NULL;
1387 x = new AbsFNode(x);
1388 if (flip) {
1389 x = new SubFNode(sub->in(1), phase->transform(x));
1390 }
1391 } else {
1392 if( sub->Opcode() != Op_SubD ||
1393 sub->in(2) != x ||
1394 phase->type(sub->in(1)) != tzero ) return NULL;
1395 x = new AbsDNode(x);
1396 if (flip) {
1397 x = new SubDNode(sub->in(1), phase->transform(x));
1398 }
1399 }
1400
1401 return x;
1402 }
1403
1404 //------------------------------split_once-------------------------------------
1405 // Helper for split_flow_path
1406 static void split_once(PhaseIterGVN *igvn, Node *phi, Node *val, Node *n, Node *newn) {
1407 igvn->hash_delete(n); // Remove from hash before hacking edges
1408
1409 uint j = 1;
1410 for (uint i = phi->req()-1; i > 0; i--) {
1411 if (phi->in(i) == val) { // Found a path with val?
1412 // Add to NEW Region/Phi, no DU info
1413 newn->set_req( j++, n->in(i) );
1414 // Remove from OLD Region/Phi
1415 n->del_req(i);
1416 }
1417 }
1452
1453 for( ; i < phi->req(); i++ ){ // Count occurrences of constant
1454 Node *n = phi->in(i);
1455 if( !n ) return NULL;
1456 if( phase->type(n) == Type::TOP ) return NULL;
1457 if( phi->in(i) == val ) {
1458 hit++;
1459 if (PhaseIdealLoop::find_predicate(r->in(i)) != NULL) {
1460 return NULL; // don't split loop entry path
1461 }
1462 }
1463 }
1464
1465 if( hit <= 1 || // Make sure we find 2 or more
1466 hit == phi->req()-1 ) // and not ALL the same value
1467 return NULL;
1468
1469 // Now start splitting out the flow paths that merge the same value.
1470 // Split first the RegionNode.
1471 PhaseIterGVN *igvn = phase->is_IterGVN();
1472 RegionNode *newr = new RegionNode(hit+1);
1473 split_once(igvn, phi, val, r, newr);
1474
1475 // Now split all other Phis than this one
1476 for (DUIterator_Fast kmax, k = r->fast_outs(kmax); k < kmax; k++) {
1477 Node* phi2 = r->fast_out(k);
1478 if( phi2->is_Phi() && phi2->as_Phi() != phi ) {
1479 PhiNode *newphi = PhiNode::make_blank(newr, phi2);
1480 split_once(igvn, phi, val, phi2, newphi);
1481 }
1482 }
1483
1484 // Clean up this guy
1485 igvn->hash_delete(phi);
1486 for( i = phi->req()-1; i > 0; i-- ) {
1487 if( phi->in(i) == val ) {
1488 phi->del_req(i);
1489 }
1490 }
1491 phi->add_req(val);
1492
1764 }
1765 Node* base = NULL;
1766 if (doit) {
1767 // Check for neighboring AddP nodes in a tree.
1768 // If they have a base, use that it.
1769 for (DUIterator_Fast kmax, k = this->fast_outs(kmax); k < kmax; k++) {
1770 Node* u = this->fast_out(k);
1771 if (u->is_AddP()) {
1772 Node* base2 = u->in(AddPNode::Base);
1773 if (base2 != NULL && !base2->is_top()) {
1774 if (base == NULL)
1775 base = base2;
1776 else if (base != base2)
1777 { doit = false; break; }
1778 }
1779 }
1780 }
1781 }
1782 if (doit) {
1783 if (base == NULL) {
1784 base = new PhiNode(in(0), type, NULL);
1785 for (uint i = 1; i < req(); i++) {
1786 base->init_req(i, in(i)->in(AddPNode::Base));
1787 }
1788 phase->is_IterGVN()->register_new_node_with_optimizer(base);
1789 }
1790 return new AddPNode(base, base, y);
1791 }
1792 }
1793 }
1794
1795 // Split phis through memory merges, so that the memory merges will go away.
1796 // Piggy-back this transformation on the search for a unique input....
1797 // It will be as if the merged memory is the unique value of the phi.
1798 // (Do not attempt this optimization unless parsing is complete.
1799 // It would make the parser's memory-merge logic sick.)
1800 // (MergeMemNode is not dead_loop_safe - need to check for dead loop.)
1801 if (progress == NULL && can_reshape && type() == Type::MEMORY) {
1802 // see if this phi should be sliced
1803 uint merge_width = 0;
1804 bool saw_self = false;
1805 for( uint i=1; i<req(); ++i ) {// For all paths in
1806 Node *ii = in(i);
1807 if (ii->is_MergeMem()) {
1808 MergeMemNode* n = ii->as_MergeMem();
1809 merge_width = MAX2(merge_width, n->req());
1810 saw_self = saw_self || phase->eqv(n->base_memory(), this);
1847 } else {
1848 // We know that at least one MergeMem->base_memory() == this
1849 // (saw_self == true). If all other inputs also references this phi
1850 // (directly or through data nodes) - it is dead loop.
1851 bool saw_safe_input = false;
1852 for (uint j = 1; j < req(); ++j) {
1853 Node *n = in(j);
1854 if (n->is_MergeMem() && n->as_MergeMem()->base_memory() == this)
1855 continue; // skip known cases
1856 if (!is_unsafe_data_reference(n)) {
1857 saw_safe_input = true; // found safe input
1858 break;
1859 }
1860 }
1861 if (!saw_safe_input)
1862 return top; // all inputs reference back to this phi - dead loop
1863
1864 // Phi(...MergeMem(m0, m1:AT1, m2:AT2)...) into
1865 // MergeMem(Phi(...m0...), Phi:AT1(...m1...), Phi:AT2(...m2...))
1866 PhaseIterGVN *igvn = phase->is_IterGVN();
1867 Node* hook = new Node(1);
1868 PhiNode* new_base = (PhiNode*) clone();
1869 // Must eagerly register phis, since they participate in loops.
1870 if (igvn) {
1871 igvn->register_new_node_with_optimizer(new_base);
1872 hook->add_req(new_base);
1873 }
1874 MergeMemNode* result = MergeMemNode::make(phase->C, new_base);
1875 for (uint i = 1; i < req(); ++i) {
1876 Node *ii = in(i);
1877 if (ii->is_MergeMem()) {
1878 MergeMemNode* n = ii->as_MergeMem();
1879 for (MergeMemStream mms(result, n); mms.next_non_empty2(); ) {
1880 // If we have not seen this slice yet, make a phi for it.
1881 bool made_new_phi = false;
1882 if (mms.is_empty()) {
1883 Node* new_phi = new_base->slice_memory(mms.adr_type(phase->C));
1884 made_new_phi = true;
1885 if (igvn) {
1886 igvn->register_new_node_with_optimizer(new_phi);
1887 hook->add_req(new_phi);
1944 if (ii->is_DecodeNarrowPtr() && ii->bottom_type() == bottom_type()) {
1945 // Do optimization if a non dead path exist.
1946 if (ii->in(1)->bottom_type() != Type::TOP) {
1947 has_decodeN = true;
1948 is_decodeN = ii->is_DecodeN();
1949 }
1950 } else if (!ii->is_Phi()) {
1951 may_push = false;
1952 }
1953 }
1954
1955 if (has_decodeN && may_push) {
1956 PhaseIterGVN *igvn = phase->is_IterGVN();
1957 // Make narrow type for new phi.
1958 const Type* narrow_t;
1959 if (is_decodeN) {
1960 narrow_t = TypeNarrowOop::make(this->bottom_type()->is_ptr());
1961 } else {
1962 narrow_t = TypeNarrowKlass::make(this->bottom_type()->is_ptr());
1963 }
1964 PhiNode* new_phi = new PhiNode(r, narrow_t);
1965 uint orig_cnt = req();
1966 for (uint i=1; i<req(); ++i) {// For all paths in
1967 Node *ii = in(i);
1968 Node* new_ii = NULL;
1969 if (ii->is_DecodeNarrowPtr()) {
1970 assert(ii->bottom_type() == bottom_type(), "sanity");
1971 new_ii = ii->in(1);
1972 } else {
1973 assert(ii->is_Phi(), "sanity");
1974 if (ii->as_Phi() == this) {
1975 new_ii = new_phi;
1976 } else {
1977 if (is_decodeN) {
1978 new_ii = new EncodePNode(ii, narrow_t);
1979 } else {
1980 new_ii = new EncodePKlassNode(ii, narrow_t);
1981 }
1982 igvn->register_new_node_with_optimizer(new_ii);
1983 }
1984 }
1985 new_phi->set_req(i, new_ii);
1986 }
1987 igvn->register_new_node_with_optimizer(new_phi, this);
1988 if (is_decodeN) {
1989 progress = new DecodeNNode(new_phi, bottom_type());
1990 } else {
1991 progress = new DecodeNKlassNode(new_phi, bottom_type());
1992 }
1993 }
1994 }
1995 #endif
1996
1997 return progress; // Return any progress
1998 }
1999
2000 //------------------------------is_tripcount-----------------------------------
2001 bool PhiNode::is_tripcount() const {
2002 return (in(0) != NULL && in(0)->is_CountedLoop() &&
2003 in(0)->as_CountedLoop()->phi() == this);
2004 }
2005
2006 //------------------------------out_RegMask------------------------------------
2007 const RegMask &PhiNode::in_RegMask(uint i) const {
2008 return i ? out_RegMask() : RegMask::Empty;
2009 }
2010
2011 const RegMask &PhiNode::out_RegMask() const {
|