[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 08:34:28 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)
+ continue;
+
+ unsigned SubReg = Opnd.getSubReg();
+ if (!IsDef) {
----------------
preames wrote:
Style: A && B instead of two if-clauses.
https://github.com/llvm/llvm-project/pull/160294
More information about the llvm-commits
mailing list