diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp --- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp +++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp @@ -845,6 +845,18 @@ 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(1); + assert(SrcConst.isImm() && "Operand should be immediate"); + Register TmpReg = + MRI->createVirtualRegister(&AMDGPU::SReg_32_XM0RegClass); + BuildMI(*MI.getParent(), MI, MI.getDebugLoc(), + TII->get(AMDGPU::S_MOV_B32), TmpReg) + .addImm(SrcConst.getImm()); + MI.getOperand(1).setReg(TmpReg); + } } return true; }