From 983c9e76c08e41cb97caf101fdc45f7463578497 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 9 Oct 2019 22:51:42 +0000 Subject: [PATCH] AMDGPU: Don't fold copies to physregs In a future patch, this will help cleanup m0 handling. The register coalescer handles copies from a register that materializes an immediate, but doesn't handle move immediates itself. The virtual register uses will often be allocated to the same register, so there end up being no real copy. llvm-svn: 374257 --- lib/Target/AMDGPU/SIFoldOperands.cpp | 14 +++++++++----- .../stack-pointer-offset-relative-frameindex.ll | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Target/AMDGPU/SIFoldOperands.cpp b/lib/Target/AMDGPU/SIFoldOperands.cpp index 1f8b744155d..698bcbdb983 100644 --- a/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -581,13 +581,17 @@ void SIFoldOperands::foldOperand( if (FoldingImmLike && UseMI->isCopy()) { Register DestReg = UseMI->getOperand(0).getReg(); - const TargetRegisterClass *DestRC = Register::isVirtualRegister(DestReg) - ? MRI->getRegClass(DestReg) - : TRI->getPhysRegClass(DestReg); + + // Don't fold into a copy to a physical register. Doing so would interfere + // with the register coalescer's logic which would avoid redundant + // initalizations. + if (DestReg.isPhysical()) + return; + + const TargetRegisterClass *DestRC = MRI->getRegClass(DestReg); Register SrcReg = UseMI->getOperand(1).getReg(); - if (Register::isVirtualRegister(DestReg) && - Register::isVirtualRegister(SrcReg)) { + if (SrcReg.isVirtual()) { // XXX - This can be an assert? const TargetRegisterClass * SrcRC = MRI->getRegClass(SrcReg); if (TRI->isSGPRClass(SrcRC) && TRI->hasVectorRegisters(DestRC)) { MachineRegisterInfo::use_iterator NextUse; diff --git a/test/CodeGen/AMDGPU/stack-pointer-offset-relative-frameindex.ll b/test/CodeGen/AMDGPU/stack-pointer-offset-relative-frameindex.ll index 7a2085fa361..00ae166a6ce 100644 --- a/test/CodeGen/AMDGPU/stack-pointer-offset-relative-frameindex.ll +++ b/test/CodeGen/AMDGPU/stack-pointer-offset-relative-frameindex.ll @@ -14,8 +14,8 @@ define amdgpu_kernel void @kernel_background_evaluate(float addrspace(5)* %kg, < ; GCN-NEXT: s_mov_b64 s[0:1], s[36:37] ; GCN-NEXT: v_mov_b32_e32 v1, 0x2000 ; GCN-NEXT: v_mov_b32_e32 v2, 0x4000 -; GCN-NEXT: s_mov_b64 s[2:3], s[38:39] ; GCN-NEXT: v_mov_b32_e32 v3, 0 +; GCN-NEXT: s_mov_b64 s[2:3], s[38:39] ; GCN-NEXT: v_mov_b32_e32 v4, 0x400000 ; GCN-NEXT: s_add_u32 s32, s33, 0xc0000 ; GCN-NEXT: v_add_nc_u32_e64 v32, 4, 0x4000