< prev index next >

src/hotspot/share/opto/ifnode.cpp

Print this page




 100     const TypePtr *tp = igvn->type(con1)->isa_ptr();
 101     if( tp && tp->_ptr == TypePtr::NotNull )
 102       break;
 103   }
 104   if( i4 >= phi->req() ) return NULL; // Found no constants
 105 
 106   igvn->C->set_has_split_ifs(true); // Has chance for split-if
 107 
 108   // Make sure that the compare can be constant folded away
 109   Node *cmp2 = cmp->clone();
 110   cmp2->set_req(1,con1);
 111   cmp2->set_req(2,con2);
 112   const Type *t = cmp2->Value(igvn);
 113   // This compare is dead, so whack it!
 114   igvn->remove_dead_node(cmp2);
 115   if( !t->singleton() ) return NULL;
 116 
 117   // No intervening control, like a simple Call
 118   Node *r = iff->in(0);
 119   if( !r->is_Region() ) return NULL;

 120   if( phi->region() != r ) return NULL;
 121   // No other users of the cmp/bool
 122   if (b->outcnt() != 1 || cmp->outcnt() != 1) {
 123     //tty->print_cr("many users of cmp/bool");
 124     return NULL;
 125   }
 126 
 127   // Make sure we can determine where all the uses of merged values go
 128   for (DUIterator_Fast jmax, j = r->fast_outs(jmax); j < jmax; j++) {
 129     Node* u = r->fast_out(j);
 130     if( u == r ) continue;
 131     if( u == iff ) continue;
 132     if( u->outcnt() == 0 ) continue; // use is dead & ignorable
 133     if( !u->is_Phi() ) {
 134       /*
 135       if( u->is_Start() ) {
 136         tty->print_cr("Region has inlined start use");
 137       } else {
 138         tty->print_cr("Region has odd use");
 139         u->dump(2);


1601   this->collect_nodes(out_rel, -2, false, false);
1602 }
1603 #endif
1604 
1605 //------------------------------idealize_test----------------------------------
1606 // Try to canonicalize tests better.  Peek at the Cmp/Bool/If sequence and
1607 // come up with a canonical sequence.  Bools getting 'eq', 'gt' and 'ge' forms
1608 // converted to 'ne', 'le' and 'lt' forms.  IfTrue/IfFalse get swapped as
1609 // needed.
1610 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) {
1611   assert(iff->in(0) != NULL, "If must be live");
1612 
1613   if (iff->outcnt() != 2)  return NULL; // Malformed projections.
1614   Node* old_if_f = iff->proj_out(false);
1615   Node* old_if_t = iff->proj_out(true);
1616 
1617   // CountedLoopEnds want the back-control test to be TRUE, irregardless of
1618   // whether they are testing a 'gt' or 'lt' condition.  The 'gt' condition
1619   // happens in count-down loops
1620   if (iff->is_CountedLoopEnd())  return NULL;










1621   if (!iff->in(1)->is_Bool())  return NULL; // Happens for partially optimized IF tests
1622   BoolNode *b = iff->in(1)->as_Bool();
1623   BoolTest bt = b->_test;
1624   // Test already in good order?
1625   if( bt.is_canonical() )
1626     return NULL;
1627 
1628   // Flip test to be canonical.  Requires flipping the IfFalse/IfTrue and
1629   // cloning the IfNode.
1630   Node* new_b = phase->transform( new BoolNode(b->in(1), bt.negate()) );
1631   if( !new_b->is_Bool() ) return NULL;
1632   b = new_b->as_Bool();
1633 
1634   PhaseIterGVN *igvn = phase->is_IterGVN();
1635   assert( igvn, "Test is not canonical in parser?" );
1636 
1637   // The IF node never really changes, but it needs to be cloned
1638   iff = iff->clone()->as_If();
1639   iff->set_req(1, b);
1640   iff->_prob = 1.0-iff->_prob;




 100     const TypePtr *tp = igvn->type(con1)->isa_ptr();
 101     if( tp && tp->_ptr == TypePtr::NotNull )
 102       break;
 103   }
 104   if( i4 >= phi->req() ) return NULL; // Found no constants
 105 
 106   igvn->C->set_has_split_ifs(true); // Has chance for split-if
 107 
 108   // Make sure that the compare can be constant folded away
 109   Node *cmp2 = cmp->clone();
 110   cmp2->set_req(1,con1);
 111   cmp2->set_req(2,con2);
 112   const Type *t = cmp2->Value(igvn);
 113   // This compare is dead, so whack it!
 114   igvn->remove_dead_node(cmp2);
 115   if( !t->singleton() ) return NULL;
 116 
 117   // No intervening control, like a simple Call
 118   Node *r = iff->in(0);
 119   if( !r->is_Region() ) return NULL;
 120   if (r->is_Loop() && r->in(LoopNode::LoopBackControl)->is_top()) return NULL; // going away anyway
 121   if( phi->region() != r ) return NULL;
 122   // No other users of the cmp/bool
 123   if (b->outcnt() != 1 || cmp->outcnt() != 1) {
 124     //tty->print_cr("many users of cmp/bool");
 125     return NULL;
 126   }
 127 
 128   // Make sure we can determine where all the uses of merged values go
 129   for (DUIterator_Fast jmax, j = r->fast_outs(jmax); j < jmax; j++) {
 130     Node* u = r->fast_out(j);
 131     if( u == r ) continue;
 132     if( u == iff ) continue;
 133     if( u->outcnt() == 0 ) continue; // use is dead & ignorable
 134     if( !u->is_Phi() ) {
 135       /*
 136       if( u->is_Start() ) {
 137         tty->print_cr("Region has inlined start use");
 138       } else {
 139         tty->print_cr("Region has odd use");
 140         u->dump(2);


1602   this->collect_nodes(out_rel, -2, false, false);
1603 }
1604 #endif
1605 
1606 //------------------------------idealize_test----------------------------------
1607 // Try to canonicalize tests better.  Peek at the Cmp/Bool/If sequence and
1608 // come up with a canonical sequence.  Bools getting 'eq', 'gt' and 'ge' forms
1609 // converted to 'ne', 'le' and 'lt' forms.  IfTrue/IfFalse get swapped as
1610 // needed.
1611 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) {
1612   assert(iff->in(0) != NULL, "If must be live");
1613 
1614   if (iff->outcnt() != 2)  return NULL; // Malformed projections.
1615   Node* old_if_f = iff->proj_out(false);
1616   Node* old_if_t = iff->proj_out(true);
1617 
1618   // CountedLoopEnds want the back-control test to be TRUE, irregardless of
1619   // whether they are testing a 'gt' or 'lt' condition.  The 'gt' condition
1620   // happens in count-down loops
1621   if (iff->is_CountedLoopEnd())  return NULL;
1622   Node* proj_true = iff->proj_out(true);
1623   if (proj_true->outcnt() == 1) {
1624     Node* c = proj_true->unique_out();
1625     // Leave test of outer strip mined loop alone
1626     if (c != NULL && c->is_Loop() &&
1627         c->in(LoopNode::LoopBackControl) == proj_true &&
1628         c->as_Loop()->is_strip_mined()) {
1629       return NULL;
1630     }
1631   }
1632   if (!iff->in(1)->is_Bool())  return NULL; // Happens for partially optimized IF tests
1633   BoolNode *b = iff->in(1)->as_Bool();
1634   BoolTest bt = b->_test;
1635   // Test already in good order?
1636   if( bt.is_canonical() )
1637     return NULL;
1638 
1639   // Flip test to be canonical.  Requires flipping the IfFalse/IfTrue and
1640   // cloning the IfNode.
1641   Node* new_b = phase->transform( new BoolNode(b->in(1), bt.negate()) );
1642   if( !new_b->is_Bool() ) return NULL;
1643   b = new_b->as_Bool();
1644 
1645   PhaseIterGVN *igvn = phase->is_IterGVN();
1646   assert( igvn, "Test is not canonical in parser?" );
1647 
1648   // The IF node never really changes, but it needs to be cloned
1649   iff = iff->clone()->as_If();
1650   iff->set_req(1, b);
1651   iff->_prob = 1.0-iff->_prob;


< prev index next >