1363 // Canonicalize the test. |
1368 // Canonicalize the test. |
1364 Node* idt_if = idealize_test(phase, this); |
1369 Node* idt_if = idealize_test(phase, this); |
1365 if (idt_if != NULL) return idt_if; |
1370 if (idt_if != NULL) return idt_if; |
1366 |
1371 |
1367 // Try to split the IF |
1372 // Try to split the IF |
|
1373 PhaseIterGVN *igvn = phase->is_IterGVN(); |
1368 Node *s = split_if(this, igvn); |
1374 Node *s = split_if(this, igvn); |
1369 if (s != NULL) return s; |
1375 if (s != NULL) return s; |
|
1376 |
|
1377 return NodeSentinel; |
|
1378 } |
|
1379 |
|
1380 //------------------------------Ideal------------------------------------------ |
|
1381 // Return a node which is more "ideal" than the current node. Strip out |
|
1382 // control copies |
|
1383 Node* IfNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
1384 Node* res = Ideal_common(phase, can_reshape); |
|
1385 if (res != NodeSentinel) { |
|
1386 return res; |
|
1387 } |
1370 |
1388 |
1371 // Check for people making a useless boolean: things like |
1389 // Check for people making a useless boolean: things like |
1372 // if( (x < y ? true : false) ) { ... } |
1390 // if( (x < y ? true : false) ) { ... } |
1373 // Replace with if( x < y ) { ... } |
1391 // Replace with if( x < y ) { ... } |
1374 Node *bol2 = remove_useless_bool(this, phase); |
1392 Node *bol2 = remove_useless_bool(this, phase); |
1375 if( bol2 ) return bol2; |
1393 if( bol2 ) return bol2; |
1376 |
1394 |
|
1395 if (in(0) == NULL) return NULL; // Dead loop? |
|
1396 |
|
1397 PhaseIterGVN *igvn = phase->is_IterGVN(); |
|
1398 Node* result = fold_compares(igvn); |
|
1399 if (result != NULL) { |
|
1400 return result; |
|
1401 } |
|
1402 |
|
1403 // Scan for an equivalent test |
|
1404 Node *cmp; |
|
1405 int dist = 0; // Cutoff limit for search |
|
1406 int op = Opcode(); |
|
1407 if( op == Op_If && |
|
1408 (cmp=in(1)->in(1))->Opcode() == Op_CmpP ) { |
|
1409 if( cmp->in(2) != NULL && // make sure cmp is not already dead |
|
1410 cmp->in(2)->bottom_type() == TypePtr::NULL_PTR ) { |
|
1411 dist = 64; // Limit for null-pointer scans |
|
1412 } else { |
|
1413 dist = 4; // Do not bother for random pointer tests |
|
1414 } |
|
1415 } else { |
|
1416 dist = 4; // Limit for random junky scans |
|
1417 } |
|
1418 |
|
1419 Node* prev_dom = search_identical(dist); |
|
1420 |
|
1421 if (prev_dom == NULL) { |
|
1422 return NULL; |
|
1423 } |
|
1424 |
|
1425 // Replace dominated IfNode |
|
1426 return dominated_by(prev_dom, igvn); |
|
1427 } |
|
1428 |
|
1429 //------------------------------dominated_by----------------------------------- |
|
1430 Node* IfNode::dominated_by(Node* prev_dom, PhaseIterGVN *igvn) { |
|
1431 #ifndef PRODUCT |
|
1432 if (TraceIterativeGVN) { |
|
1433 tty->print(" Removing IfNode: "); this->dump(); |
|
1434 } |
|
1435 if (VerifyOpto && !igvn->allow_progress()) { |
|
1436 // Found an equivalent dominating test, |
|
1437 // we can not guarantee reaching a fix-point for these during iterativeGVN |
|
1438 // since intervening nodes may not change. |
|
1439 return NULL; |
|
1440 } |
|
1441 #endif |
|
1442 |
|
1443 igvn->hash_delete(this); // Remove self to prevent spurious V-N |
|
1444 Node *idom = in(0); |
|
1445 // Need opcode to decide which way 'this' test goes |
|
1446 int prev_op = prev_dom->Opcode(); |
|
1447 Node *top = igvn->C->top(); // Shortcut to top |
|
1448 |
|
1449 // Loop predicates may have depending checks which should not |
|
1450 // be skipped. For example, range check predicate has two checks |
|
1451 // for lower and upper bounds. |
|
1452 ProjNode* unc_proj = proj_out(1 - prev_dom->as_Proj()->_con)->as_Proj(); |
|
1453 if (unc_proj->is_uncommon_trap_proj(Deoptimization::Reason_predicate) != NULL) |
|
1454 prev_dom = idom; |
|
1455 |
|
1456 // Now walk the current IfNode's projections. |
|
1457 // Loop ends when 'this' has no more uses. |
|
1458 for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) { |
|
1459 Node *ifp = last_out(i); // Get IfTrue/IfFalse |
|
1460 igvn->add_users_to_worklist(ifp); |
|
1461 // Check which projection it is and set target. |
|
1462 // Data-target is either the dominating projection of the same type |
|
1463 // or TOP if the dominating projection is of opposite type. |
|
1464 // Data-target will be used as the new control edge for the non-CFG |
|
1465 // nodes like Casts and Loads. |
|
1466 Node *data_target = (ifp->Opcode() == prev_op) ? prev_dom : top; |
|
1467 // Control-target is just the If's immediate dominator or TOP. |
|
1468 Node *ctrl_target = (ifp->Opcode() == prev_op) ? idom : top; |
|
1469 |
|
1470 // For each child of an IfTrue/IfFalse projection, reroute. |
|
1471 // Loop ends when projection has no more uses. |
|
1472 for (DUIterator_Last jmin, j = ifp->last_outs(jmin); j >= jmin; --j) { |
|
1473 Node* s = ifp->last_out(j); // Get child of IfTrue/IfFalse |
|
1474 if( !s->depends_only_on_test() ) { |
|
1475 // Find the control input matching this def-use edge. |
|
1476 // For Regions it may not be in slot 0. |
|
1477 uint l; |
|
1478 for( l = 0; s->in(l) != ifp; l++ ) { } |
|
1479 igvn->replace_input_of(s, l, ctrl_target); |
|
1480 } else { // Else, for control producers, |
|
1481 igvn->replace_input_of(s, 0, data_target); // Move child to data-target |
|
1482 } |
|
1483 } // End for each child of a projection |
|
1484 |
|
1485 igvn->remove_dead_node(ifp); |
|
1486 } // End for each IfTrue/IfFalse child of If |
|
1487 |
|
1488 // Kill the IfNode |
|
1489 igvn->remove_dead_node(this); |
|
1490 |
|
1491 // Must return either the original node (now dead) or a new node |
|
1492 // (Do not return a top here, since that would break the uniqueness of top.) |
|
1493 return new ConINode(TypeInt::ZERO); |
|
1494 } |
|
1495 |
|
1496 Node* IfNode::search_identical(int dist) { |
1377 // Setup to scan up the CFG looking for a dominating test |
1497 // Setup to scan up the CFG looking for a dominating test |
1378 Node *dom = in(0); |
1498 Node* dom = in(0); |
1379 Node *prev_dom = this; |
1499 Node* prev_dom = this; |
|
1500 int op = Opcode(); |
|
1501 // Search up the dominator tree for an If with an identical test |
|
1502 while( dom->Opcode() != op || // Not same opcode? |
|
1503 dom->in(1) != in(1) || // Not same input 1? |
|
1504 (req() == 3 && dom->in(2) != in(2)) || // Not same input 2? |
|
1505 prev_dom->in(0) != dom ) { // One path of test does not dominate? |
|
1506 if( dist < 0 ) return NULL; |
|
1507 |
|
1508 dist--; |
|
1509 prev_dom = dom; |
|
1510 dom = up_one_dom( dom ); |
|
1511 if( !dom ) return NULL; |
|
1512 } |
|
1513 |
|
1514 // Check that we did not follow a loop back to ourselves |
|
1515 if( this == dom ) |
|
1516 return NULL; |
|
1517 |
|
1518 if( dist > 2 ) // Add to count of NULL checks elided |
|
1519 explicit_null_checks_elided++; |
|
1520 |
|
1521 return prev_dom; |
|
1522 } |
|
1523 |
|
1524 //------------------------------Identity--------------------------------------- |
|
1525 // If the test is constant & we match, then we are the input Control |
|
1526 Node *IfProjNode::Identity(PhaseTransform *phase) { |
|
1527 // Can only optimize if cannot go the other way |
|
1528 const TypeTuple *t = phase->type(in(0))->is_tuple(); |
|
1529 if (t == TypeTuple::IFNEITHER || |
|
1530 // kill dead branch first otherwise the IfNode's control will |
|
1531 // have 2 control uses (the IfNode that doesn't go away because |
|
1532 // it still has uses and this branch of the |
|
1533 // If). Node::has_special_unique_user() will cause this node to |
|
1534 // be reprocessed once the dead branch is killed. |
|
1535 (always_taken(t) && in(0)->outcnt() == 1)) { |
|
1536 // IfNode control |
|
1537 return in(0)->in(0); |
|
1538 } |
|
1539 // no progress |
|
1540 return this; |
|
1541 } |
|
1542 |
|
1543 #ifndef PRODUCT |
|
1544 //-------------------------------related--------------------------------------- |
|
1545 // An IfProjNode's related node set consists of its input (an IfNode) including |
|
1546 // the IfNode's condition, plus all of its outputs at level 1. In compact mode, |
|
1547 // the restrictions for IfNode apply (see IfNode::rel). |
|
1548 void IfProjNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const { |
|
1549 Node* ifNode = this->in(0); |
|
1550 in_rel->append(ifNode); |
|
1551 if (compact) { |
|
1552 ifNode->collect_nodes(in_rel, 3, false, true); |
|
1553 } else { |
|
1554 ifNode->collect_nodes_in_all_data(in_rel, false); |
|
1555 } |
|
1556 this->collect_nodes(out_rel, -1, false, false); |
|
1557 } |
|
1558 |
|
1559 //------------------------------dump_spec-------------------------------------- |
|
1560 void IfNode::dump_spec(outputStream *st) const { |
|
1561 st->print("P=%f, C=%f",_prob,_fcnt); |
|
1562 } |
|
1563 |
|
1564 //-------------------------------related--------------------------------------- |
|
1565 // For an IfNode, the set of related output nodes is just the output nodes till |
|
1566 // depth 2, i.e, the IfTrue/IfFalse projection nodes plus the nodes they refer. |
|
1567 // The related input nodes contain no control nodes, but all data nodes |
|
1568 // pertaining to the condition. In compact mode, the input nodes are collected |
|
1569 // up to a depth of 3. |
|
1570 void IfNode::related(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const { |
|
1571 if (compact) { |
|
1572 this->collect_nodes(in_rel, 3, false, true); |
|
1573 } else { |
|
1574 this->collect_nodes_in_all_data(in_rel, false); |
|
1575 } |
|
1576 this->collect_nodes(out_rel, -2, false, false); |
|
1577 } |
|
1578 #endif |
|
1579 |
|
1580 //------------------------------idealize_test---------------------------------- |
|
1581 // Try to canonicalize tests better. Peek at the Cmp/Bool/If sequence and |
|
1582 // come up with a canonical sequence. Bools getting 'eq', 'gt' and 'ge' forms |
|
1583 // converted to 'ne', 'le' and 'lt' forms. IfTrue/IfFalse get swapped as |
|
1584 // needed. |
|
1585 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) { |
|
1586 assert(iff->in(0) != NULL, "If must be live"); |
|
1587 |
|
1588 if (iff->outcnt() != 2) return NULL; // Malformed projections. |
|
1589 Node* old_if_f = iff->proj_out(false); |
|
1590 Node* old_if_t = iff->proj_out(true); |
|
1591 |
|
1592 // CountedLoopEnds want the back-control test to be TRUE, irregardless of |
|
1593 // whether they are testing a 'gt' or 'lt' condition. The 'gt' condition |
|
1594 // happens in count-down loops |
|
1595 if (iff->is_CountedLoopEnd()) return NULL; |
|
1596 if (!iff->in(1)->is_Bool()) return NULL; // Happens for partially optimized IF tests |
|
1597 BoolNode *b = iff->in(1)->as_Bool(); |
|
1598 BoolTest bt = b->_test; |
|
1599 // Test already in good order? |
|
1600 if( bt.is_canonical() ) |
|
1601 return NULL; |
|
1602 |
|
1603 // Flip test to be canonical. Requires flipping the IfFalse/IfTrue and |
|
1604 // cloning the IfNode. |
|
1605 Node* new_b = phase->transform( new BoolNode(b->in(1), bt.negate()) ); |
|
1606 if( !new_b->is_Bool() ) return NULL; |
|
1607 b = new_b->as_Bool(); |
|
1608 |
|
1609 PhaseIterGVN *igvn = phase->is_IterGVN(); |
|
1610 assert( igvn, "Test is not canonical in parser?" ); |
|
1611 |
|
1612 // The IF node never really changes, but it needs to be cloned |
|
1613 iff = iff->clone()->as_If(); |
|
1614 iff->set_req(1, b); |
|
1615 iff->_prob = 1.0-iff->_prob; |
|
1616 |
|
1617 Node *prior = igvn->hash_find_insert(iff); |
|
1618 if( prior ) { |
|
1619 igvn->remove_dead_node(iff); |
|
1620 iff = (IfNode*)prior; |
|
1621 } else { |
|
1622 // Cannot call transform on it just yet |
|
1623 igvn->set_type_bottom(iff); |
|
1624 } |
|
1625 igvn->_worklist.push(iff); |
|
1626 |
|
1627 // Now handle projections. Cloning not required. |
|
1628 Node* new_if_f = (Node*)(new IfFalseNode( iff )); |
|
1629 Node* new_if_t = (Node*)(new IfTrueNode ( iff )); |
|
1630 |
|
1631 igvn->register_new_node_with_optimizer(new_if_f); |
|
1632 igvn->register_new_node_with_optimizer(new_if_t); |
|
1633 // Flip test, so flip trailing control |
|
1634 igvn->replace_node(old_if_f, new_if_t); |
|
1635 igvn->replace_node(old_if_t, new_if_f); |
|
1636 |
|
1637 // Progress |
|
1638 return iff; |
|
1639 } |
|
1640 |
|
1641 Node* RangeCheckNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
|
1642 Node* res = Ideal_common(phase, can_reshape); |
|
1643 if (res != NodeSentinel) { |
|
1644 return res; |
|
1645 } |
|
1646 |
|
1647 PhaseIterGVN *igvn = phase->is_IterGVN(); |
|
1648 // Setup to scan up the CFG looking for a dominating test |
|
1649 Node* prev_dom = this; |
1380 |
1650 |
1381 // Check for range-check vs other kinds of tests |
1651 // Check for range-check vs other kinds of tests |
1382 Node *index1, *range1; |
1652 Node* index1; |
|
1653 Node* range1; |
1383 jint offset1; |
1654 jint offset1; |
1384 int flip1 = is_range_check(range1, index1, offset1); |
1655 int flip1 = is_range_check(range1, index1, offset1); |
1385 if( flip1 ) { |
1656 if (flip1) { |
|
1657 Node* dom = in(0); |
1386 // Try to remove extra range checks. All 'up_one_dom' gives up at merges |
1658 // Try to remove extra range checks. All 'up_one_dom' gives up at merges |
1387 // so all checks we inspect post-dominate the top-most check we find. |
1659 // so all checks we inspect post-dominate the top-most check we find. |
1388 // If we are going to fail the current check and we reach the top check |
1660 // If we are going to fail the current check and we reach the top check |
1389 // then we are guaranteed to fail, so just start interpreting there. |
1661 // then we are guaranteed to fail, so just start interpreting there. |
1390 // We 'expand' the top 3 range checks to include all post-dominating |
1662 // We 'expand' the top 3 range checks to include all post-dominating |
1515 adjust_check(rc0.ctl, range1, index1, flip1, off_hi, igvn); |
1788 adjust_check(rc0.ctl, range1, index1, flip1, off_hi, igvn); |
1516 // Test is now covered by prior checks, dominate it out |
1789 // Test is now covered by prior checks, dominate it out |
1517 prev_dom = rc0.ctl; |
1790 prev_dom = rc0.ctl; |
1518 } |
1791 } |
1519 } |
1792 } |
1520 |
1793 } else { |
1521 } else { // Scan for an equivalent test |
1794 prev_dom = search_identical(4); |
1522 |
1795 |
1523 Node *cmp; |
1796 if (prev_dom == NULL) { |
1524 int dist = 0; // Cutoff limit for search |
|
1525 int op = Opcode(); |
|
1526 if( op == Op_If && |
|
1527 (cmp=in(1)->in(1))->Opcode() == Op_CmpP ) { |
|
1528 if( cmp->in(2) != NULL && // make sure cmp is not already dead |
|
1529 cmp->in(2)->bottom_type() == TypePtr::NULL_PTR ) { |
|
1530 dist = 64; // Limit for null-pointer scans |
|
1531 } else { |
|
1532 dist = 4; // Do not bother for random pointer tests |
|
1533 } |
|
1534 } else { |
|
1535 dist = 4; // Limit for random junky scans |
|
1536 } |
|
1537 |
|
1538 // Normal equivalent-test check. |
|
1539 if( !dom ) return NULL; // Dead loop? |
|
1540 |
|
1541 Node* result = fold_compares(igvn); |
|
1542 if (result != NULL) { |
|
1543 return result; |
|
1544 } |
|
1545 |
|
1546 // Search up the dominator tree for an If with an identical test |
|
1547 while( dom->Opcode() != op || // Not same opcode? |
|
1548 dom->in(1) != in(1) || // Not same input 1? |
|
1549 (req() == 3 && dom->in(2) != in(2)) || // Not same input 2? |
|
1550 prev_dom->in(0) != dom ) { // One path of test does not dominate? |
|
1551 if( dist < 0 ) return NULL; |
|
1552 |
|
1553 dist--; |
|
1554 prev_dom = dom; |
|
1555 dom = up_one_dom( dom ); |
|
1556 if( !dom ) return NULL; |
|
1557 } |
|
1558 |
|
1559 // Check that we did not follow a loop back to ourselves |
|
1560 if( this == dom ) |
|
1561 return NULL; |
1797 return NULL; |
1562 |
1798 } |
1563 if( dist > 2 ) // Add to count of NULL checks elided |
1799 } |
1564 explicit_null_checks_elided++; |
|
1565 |
|
1566 } // End of Else scan for an equivalent test |
|
1567 |
|
1568 // Hit! Remove this IF |
|
1569 #ifndef PRODUCT |
|
1570 if( TraceIterativeGVN ) { |
|
1571 tty->print(" Removing IfNode: "); this->dump(); |
|
1572 } |
|
1573 if( VerifyOpto && !phase->allow_progress() ) { |
|
1574 // Found an equivalent dominating test, |
|
1575 // we can not guarantee reaching a fix-point for these during iterativeGVN |
|
1576 // since intervening nodes may not change. |
|
1577 return NULL; |
|
1578 } |
|
1579 #endif |
|
1580 |
1800 |
1581 // Replace dominated IfNode |
1801 // Replace dominated IfNode |
1582 dominated_by( prev_dom, igvn ); |
1802 return dominated_by(prev_dom, igvn); |
1583 |
1803 } |
1584 // Must return either the original node (now dead) or a new node |
|
1585 // (Do not return a top here, since that would break the uniqueness of top.) |
|
1586 return new ConINode(TypeInt::ZERO); |
|
1587 } |
|
1588 |
|
1589 //------------------------------dominated_by----------------------------------- |
|
1590 void IfNode::dominated_by( Node *prev_dom, PhaseIterGVN *igvn ) { |
|
1591 igvn->hash_delete(this); // Remove self to prevent spurious V-N |
|
1592 Node *idom = in(0); |
|
1593 // Need opcode to decide which way 'this' test goes |
|
1594 int prev_op = prev_dom->Opcode(); |
|
1595 Node *top = igvn->C->top(); // Shortcut to top |
|
1596 |
|
1597 // Loop predicates may have depending checks which should not |
|
1598 // be skipped. For example, range check predicate has two checks |
|
1599 // for lower and upper bounds. |
|
1600 ProjNode* unc_proj = proj_out(1 - prev_dom->as_Proj()->_con)->as_Proj(); |
|
1601 if (unc_proj->is_uncommon_trap_proj(Deoptimization::Reason_predicate) != NULL) |
|
1602 prev_dom = idom; |
|
1603 |
|
1604 // Now walk the current IfNode's projections. |
|
1605 // Loop ends when 'this' has no more uses. |
|
1606 for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) { |
|
1607 Node *ifp = last_out(i); // Get IfTrue/IfFalse |
|
1608 igvn->add_users_to_worklist(ifp); |
|
1609 // Check which projection it is and set target. |
|
1610 // Data-target is either the dominating projection of the same type |
|
1611 // or TOP if the dominating projection is of opposite type. |
|
1612 // Data-target will be used as the new control edge for the non-CFG |
|
1613 // nodes like Casts and Loads. |
|
1614 Node *data_target = (ifp->Opcode() == prev_op) ? prev_dom : top; |
|
1615 // Control-target is just the If's immediate dominator or TOP. |
|
1616 Node *ctrl_target = (ifp->Opcode() == prev_op) ? idom : top; |
|
1617 |
|
1618 // For each child of an IfTrue/IfFalse projection, reroute. |
|
1619 // Loop ends when projection has no more uses. |
|
1620 for (DUIterator_Last jmin, j = ifp->last_outs(jmin); j >= jmin; --j) { |
|
1621 Node* s = ifp->last_out(j); // Get child of IfTrue/IfFalse |
|
1622 if( !s->depends_only_on_test() ) { |
|
1623 // Find the control input matching this def-use edge. |
|
1624 // For Regions it may not be in slot 0. |
|
1625 uint l; |
|
1626 for( l = 0; s->in(l) != ifp; l++ ) { } |
|
1627 igvn->replace_input_of(s, l, ctrl_target); |
|
1628 } else { // Else, for control producers, |
|
1629 igvn->replace_input_of(s, 0, data_target); // Move child to data-target |
|
1630 } |
|
1631 } // End for each child of a projection |
|
1632 |
|
1633 igvn->remove_dead_node(ifp); |
|
1634 } // End for each IfTrue/IfFalse child of If |
|
1635 |
|
1636 // Kill the IfNode |
|
1637 igvn->remove_dead_node(this); |
|
1638 } |
|
1639 |
|
1640 //------------------------------Identity--------------------------------------- |
|
1641 // If the test is constant & we match, then we are the input Control |
|
1642 Node *IfProjNode::Identity(PhaseTransform *phase) { |
|
1643 // Can only optimize if cannot go the other way |
|
1644 const TypeTuple *t = phase->type(in(0))->is_tuple(); |
|
1645 if (t == TypeTuple::IFNEITHER || |
|
1646 // kill dead branch first otherwise the IfNode's control will |
|
1647 // have 2 control uses (the IfNode that doesn't go away because |
|
1648 // it still has uses and this branch of the |
|
1649 // If). Node::has_special_unique_user() will cause this node to |
|
1650 // be reprocessed once the dead branch is killed. |
|
1651 (always_taken(t) && in(0)->outcnt() == 1)) { |
|
1652 // IfNode control |
|
1653 return in(0)->in(0); |
|
1654 } |
|
1655 // no progress |
|
1656 return this; |
|
1657 } |
|
1658 |
|
1659 #ifndef PRODUCT |
|
1660 //-------------------------------related--------------------------------------- |
|
1661 // An IfProjNode's related node set consists of its input (an IfNode) including |
|
1662 // the IfNode's condition, plus all of its outputs at level 1. In compact mode, |
|
1663 // the restrictions for IfNode apply (see IfNode::rel). |
|
1664 void IfProjNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const { |
|
1665 Node* ifNode = this->in(0); |
|
1666 in_rel->append(ifNode); |
|
1667 if (compact) { |
|
1668 ifNode->collect_nodes(in_rel, 3, false, true); |
|
1669 } else { |
|
1670 ifNode->collect_nodes_in_all_data(in_rel, false); |
|
1671 } |
|
1672 this->collect_nodes(out_rel, -1, false, false); |
|
1673 } |
|
1674 |
|
1675 //------------------------------dump_spec-------------------------------------- |
|
1676 void IfNode::dump_spec(outputStream *st) const { |
|
1677 st->print("P=%f, C=%f",_prob,_fcnt); |
|
1678 } |
|
1679 |
|
1680 //-------------------------------related--------------------------------------- |
|
1681 // For an IfNode, the set of related output nodes is just the output nodes till |
|
1682 // depth 2, i.e, the IfTrue/IfFalse projection nodes plus the nodes they refer. |
|
1683 // The related input nodes contain no control nodes, but all data nodes |
|
1684 // pertaining to the condition. In compact mode, the input nodes are collected |
|
1685 // up to a depth of 3. |
|
1686 void IfNode::related(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const { |
|
1687 if (compact) { |
|
1688 this->collect_nodes(in_rel, 3, false, true); |
|
1689 } else { |
|
1690 this->collect_nodes_in_all_data(in_rel, false); |
|
1691 } |
|
1692 this->collect_nodes(out_rel, -2, false, false); |
|
1693 } |
|
1694 #endif |
|
1695 |
|
1696 //------------------------------idealize_test---------------------------------- |
|
1697 // Try to canonicalize tests better. Peek at the Cmp/Bool/If sequence and |
|
1698 // come up with a canonical sequence. Bools getting 'eq', 'gt' and 'ge' forms |
|
1699 // converted to 'ne', 'le' and 'lt' forms. IfTrue/IfFalse get swapped as |
|
1700 // needed. |
|
1701 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) { |
|
1702 assert(iff->in(0) != NULL, "If must be live"); |
|
1703 |
|
1704 if (iff->outcnt() != 2) return NULL; // Malformed projections. |
|
1705 Node* old_if_f = iff->proj_out(false); |
|
1706 Node* old_if_t = iff->proj_out(true); |
|
1707 |
|
1708 // CountedLoopEnds want the back-control test to be TRUE, irregardless of |
|
1709 // whether they are testing a 'gt' or 'lt' condition. The 'gt' condition |
|
1710 // happens in count-down loops |
|
1711 if (iff->is_CountedLoopEnd()) return NULL; |
|
1712 if (!iff->in(1)->is_Bool()) return NULL; // Happens for partially optimized IF tests |
|
1713 BoolNode *b = iff->in(1)->as_Bool(); |
|
1714 BoolTest bt = b->_test; |
|
1715 // Test already in good order? |
|
1716 if( bt.is_canonical() ) |
|
1717 return NULL; |
|
1718 |
|
1719 // Flip test to be canonical. Requires flipping the IfFalse/IfTrue and |
|
1720 // cloning the IfNode. |
|
1721 Node* new_b = phase->transform( new BoolNode(b->in(1), bt.negate()) ); |
|
1722 if( !new_b->is_Bool() ) return NULL; |
|
1723 b = new_b->as_Bool(); |
|
1724 |
|
1725 PhaseIterGVN *igvn = phase->is_IterGVN(); |
|
1726 assert( igvn, "Test is not canonical in parser?" ); |
|
1727 |
|
1728 // The IF node never really changes, but it needs to be cloned |
|
1729 iff = new IfNode( iff->in(0), b, 1.0-iff->_prob, iff->_fcnt); |
|
1730 |
|
1731 Node *prior = igvn->hash_find_insert(iff); |
|
1732 if( prior ) { |
|
1733 igvn->remove_dead_node(iff); |
|
1734 iff = (IfNode*)prior; |
|
1735 } else { |
|
1736 // Cannot call transform on it just yet |
|
1737 igvn->set_type_bottom(iff); |
|
1738 } |
|
1739 igvn->_worklist.push(iff); |
|
1740 |
|
1741 // Now handle projections. Cloning not required. |
|
1742 Node* new_if_f = (Node*)(new IfFalseNode( iff )); |
|
1743 Node* new_if_t = (Node*)(new IfTrueNode ( iff )); |
|
1744 |
|
1745 igvn->register_new_node_with_optimizer(new_if_f); |
|
1746 igvn->register_new_node_with_optimizer(new_if_t); |
|
1747 // Flip test, so flip trailing control |
|
1748 igvn->replace_node(old_if_f, new_if_t); |
|
1749 igvn->replace_node(old_if_t, new_if_f); |
|
1750 |
|
1751 // Progress |
|
1752 return iff; |
|
1753 } |
|