@@ -2458,7 +2458,28 @@ void RAGreedy::collectHintInfo(Register Reg, HintsInfo &Out) {
24582458
24592459 // Push the collected information.
24602460 if (OtherPhysReg) {
2461- Out.push_back (HintInfo (MBFI->getBlockFreq (Instr.getParent ()), OtherReg,
2461+ BlockFrequency Freq = MBFI->getBlockFreq (Instr.getParent ());
2462+
2463+ if (OtherSubReg) {
2464+ const TargetRegisterClass *OtherRC = MRI->getRegClass (OtherReg);
2465+ unsigned FullRegCopyCost = OtherRC->getCopyCost ();
2466+
2467+ const TargetRegisterClass *OtherSubRC = TRI->getSubRegisterClass (OtherRC, OtherSubReg);
2468+ unsigned SubRegCopyCost = OtherSubRC->getCopyCost ();
2469+
2470+ BranchProbability Scaling (SubRegCopyCost, FullRegCopyCost);
2471+ Freq *= Scaling;
2472+ } else if (SubReg) {
2473+ unsigned FullRegCopyCost = RC->getCopyCost ();
2474+ const TargetRegisterClass *SubRC = TRI->getSubRegisterClass (RC, SubReg);
2475+ unsigned SubRegCopyCost = SubRC->getCopyCost ();
2476+
2477+ BranchProbability Scaling (SubRegCopyCost, FullRegCopyCost);
2478+ Freq *= Scaling;
2479+
2480+ }
2481+
2482+ Out.push_back (HintInfo (Freq, OtherReg,
24622483 OtherPhysReg));
24632484 }
24642485 }
@@ -2471,6 +2492,13 @@ BlockFrequency RAGreedy::getBrokenHintFreq(const HintsInfo &List,
24712492 MCRegister PhysReg) {
24722493 BlockFrequency Cost = BlockFrequency (0 );
24732494 for (const HintInfo &Info : List) {
2495+
2496+ if (!Info.PhysReg ) {
2497+ // Apply subreg hint
2498+ continue ;
2499+ }
2500+
2501+
24742502 if (Info.PhysReg != PhysReg)
24752503 Cost += Info.Freq ;
24762504 }
@@ -2536,6 +2564,8 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
25362564 // non-identity copies.
25372565 if (CurrPhys != PhysReg) {
25382566 LLVM_DEBUG (dbgs () << " Checking profitability:\n " );
2567+
2568+ // TODO: Scale by copy cost
25392569 BlockFrequency OldCopiesCost = getBrokenHintFreq (Info, CurrPhys);
25402570 BlockFrequency NewCopiesCost = getBrokenHintFreq (Info, PhysReg);
25412571 LLVM_DEBUG (dbgs () << " Old Cost: " << printBlockFreq (*MBFI, OldCopiesCost)
0 commit comments