Skip to content

Commit fe9e65f

Browse files
committed
[RegAlloc] Count copy bundles instead of counting copy instructions
1 parent e6358ab commit fe9e65f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,9 +1384,6 @@ bool RAGreedy::trySplitAroundHintReg(MCPhysReg Hint,
13841384
// We define it as the total frequency of broken COPY instructions to/from
13851385
// Hint register, and after split, they can be deleted.
13861386

1387-
// FIXME: This is miscounting the costs with subregisters. In particular, this
1388-
// should support recognizing SplitKit formed copy bundles instead of direct
1389-
// copy instructions, which will appear in the same block.
13901387
for (const MachineOperand &Opnd : MRI->reg_nodbg_operands(Reg)) {
13911388
const MachineInstr &Instr = *Opnd.getParent();
13921389
if (!Instr.isCopy() || Opnd.isImplicit())
@@ -1429,8 +1426,19 @@ bool RAGreedy::trySplitAroundHintReg(MCPhysReg Hint,
14291426
OtherReg.isPhysical() ? OtherReg.asMCReg() : VRM->getPhys(OtherReg);
14301427
MCRegister ThisHint =
14311428
SubReg ? TRI->getSubReg(Hint, SubReg) : MCRegister(Hint);
1432-
if (OtherPhysReg == ThisHint)
1433-
Cost += MBFI->getBlockFreq(Instr.getParent());
1429+
if (OtherPhysReg == ThisHint) {
1430+
const MachineBasicBlock *MBB = Instr.getParent();
1431+
1432+
// Skip counting if this COPY instruction is part of a bundle but not the
1433+
// first instruction in the bundle. This avoids overcounting SplitKit
1434+
// formed copy bundles.
1435+
if (Instr.isBundledWithPred()) {
1436+
// This is part of a bundle but not the first instruction, so skip it
1437+
continue;
1438+
}
1439+
1440+
Cost += MBFI->getBlockFreq(MBB);
1441+
}
14341442
}
14351443

14361444
// Decrease the cost so it will be split in colder blocks.

0 commit comments

Comments
 (0)