diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -2369,11 +2369,25 @@ }; for (MachineInstr &MI : MBB) { if (MI.isCopy()) { - MachineOperand &Dest = MI.getOperand(0); - MachineOperand &Src = MI.getOperand(1); - if (Dest.isReg() && Src.isReg() && Dest.getReg().isVirtual() && - Src.getReg().isVirtual()) - ++Stats.Copies; + const MachineOperand &Dest = MI.getOperand(0); + const MachineOperand &Src = MI.getOperand(1); + Register SrcReg = Src.getReg(); + Register DestReg = Dest.getReg(); + // Only count `COPY`s with a virtual register as source or destination. + if (SrcReg.isVirtual() || DestReg.isVirtual()) { + if (SrcReg.isVirtual()) { + SrcReg = VRM->getPhys(SrcReg); + if (Src.getSubReg()) + SrcReg = TRI->getSubReg(SrcReg, Src.getSubReg()); + } + if (DestReg.isVirtual()) { + DestReg = VRM->getPhys(DestReg); + if (Dest.getSubReg()) + DestReg = TRI->getSubReg(DestReg, Dest.getSubReg()); + } + if (SrcReg != DestReg) + ++Stats.Copies; + } continue; } diff --git a/llvm/test/CodeGen/X86/statepoint-ra.ll b/llvm/test/CodeGen/X86/statepoint-ra.ll --- a/llvm/test/CodeGen/X86/statepoint-ra.ll +++ b/llvm/test/CodeGen/X86/statepoint-ra.ll @@ -20,10 +20,6 @@ ;YAML: - String: ' total reloads cost ' ;YAML: - NumZeroCostFoldedReloads: '20' ;YAML: - String: ' zero cost folded reloads ' -;YAML: - NumVRCopies: '2' -;YAML: - String: ' virtual registers copies ' -;YAML: - TotalCopiesCost: '8.882868e-16' -;YAML: - String: ' total copies cost ' ;YAML: - String: generated in function define void @barney(ptr addrspace(1) %arg, double %arg1, double %arg2, double %arg3, double %arg4, double %arg5, double %arg6, double %arg7, double %arg8, double %arg9, double %arg10, double %arg11, double %arg12) gc "statepoint-example" personality ptr @widget {