summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
diff options
context:
space:
mode:
authorAlexander Timofeev <alexander.timofeev@amd.com>2022-12-12 21:18:19 +0100
committerAlexander Timofeev <alexander.timofeev@amd.com>2022-12-16 00:38:10 +0100
commit2877b876666079b3af9714692790fd5e1b5f038c (patch)
treee20dce0af49cf4ef5f496186dc83d5f6014c0bc9 /llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
parent4ec480dea2b8889de7b7fa443c60ab4667568f85 (diff)
[AMDGPU] Lower VGPR to physical SGPR COPY to S_MOV_B32 if VGPR contains the compile time constant
Sometimes we have a constant value loaded to VGPR. In case we further need to rematrerialize it in the physical scalar register we may avoid VGPR to SGPR copy replacing it with S_MOV_B32. Reviewed By: JonChesterfield, arsenm Differential Revision: https://reviews.llvm.org/D139874
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp')
-rw-r--r--llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
index f38b5d6fa3cf..f0dfa5f8827d 100644
--- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -148,7 +148,7 @@ public:
// 1. Physical register
// 2. AGPR
// 3. Defined by the instruction the merely moves the immediate
- bool lowerSpecialCase(MachineInstr &MI);
+ bool lowerSpecialCase(MachineInstr &MI, MachineBasicBlock::iterator &I);
void processPHINode(MachineInstr &MI);
@@ -638,7 +638,7 @@ bool SIFixSGPRCopies::runOnMachineFunction(MachineFunction &MF) {
}
if (!isVGPRToSGPRCopy(SrcRC, DstRC, *TRI))
continue;
- if (lowerSpecialCase(MI))
+ if (lowerSpecialCase(MI, I))
continue;
analyzeVGPRToSGPRCopy(&MI);
@@ -829,7 +829,8 @@ void SIFixSGPRCopies::processPHINode(MachineInstr &MI) {
}
}
-bool SIFixSGPRCopies::lowerSpecialCase(MachineInstr &MI) {
+bool SIFixSGPRCopies::lowerSpecialCase(MachineInstr &MI,
+ MachineBasicBlock::iterator &I) {
Register DstReg = MI.getOperand(0).getReg();
Register SrcReg = MI.getOperand(1).getReg();
if (!DstReg.isVirtual()) {
@@ -845,6 +846,25 @@ bool SIFixSGPRCopies::lowerSpecialCase(MachineInstr &MI) {
TII->get(AMDGPU::V_READFIRSTLANE_B32), TmpReg)
.add(MI.getOperand(1));
MI.getOperand(1).setReg(TmpReg);
+ } else {
+ MachineInstr *DefMI = MRI->getVRegDef(SrcReg);
+ if (DefMI && DefMI->isMoveImmediate()) {
+ MachineOperand SrcConst = DefMI->getOperand(AMDGPU::getNamedOperandIdx(
+ DefMI->getOpcode(), AMDGPU::OpName::src0));
+ if (!SrcConst.isReg()) {
+ const TargetRegisterClass *SrcRC = MRI->getRegClass(SrcReg);
+ unsigned MoveSize = TRI->getRegSizeInBits(*SrcRC);
+ unsigned MoveOp =
+ MoveSize == 64 ? AMDGPU::S_MOV_B64 : AMDGPU::S_MOV_B32;
+ BuildMI(*MI.getParent(), MI, MI.getDebugLoc(), TII->get(MoveOp),
+ DstReg)
+ .add(SrcConst);
+ I = std::next(I);
+ if (MRI->hasOneUse(SrcReg))
+ DefMI->eraseFromParent();
+ MI.eraseFromParent();
+ }
+ }
}
return true;
}