< prev index next >

src/hotspot/share/opto/loopopts.cpp

Print this page




  29 #include "memory/resourceArea.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/castnode.hpp"
  35 #include "opto/divnode.hpp"
  36 #include "opto/loopnode.hpp"
  37 #include "opto/matcher.hpp"
  38 #include "opto/mulnode.hpp"
  39 #include "opto/movenode.hpp"
  40 #include "opto/opaquenode.hpp"
  41 #include "opto/rootnode.hpp"
  42 #include "opto/subnode.hpp"
  43 #include "opto/subtypenode.hpp"
  44 #include "utilities/macros.hpp"
  45 
  46 //=============================================================================
  47 //------------------------------split_thru_phi---------------------------------
  48 // Split Node 'n' through merge point if there is enough win.
  49 Node *PhaseIdealLoop::split_thru_phi( Node *n, Node *region, int policy ) {
  50   if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) {
  51     // ConvI2L may have type information on it which is unsafe to push up
  52     // so disable this for now
  53     return NULL;
  54   }
  55 
  56   // Splitting range check CastIIs through a loop induction Phi can
  57   // cause new Phis to be created that are left unrelated to the loop
  58   // induction Phi and prevent optimizations (vectorization)
  59   if (n->Opcode() == Op_CastII && n->as_CastII()->has_range_check() &&
  60       region->is_CountedLoop() && n->in(1) == region->as_CountedLoop()->phi()) {
  61     return NULL;
  62   }
  63 



























  64   int wins = 0;
  65   assert(!n->is_CFG(), "");
  66   assert(region->is_Region(), "");
  67 
  68   const Type* type = n->bottom_type();
  69   const TypeOopPtr *t_oop = _igvn.type(n)->isa_oopptr();
  70   Node *phi;
  71   if (t_oop != NULL && t_oop->is_known_instance_field()) {
  72     int iid    = t_oop->instance_id();
  73     int index  = C->get_alias_index(t_oop);
  74     int offset = t_oop->offset();
  75     phi = new PhiNode(region, type, NULL, iid, index, offset);
  76   } else {
  77     phi = PhiNode::make_blank(region, n);
  78   }
  79   uint old_unique = C->unique();
  80   for (uint i = 1; i < region->req(); i++) {
  81     Node *x;
  82     Node* the_clone = NULL;
  83     if (region->in(i) == C->top()) {
  84       x = C->top();             // Dead path?  Use a dead data op
  85     } else {
  86       x = n->clone();           // Else clone up the data op
  87       the_clone = x;            // Remember for possible deletion.
  88       // Alter data node to use pre-phi inputs
  89       if (n->in(0) == region)
  90         x->set_req( 0, region->in(i) );
  91       for (uint j = 1; j < n->req(); j++) {
  92         Node *in = n->in(j);
  93         if (in->is_Phi() && in->in(0) == region)
  94           x->set_req( j, in->in(i) ); // Use pre-Phi input for the clone
  95       }
  96     }
  97     // Check for a 'win' on some paths
  98     const Type *t = x->Value(&_igvn);
  99 
 100     bool singleton = t->singleton();
 101 
 102     // A TOP singleton indicates that there are no possible values incoming
 103     // along a particular edge. In most cases, this is OK, and the Phi will
 104     // be eliminated later in an Ideal call. However, we can't allow this to
 105     // happen if the singleton occurs on loop entry, as the elimination of
 106     // the PhiNode may cause the resulting node to migrate back to a previous
 107     // loop iteration.
 108     if (singleton && t == Type::TOP) {
 109       // Is_Loop() == false does not confirm the absence of a loop (e.g., an
 110       // irreducible loop may not be indicated by an affirmative is_Loop());
 111       // therefore, the only top we can split thru a phi is on a backedge of
 112       // a loop.
 113       singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
 114     }
 115 
 116     if (singleton) {
 117       wins++;
 118       x = ((PhaseGVN&)_igvn).makecon(t);


 192     if (!new_loop->is_member(use_loop) &&
 193         (old_loop == NULL || !new_loop->is_member(old_loop))) {
 194       // Take early control, later control will be recalculated
 195       // during next iteration of loop optimizations.
 196       new_ctrl = get_early_ctrl(x);
 197       new_loop = get_loop(new_ctrl);
 198     }
 199     // Set new location
 200     set_ctrl(x, new_ctrl);
 201     // If changing loop bodies, see if we need to collect into new body
 202     if (old_loop != new_loop) {
 203       if (old_loop && !old_loop->_child)
 204         old_loop->_body.yank(x);
 205       if (!new_loop->_child)
 206         new_loop->_body.push(x);  // Collect body info
 207     }
 208   }
 209 
 210   return phi;
 211 }
















 212 
 213 //------------------------------dominated_by------------------------------------
 214 // Replace the dominated test with an obvious true or false.  Place it on the
 215 // IGVN worklist for later cleanup.  Move control-dependent data Nodes on the
 216 // live path up to the dominating control.
 217 void PhaseIdealLoop::dominated_by( Node *prevdom, Node *iff, bool flip, bool exclude_loop_predicate ) {
 218   if (VerifyLoopOptimizations && PrintOpto) { tty->print_cr("dominating test"); }
 219 
 220   // prevdom is the dominating projection of the dominating test.
 221   assert( iff->is_If(), "" );
 222   assert(iff->Opcode() == Op_If || iff->Opcode() == Op_CountedLoopEnd || iff->Opcode() == Op_RangeCheck, "Check this code when new subtype is added");
 223   int pop = prevdom->Opcode();
 224   assert( pop == Op_IfFalse || pop == Op_IfTrue, "" );
 225   if (flip) {
 226     if (pop == Op_IfTrue)
 227       pop = Op_IfFalse;
 228     else
 229       pop = Op_IfTrue;
 230   }
 231   // 'con' is set to true or false to kill the dominated test.




  29 #include "memory/resourceArea.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/connode.hpp"
  34 #include "opto/castnode.hpp"
  35 #include "opto/divnode.hpp"
  36 #include "opto/loopnode.hpp"
  37 #include "opto/matcher.hpp"
  38 #include "opto/mulnode.hpp"
  39 #include "opto/movenode.hpp"
  40 #include "opto/opaquenode.hpp"
  41 #include "opto/rootnode.hpp"
  42 #include "opto/subnode.hpp"
  43 #include "opto/subtypenode.hpp"
  44 #include "utilities/macros.hpp"
  45 
  46 //=============================================================================
  47 //------------------------------split_thru_phi---------------------------------
  48 // Split Node 'n' through merge point if there is enough win.
  49 Node* PhaseIdealLoop::split_thru_phi(Node* n, Node* region, int policy) {
  50   if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) {
  51     // ConvI2L may have type information on it which is unsafe to push up
  52     // so disable this for now
  53     return NULL;
  54   }
  55 
  56   // Splitting range check CastIIs through a loop induction Phi can
  57   // cause new Phis to be created that are left unrelated to the loop
  58   // induction Phi and prevent optimizations (vectorization)
  59   if (n->Opcode() == Op_CastII && n->as_CastII()->has_range_check() &&
  60       region->is_CountedLoop() && n->in(1) == region->as_CountedLoop()->phi()) {
  61     return NULL;
  62   }
  63 
  64   // Bail out if 'n' is a Div or Mod node whose zero check was removed earlier (i.e. control is NULL) and its divisor is a phi node d_phi whose
  65   // inputs could be zero (include zero in their type range). This can only happen if d_phi is an induction variable of a trip-counted (integer)
  66   // loop. d_phi could have a more precise type range that does not necessarily include all values of its inputs. Since each of these inputs will
  67   // be a divisor of the newly cloned nodes of 'n', we need to bail out of one of these divisors could be zero (zero in its type range).
  68   if ((n->Opcode() == Op_DivI || n->Opcode() == Op_ModI) && n->in(0) == NULL
  69       && region->is_CountedLoop() && n->in(2) == region->as_CountedLoop()->phi()) {
  70     Node* phi = region->as_CountedLoop()->phi();
  71     for (uint i = 1; i < phi->req(); i++) {
  72       if (_igvn.type(phi->in(i))->filter_speculative(TypeInt::ZERO) != Type::TOP) {
  73         // Zero could be a possible value but we already removed the zero check. Bail out to avoid a possible division by zero at a later point.
  74         return NULL;
  75       }
  76     }
  77   }
  78 
  79 #ifdef ASSERT
  80   // A phi only has a more precise type than its inputs if it is an induction variable of a trip-counted integer loop. Verify that this is the
  81   // case and we are not about to split a Mod or Div node without zero check that could end up with a new divisor that can be zero.
  82   // A split of a division by a floating point zero, on the other hand, is not a problem since the result would just be INFINITY as floating point
  83   // representation and does not result in an exception.
  84   if ((n->Opcode() == Op_DivI || n->Opcode() == Op_ModI)) {
  85     check_divide_by_zero(n, TypeInt::ZERO);
  86   } else if ((n->Opcode() == Op_DivL || n->Opcode() == Op_ModL)) {
  87     check_divide_by_zero(n, TypeLong::ZERO);
  88   }
  89 #endif
  90 
  91   int wins = 0;
  92   assert(!n->is_CFG(), "");
  93   assert(region->is_Region(), "");
  94 
  95   const Type* type = n->bottom_type();
  96   const TypeOopPtr* t_oop = _igvn.type(n)->isa_oopptr();
  97   Node* phi;
  98   if (t_oop != NULL && t_oop->is_known_instance_field()) {
  99     int iid    = t_oop->instance_id();
 100     int index  = C->get_alias_index(t_oop);
 101     int offset = t_oop->offset();
 102     phi = new PhiNode(region, type, NULL, iid, index, offset);
 103   } else {
 104     phi = PhiNode::make_blank(region, n);
 105   }
 106   uint old_unique = C->unique();
 107   for (uint i = 1; i < region->req(); i++) {
 108     Node* x;
 109     Node* the_clone = NULL;
 110     if (region->in(i) == C->top()) {
 111       x = C->top();             // Dead path?  Use a dead data op
 112     } else {
 113       x = n->clone();           // Else clone up the data op
 114       the_clone = x;            // Remember for possible deletion.
 115       // Alter data node to use pre-phi inputs
 116       if (n->in(0) == region)
 117         x->set_req( 0, region->in(i) );
 118       for (uint j = 1; j < n->req(); j++) {
 119         Node* in = n->in(j);
 120         if (in->is_Phi() && in->in(0) == region)
 121           x->set_req(j, in->in(i)); // Use pre-Phi input for the clone
 122       }
 123     }
 124     // Check for a 'win' on some paths
 125     const Type* t = x->Value(&_igvn);
 126 
 127     bool singleton = t->singleton();
 128 
 129     // A TOP singleton indicates that there are no possible values incoming
 130     // along a particular edge. In most cases, this is OK, and the Phi will
 131     // be eliminated later in an Ideal call. However, we can't allow this to
 132     // happen if the singleton occurs on loop entry, as the elimination of
 133     // the PhiNode may cause the resulting node to migrate back to a previous
 134     // loop iteration.
 135     if (singleton && t == Type::TOP) {
 136       // Is_Loop() == false does not confirm the absence of a loop (e.g., an
 137       // irreducible loop may not be indicated by an affirmative is_Loop());
 138       // therefore, the only top we can split thru a phi is on a backedge of
 139       // a loop.
 140       singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
 141     }
 142 
 143     if (singleton) {
 144       wins++;
 145       x = ((PhaseGVN&)_igvn).makecon(t);


 219     if (!new_loop->is_member(use_loop) &&
 220         (old_loop == NULL || !new_loop->is_member(old_loop))) {
 221       // Take early control, later control will be recalculated
 222       // during next iteration of loop optimizations.
 223       new_ctrl = get_early_ctrl(x);
 224       new_loop = get_loop(new_ctrl);
 225     }
 226     // Set new location
 227     set_ctrl(x, new_ctrl);
 228     // If changing loop bodies, see if we need to collect into new body
 229     if (old_loop != new_loop) {
 230       if (old_loop && !old_loop->_child)
 231         old_loop->_body.yank(x);
 232       if (!new_loop->_child)
 233         new_loop->_body.push(x);  // Collect body info
 234     }
 235   }
 236 
 237   return phi;
 238 }
 239 
 240 #ifdef ASSERT
 241 void PhaseIdealLoop::check_divide_by_zero(const Node* n, const Type* zero) const {
 242   if (n->in(0) == NULL && n->in(2)->is_Phi()) {
 243     Node* phi = n->in(2);
 244     for (uint i = 1; i < phi->req(); i++) {
 245       if (_igvn.type(phi->in(i))->filter_speculative(zero) != Type::TOP) {
 246         // Zero could be a possible value
 247         n->dump(2);
 248         phi->dump(2);
 249         assert(false, "should not happen that pre-phi type includes zero as possible value but zero check was already removed");
 250       }
 251     }
 252   }
 253 }
 254 #endif
 255 
 256 //------------------------------dominated_by------------------------------------
 257 // Replace the dominated test with an obvious true or false.  Place it on the
 258 // IGVN worklist for later cleanup.  Move control-dependent data Nodes on the
 259 // live path up to the dominating control.
 260 void PhaseIdealLoop::dominated_by( Node *prevdom, Node *iff, bool flip, bool exclude_loop_predicate ) {
 261   if (VerifyLoopOptimizations && PrintOpto) { tty->print_cr("dominating test"); }
 262 
 263   // prevdom is the dominating projection of the dominating test.
 264   assert( iff->is_If(), "" );
 265   assert(iff->Opcode() == Op_If || iff->Opcode() == Op_CountedLoopEnd || iff->Opcode() == Op_RangeCheck, "Check this code when new subtype is added");
 266   int pop = prevdom->Opcode();
 267   assert( pop == Op_IfFalse || pop == Op_IfTrue, "" );
 268   if (flip) {
 269     if (pop == Op_IfTrue)
 270       pop = Op_IfFalse;
 271     else
 272       pop = Op_IfTrue;
 273   }
 274   // 'con' is set to true or false to kill the dominated test.


< prev index next >