< prev index next >

src/share/vm/opto/loopTransform.cpp

Print this page




1507 #ifndef PRODUCT
1508   if (TraceLoopOpts) {
1509     tty->print("MaxUnroll  %d ", cl->trip_count());
1510     loop->dump_head();
1511   }
1512 #endif
1513 
1514   // If loop is tripping an odd number of times, peel odd iteration
1515   if ((cl->trip_count() & 1) == 1) {
1516     do_peeling(loop, old_new);
1517   }
1518 
1519   // Now its tripping an even number of times remaining.  Double loop body.
1520   // Do not adjust pre-guards; they are not needed and do not exist.
1521   if (cl->trip_count() > 0) {
1522     assert((cl->trip_count() & 1) == 0, "missed peeling");
1523     do_unroll(loop, old_new, false);
1524   }
1525 }
1526 




































































1527 //------------------------------dominates_backedge---------------------------------
1528 // Returns true if ctrl is executed on every complete iteration
1529 bool IdealLoopTree::dominates_backedge(Node* ctrl) {
1530   assert(ctrl->is_CFG(), "must be control");
1531   Node* backedge = _head->as_Loop()->in(LoopNode::LoopBackControl);
1532   return _phase->dom_lca_internal(ctrl, backedge) == ctrl;
1533 }
1534 
1535 //------------------------------adjust_limit-----------------------------------
1536 // Helper function for add_constraint().
1537 Node* PhaseIdealLoop::adjust_limit(int stride_con, Node * scale, Node *offset, Node *rc_limit, Node *loop_limit, Node *pre_ctrl) {
1538   // Compute "I :: (limit-offset)/scale"
1539   Node *con = new SubINode(rc_limit, offset);
1540   register_new_node(con, pre_ctrl);
1541   Node *X = new DivINode(0, con, scale);
1542   register_new_node(X, pre_ctrl);
1543 
1544   // Adjust loop limit
1545   loop_limit = (stride_con > 0)
1546                ? (Node*)(new MinINode(loop_limit, X))


2344   bool may_rce_align = !policy_peel_only(phase) || should_rce || should_align;
2345 
2346   // If we have any of these conditions (RCE, alignment, unrolling) met, then
2347   // we switch to the pre-/main-/post-loop model.  This model also covers
2348   // peeling.
2349   if (should_rce || should_align || should_unroll) {
2350     if (cl->is_normal_loop())  // Convert to 'pre/main/post' loops
2351       phase->insert_pre_post_loops(this,old_new, !may_rce_align);
2352 
2353     // Adjust the pre- and main-loop limits to let the pre and post loops run
2354     // with full checks, but the main-loop with no checks.  Remove said
2355     // checks from the main body.
2356     if (should_rce)
2357       phase->do_range_check(this,old_new);
2358 
2359     // Double loop body for unrolling.  Adjust the minimum-trip test (will do
2360     // twice as many iterations as before) and the main body limit (only do
2361     // an even number of trips).  If we are peeling, we might enable some RCE
2362     // and we'd rather unroll the post-RCE'd loop SO... do not unroll if
2363     // peeling.
2364     if (should_unroll && !should_peel)
2365       phase->do_unroll(this,old_new, true);


2366 
2367     // Adjust the pre-loop limits to align the main body
2368     // iterations.
2369     if (should_align)
2370       Unimplemented();
2371 
2372   } else {                      // Else we have an unchanged counted loop
2373     if (should_peel)           // Might want to peel but do nothing else
2374       phase->do_peeling(this,old_new);
2375   }
2376   return true;
2377 }
2378 
2379 
2380 //=============================================================================
2381 //------------------------------iteration_split--------------------------------
2382 bool IdealLoopTree::iteration_split( PhaseIdealLoop *phase, Node_List &old_new ) {
2383   // Recursively iteration split nested loops
2384   if (_child && !_child->iteration_split(phase, old_new))
2385     return false;




1507 #ifndef PRODUCT
1508   if (TraceLoopOpts) {
1509     tty->print("MaxUnroll  %d ", cl->trip_count());
1510     loop->dump_head();
1511   }
1512 #endif
1513 
1514   // If loop is tripping an odd number of times, peel odd iteration
1515   if ((cl->trip_count() & 1) == 1) {
1516     do_peeling(loop, old_new);
1517   }
1518 
1519   // Now its tripping an even number of times remaining.  Double loop body.
1520   // Do not adjust pre-guards; they are not needed and do not exist.
1521   if (cl->trip_count() > 0) {
1522     assert((cl->trip_count() & 1) == 0, "missed peeling");
1523     do_unroll(loop, old_new, false);
1524   }
1525 }
1526 
1527 void PhaseIdealLoop::mark_reductions(IdealLoopTree *loop) {
1528   if (SuperWordReductions == false) return;
1529 
1530   for (uint i = 0; i < loop->_body.size(); i++) {
1531     Node *n = loop->_body[i];
1532     if (n != NULL && n->is_Phi()) {
1533       PhiNode *phi = n->as_Phi();
1534       // for definitions which are loop inclusive and not tripcounts
1535       if (phi != NULL && phi->is_tripcount() == false) {
1536         uint len = n->len();
1537         Node *defNode = n->in(len - 1);
1538 
1539         if (defNode != NULL) {
1540           Node *n_ctrl = get_ctrl(defNode);
1541           if (n_ctrl != NULL && loop->is_member(get_loop(n_ctrl))) {
1542             uint flags = defNode->flags();
1543 
1544             // This is a loop carried depedence, set if needed
1545             if ((flags & Node::Flag_is_loop_carried_dep) != Node::Flag_is_loop_carried_dep)
1546               defNode->add_flag(Node::Flag_is_loop_carried_dep);
1547 
1548             // now test it to see if it fits the standard pattern for a reduction operator
1549             switch (defNode->Opcode()) {
1550               // the communitative operators
1551             case Op_AddI:
1552             case Op_AddL:
1553             case Op_AddF:
1554             case Op_AddD:
1555             case Op_MulI:
1556             case Op_MulL:
1557             case Op_MulF:
1558             case Op_MulD:
1559               if ((flags & Node::Flag_has_reduction) != Node::Flag_has_reduction)
1560               {
1561                 // To be a reduction, the arithmetic node must source the phi and provide a def to it
1562                 int end = defNode->req();
1563                 for (int j = 1; j < end; j++) {
1564                   Node* in = defNode->in(j);
1565                   if (in == n){
1566                     defNode->add_flag(Node::Flag_has_reduction);
1567                     break;
1568                   }
1569                 }
1570               }
1571               break;
1572 
1573               // the non communitative operators
1574             case Op_DivI:
1575             case Op_DivL:
1576             case Op_DivF:
1577             case Op_DivD:
1578             case Op_SubI:
1579             case Op_SubL:
1580             case Op_SubF:
1581             case Op_SubD:
1582               // TODO: these need ordering constraints
1583               break;
1584 
1585             default:
1586               break;
1587             }
1588           }
1589         }
1590       }
1591     }
1592   }
1593 }
1594 
1595 //------------------------------dominates_backedge---------------------------------
1596 // Returns true if ctrl is executed on every complete iteration
1597 bool IdealLoopTree::dominates_backedge(Node* ctrl) {
1598   assert(ctrl->is_CFG(), "must be control");
1599   Node* backedge = _head->as_Loop()->in(LoopNode::LoopBackControl);
1600   return _phase->dom_lca_internal(ctrl, backedge) == ctrl;
1601 }
1602 
1603 //------------------------------adjust_limit-----------------------------------
1604 // Helper function for add_constraint().
1605 Node* PhaseIdealLoop::adjust_limit(int stride_con, Node * scale, Node *offset, Node *rc_limit, Node *loop_limit, Node *pre_ctrl) {
1606   // Compute "I :: (limit-offset)/scale"
1607   Node *con = new SubINode(rc_limit, offset);
1608   register_new_node(con, pre_ctrl);
1609   Node *X = new DivINode(0, con, scale);
1610   register_new_node(X, pre_ctrl);
1611 
1612   // Adjust loop limit
1613   loop_limit = (stride_con > 0)
1614                ? (Node*)(new MinINode(loop_limit, X))


2412   bool may_rce_align = !policy_peel_only(phase) || should_rce || should_align;
2413 
2414   // If we have any of these conditions (RCE, alignment, unrolling) met, then
2415   // we switch to the pre-/main-/post-loop model.  This model also covers
2416   // peeling.
2417   if (should_rce || should_align || should_unroll) {
2418     if (cl->is_normal_loop())  // Convert to 'pre/main/post' loops
2419       phase->insert_pre_post_loops(this,old_new, !may_rce_align);
2420 
2421     // Adjust the pre- and main-loop limits to let the pre and post loops run
2422     // with full checks, but the main-loop with no checks.  Remove said
2423     // checks from the main body.
2424     if (should_rce)
2425       phase->do_range_check(this,old_new);
2426 
2427     // Double loop body for unrolling.  Adjust the minimum-trip test (will do
2428     // twice as many iterations as before) and the main body limit (only do
2429     // an even number of trips).  If we are peeling, we might enable some RCE
2430     // and we'd rather unroll the post-RCE'd loop SO... do not unroll if
2431     // peeling.
2432     if (should_unroll && !should_peel) {
2433       phase->mark_reductions(this);
2434       phase->do_unroll(this, old_new, true);
2435     }
2436 
2437     // Adjust the pre-loop limits to align the main body
2438     // iterations.
2439     if (should_align)
2440       Unimplemented();
2441 
2442   } else {                      // Else we have an unchanged counted loop
2443     if (should_peel)           // Might want to peel but do nothing else
2444       phase->do_peeling(this,old_new);
2445   }
2446   return true;
2447 }
2448 
2449 
2450 //=============================================================================
2451 //------------------------------iteration_split--------------------------------
2452 bool IdealLoopTree::iteration_split( PhaseIdealLoop *phase, Node_List &old_new ) {
2453   // Recursively iteration split nested loops
2454   if (_child && !_child->iteration_split(phase, old_new))
2455     return false;


< prev index next >