RAGreedyStats: Ignore identity COPYs; count COPYs from/to physregs

Improve copy statistics:

- Count copies from or to physical registers: They are used to model function parameters and calling conventions and the register allocator optimizes for them.
- Check physical registers assigned to virtual registers and stop counting "identity" `COPY`s where source and destination is the same physical registers; they will be removed in the `virtregmap` pass anyway.

Differential Revision: https://reviews.llvm.org/D131932
This commit is contained in:
Matthias Braun 2022-08-15 14:45:22 -07:00
parent e170d955fe
commit 19ce5e515f
3 changed files with 30 additions and 12 deletions

View File

@ -2369,11 +2369,25 @@ RAGreedy::RAGreedyStats RAGreedy::computeStats(MachineBasicBlock &MBB) {
};
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;
}

View File

@ -21,16 +21,16 @@
; (loop2:)
; REMARK: remark: /tmp/kk.c:2:20: 1 spills 1.000000e+04 total spills cost 1 reloads 1.000000e+04 total reloads cost generated in loop{{$}}
; (loop:)
; REMARK: remark: /tmp/kk.c:1:20: 2 spills 1.010000e+04 total spills cost 2 reloads 1.010000e+04 total reloads cost generated in loop{{$}}
; REMARK: remark: /tmp/kk.c:1:20: 2 spills 1.010000e+04 total spills cost 2 reloads 1.010000e+04 total reloads cost 1 virtual registers copies 1.000000e+02 total copies cost generated in loop{{$}}
; (func:)
; REMARK: remark: /tmp/kk.c:1:1: 3 spills 1.020000e+04 total spills cost 3 reloads 1.020000e+04 total reloads cost generated in function
; REMARK: remark: /tmp/kk.c:1:1: 3 spills 1.020000e+04 total spills cost 3 reloads 1.020000e+04 total reloads cost 3 virtual registers copies 1.020000e+02 total copies cost generated in function{{$}}
; (loop3:)
; HOTNESS: remark: /tmp/kk.c:3:20: 1 spills 1.000000e+02 total spills cost 1 reloads 1.000000e+02 total reloads cost generated in loop (hotness: 300)
; (loop2:)
; HOTNESS: remark: /tmp/kk.c:2:20: 1 spills 1.000000e+04 total spills cost 1 reloads 1.000000e+04 total reloads cost generated in loop (hotness: 30000)
; (loop:)
; HOTNESS: remark: /tmp/kk.c:1:20: 2 spills 1.010000e+04 total spills cost 2 reloads 1.010000e+04 total reloads cost generated in loop (hotness: 300)
; HOTNESS: remark: /tmp/kk.c:1:20: 2 spills 1.010000e+04 total spills cost 2 reloads 1.010000e+04 total reloads cost 1 virtual registers copies 1.000000e+02 total copies cost generated in loop (hotness: 300)
; NO_REMARK-NOT: remark
@ -86,6 +86,10 @@
; YAML: - String: ' reloads '
; YAML: - TotalReloadsCost: '1.010000e+04'
; YAML: - String: ' total reloads cost '
; YAML: - NumVRCopies: '1'
; YAML: - String: ' virtual registers copies '
; YAML: - TotalCopiesCost: '1.000000e+02'
; YAML: - String: ' total copies cost '
; YAML: - String: generated in loop
; YAML: ...
; YAML: --- !Missed
@ -103,6 +107,10 @@
; YAML: - String: ' reloads '
; YAML: - TotalReloadsCost: '1.020000e+04'
; YAML: - String: ' total reloads cost '
; YAML: - NumVRCopies: '3'
; YAML: - String: ' virtual registers copies '
; YAML: - TotalCopiesCost: '1.020000e+02'
; YAML: - String: ' total copies cost '
; YAML: - String: generated in function
; YAML: ...

View File

@ -20,10 +20,6 @@ target triple = "x86_64-unknown-linux-gnu"
;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 {