@@ -1471,6 +1471,65 @@ static OptoReg::Name find_first_set(LRG& lrg, RegMask& mask) {
14711471 return assigned;
14721472}
14731473
1474+ OptoReg::Name PhaseChaitin::select_bias_lrg_color (LRG& lrg) {
1475+ uint bias_lrg1_idx = _lrg_map.find (lrg._copy_bias );
1476+ uint bias_lrg2_idx = _lrg_map.find (lrg._copy_bias2 );
1477+
1478+ // If bias_lrg1 has a color
1479+ if (bias_lrg1_idx != 0 && !_ifg->_yanked ->test (bias_lrg1_idx)) {
1480+ OptoReg::Name reg = lrgs (bias_lrg1_idx).reg ();
1481+ // and it is legal for lrg
1482+ if (is_legal_reg (lrg, reg)) {
1483+ return reg;
1484+ }
1485+ }
1486+
1487+ // If bias_lrg2 has a color
1488+ if (bias_lrg2_idx != 0 && !_ifg->_yanked ->test (bias_lrg2_idx)) {
1489+ OptoReg::Name reg = lrgs (bias_lrg2_idx).reg ();
1490+ // and it is legal for lrg
1491+ if (is_legal_reg (lrg, reg)) {
1492+ return reg;
1493+ }
1494+ }
1495+
1496+ uint bias_lrg_idx = 0 ;
1497+ if (bias_lrg1_idx != 0 && bias_lrg2_idx != 0 ) {
1498+ // Since none of the bias live ranges are part of the IFG yet, constrain the
1499+ // definition mask with the bias live range with the least degrees of
1500+ // freedom. This will increase the chances of register sharing once the bias
1501+ // live range becomes part of the IFG.
1502+ lrgs (bias_lrg1_idx).compute_set_mask_size ();
1503+ lrgs (bias_lrg2_idx).compute_set_mask_size ();
1504+ bias_lrg_idx = lrgs (bias_lrg1_idx).degrees_of_freedom () >
1505+ lrgs (bias_lrg2_idx).degrees_of_freedom ()
1506+ ? bias_lrg2_idx
1507+ : bias_lrg1_idx;
1508+ } else if (bias_lrg1_idx != 0 ) {
1509+ bias_lrg_idx = bias_lrg1_idx;
1510+ } else if (bias_lrg2_idx != 0 ) {
1511+ bias_lrg_idx = bias_lrg2_idx;
1512+ }
1513+
1514+ // Register masks with offset excludes all mask bits before the offset.
1515+ // Such masks are mainly used for allocation from stack slots. Constrain the
1516+ // register mask of definition live range using bias mask only if
1517+ // both masks have zero offset.
1518+ if (bias_lrg_idx != 0 && !lrg.mask ().is_offset () &&
1519+ !lrgs (bias_lrg_idx).mask ().is_offset ()) {
1520+ // Choose a color which is legal for bias_lrg
1521+ ResourceMark rm (C->regmask_arena ());
1522+ RegMask tempmask (lrg.mask (), C->regmask_arena ());
1523+ tempmask.and_with (lrgs (bias_lrg_idx).mask ());
1524+ tempmask.clear_to_sets (lrg.num_regs ());
1525+ OptoReg::Name reg = find_first_set (lrg, tempmask);
1526+ if (OptoReg::is_valid (reg)) {
1527+ return reg;
1528+ }
1529+ }
1530+ return OptoReg::Bad;
1531+ }
1532+
14741533// Choose a color using the biasing heuristic
14751534OptoReg::Name PhaseChaitin::bias_color (LRG& lrg) {
14761535
@@ -1492,25 +1551,10 @@ OptoReg::Name PhaseChaitin::bias_color(LRG& lrg) {
14921551 }
14931552 }
14941553
1495- uint copy_lrg = _lrg_map.find (lrg._copy_bias );
1496- if (copy_lrg != 0 ) {
1497- // If he has a color,
1498- if (!_ifg->_yanked ->test (copy_lrg)) {
1499- OptoReg::Name reg = lrgs (copy_lrg).reg ();
1500- // And it is legal for you,
1501- if (is_legal_reg (lrg, reg)) {
1502- return reg;
1503- }
1504- } else if (!lrg.mask ().is_offset ()) {
1505- // Choose a color which is legal for him
1506- ResourceMark rm (C->regmask_arena ());
1507- RegMask tempmask (lrg.mask (), C->regmask_arena ());
1508- tempmask.and_with (lrgs (copy_lrg).mask ());
1509- tempmask.clear_to_sets (lrg.num_regs ());
1510- OptoReg::Name reg = find_first_set (lrg, tempmask);
1511- if (OptoReg::is_valid (reg))
1512- return reg;
1513- }
1554+ // Try biasing the color with non-interfering bias live range[s].
1555+ OptoReg::Name reg = select_bias_lrg_color (lrg);
1556+ if (OptoReg::is_valid (reg)) {
1557+ return reg;
15141558 }
15151559
15161560 // If no bias info exists, just go with the register selection ordering
@@ -1524,7 +1568,7 @@ OptoReg::Name PhaseChaitin::bias_color(LRG& lrg) {
15241568 // CNC - Fun hack. Alternate 1st and 2nd selection. Enables post-allocate
15251569 // copy removal to remove many more copies, by preventing a just-assigned
15261570 // register from being repeatedly assigned.
1527- OptoReg::Name reg = lrg.mask ().find_first_elem ();
1571+ reg = lrg.mask ().find_first_elem ();
15281572 if ( (++_alternate & 1 ) && OptoReg::is_valid (reg) ) {
15291573 // This 'Remove; find; Insert' idiom is an expensive way to find the
15301574 // SECOND element in the mask.
@@ -1640,6 +1684,27 @@ uint PhaseChaitin::Select( ) {
16401684 }
16411685 }
16421686 }
1687+
1688+ Node* def = lrg->_def ;
1689+ if (lrg->is_singledef () && !lrg->_is_bound && def->is_Mach ()) {
1690+ MachNode* mdef = def->as_Mach ();
1691+ if (Matcher::is_register_biasing_candidate (mdef, 1 )) {
1692+ Node* in1 = mdef->in (mdef->operand_index (1 ));
1693+ if (in1 != nullptr && lrg->_copy_bias == 0 ) {
1694+ lrg->_copy_bias = _lrg_map.find (in1);
1695+ }
1696+ }
1697+
1698+ // For commutative operations, def allocation can also be
1699+ // biased towards LRG of second input's def.
1700+ if (Matcher::is_register_biasing_candidate (mdef, 2 )) {
1701+ Node* in2 = mdef->in (mdef->operand_index (2 ));
1702+ if (in2 != nullptr && lrg->_copy_bias2 == 0 ) {
1703+ lrg->_copy_bias2 = _lrg_map.find (in2);
1704+ }
1705+ }
1706+ }
1707+
16431708 // assert(is_infinite_stack == lrg->mask().is_infinite_stack(), "nbrs must not change InfiniteStackedness");
16441709 // Aligned pairs need aligned masks
16451710 assert (!lrg->_is_vector || !lrg->_fat_proj , " sanity" );
0 commit comments