[llvm] Greedy: Make trySplitAroundHintReg try to match hints with subreg copies (PR #160294)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 23 16:47:37 PDT 2025
================
@@ -1383,21 +1383,35 @@ bool RAGreedy::trySplitAroundHintReg(MCPhysReg Hint,
// Compute the cost of assigning a non Hint physical register to VirtReg.
// We define it as the total frequency of broken COPY instructions to/from
// Hint register, and after split, they can be deleted.
- for (const MachineInstr &Instr : MRI->reg_nodbg_instructions(Reg)) {
- if (!TII->isFullCopyInstr(Instr))
+
+ // FIXME: This is miscounting the costs with subregisters. In particular, this
+ // should support recognizing SplitKit formed copy bundles instead of direct
+ // copy instructions.
+ for (const MachineOperand &Opnd : MRI->reg_nodbg_operands(Reg)) {
+ const MachineInstr &Instr = *Opnd.getParent();
+ if (!Instr.isCopy() || Opnd.isImplicit())
continue;
- Register OtherReg = Instr.getOperand(1).getReg();
- if (OtherReg == Reg) {
- OtherReg = Instr.getOperand(0).getReg();
- if (OtherReg == Reg)
- continue;
+
+ // Look for the other end of the copy.
+ const bool IsDef = Opnd.isDef();
+ const MachineOperand &OtherOpnd = Instr.getOperand(IsDef);
+ Register OtherReg = OtherOpnd.getReg();
+ assert(Reg == Opnd.getReg());
+ if (OtherReg == Reg)
----------------
preames wrote:
This is exactly the case I was wondering about. If I'm reading it correctly, the check I commented on would ignore this copy, even though it likely needs to be materialized to a real instruction. I think we need to check that the subreg on the two operands are the same too don't we?
https://github.com/llvm/llvm-project/pull/160294
More information about the llvm-commits
mailing list