Skip to content

Commit 4836425

Browse files
[MCP] Skip invalidating constant regs during forward propagation
Before this patch, redundant COPY couldn't be removed for the following case: %reg1 = COPY %const-reg ... // No use of %reg1 but there is a def/use of %const-reg %reg2 = COPY killed %reg1 where this can be optimized to: ... // No use of %reg1 but there is a def/use of %const-reg %reg2 = COPY %const-reg This patch allows for such optimization by not invalidating constant registers. This is safe even where constant registers are defined, as architectures like AArch64 and RISCV replace a dead definition of a GPR with a zero constant register for certain instructions. Upstream PR: llvm/llvm-project#111129 Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent 6682727 commit 4836425

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,12 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
843843
assert(!Reg.isVirtual() &&
844844
"MachineCopyPropagation should be run after register allocation!");
845845

846+
// EraVM local begin
847+
// Skip invalidating constant registers.
848+
if (MRI->isReserved(Reg) && MRI->isConstantPhysReg(Reg))
849+
continue;
850+
// EraVM local end
851+
846852
if (MO.isDef() && !MO.isEarlyClobber()) {
847853
Defs.push_back(Reg.asMCReg());
848854
continue;

llvm/test/CodeGen/EraVM/machine-cp-constant-reg.mir

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ body: |
1818
; CHECK-LABEL: name: test
1919
; CHECK: liveins: $r2, $r3
2020
; CHECK-NEXT: {{ $}}
21-
; CHECK-NEXT: renamable $r4 = COPY $r0
2221
; CHECK-NEXT: dead $r0 = SUBrrr_v renamable $r2, renamable $r3, i256 0, implicit-def $flags
23-
; CHECK-NEXT: renamable $r1 = COPY killed renamable $r4
22+
; CHECK-NEXT: renamable $r1 = COPY $r0
2423
; CHECK-NEXT: RET 0, implicit $r1
2524
renamable $r4 = COPY $r0
2625
dead $r0 = SUBrrr_v renamable $r2, renamable $r3, i256 0, implicit-def $flags

0 commit comments

Comments
 (0)