Skip to content

Commit a84c256

Browse files
committed
[AMDGPU][SelectionDAG] Use COPY instead of S_MOV_B32 to assign values to M0 (llvm#132957)
This is consistent with what's done on GISel. This allows the register coalescer to remove the redundant intermediate `s_mov_b32` instructions by using `m0` directly as the result register.
1 parent d42900d commit a84c256

13 files changed

+1320
-601
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,8 +4561,8 @@ emitLoadM0FromVGPRLoop(const SIInstrInfo *TII, MachineRegisterInfo &MRI,
45614561
} else {
45624562
// Move index from VCC into M0
45634563
if (Offset == 0) {
4564-
BuildMI(LoopBB, I, DL, TII->get(AMDGPU::S_MOV_B32), AMDGPU::M0)
4565-
.addReg(CurrentIdxReg, RegState::Kill);
4564+
BuildMI(LoopBB, I, DL, TII->get(AMDGPU::COPY), AMDGPU::M0)
4565+
.addReg(CurrentIdxReg, RegState::Kill);
45664566
} else {
45674567
BuildMI(LoopBB, I, DL, TII->get(AMDGPU::S_ADD_I32), AMDGPU::M0)
45684568
.addReg(CurrentIdxReg, RegState::Kill)
@@ -4669,7 +4669,7 @@ static void setM0ToIndexFromSGPR(const SIInstrInfo *TII,
46694669
assert(Idx->getReg() != AMDGPU::NoRegister);
46704670

46714671
if (Offset == 0) {
4672-
BuildMI(*MBB, I, DL, TII->get(AMDGPU::S_MOV_B32), AMDGPU::M0).add(*Idx);
4672+
BuildMI(*MBB, I, DL, TII->get(AMDGPU::COPY), AMDGPU::M0).add(*Idx);
46734673
} else {
46744674
BuildMI(*MBB, I, DL, TII->get(AMDGPU::S_ADD_I32), AMDGPU::M0)
46754675
.add(*Idx)
@@ -5245,9 +5245,11 @@ MachineBasicBlock *SITargetLowering::EmitInstrWithCustomInserter(
52455245
return BB;
52465246
}
52475247
case AMDGPU::SI_INIT_M0: {
5248+
MachineOperand &M0Init = MI.getOperand(0);
52485249
BuildMI(*BB, MI.getIterator(), MI.getDebugLoc(),
5249-
TII->get(AMDGPU::S_MOV_B32), AMDGPU::M0)
5250-
.add(MI.getOperand(0));
5250+
TII->get(M0Init.isReg() ? AMDGPU::COPY : AMDGPU::S_MOV_B32),
5251+
AMDGPU::M0)
5252+
.add(M0Init);
52515253
MI.eraseFromParent();
52525254
return BB;
52535255
}

0 commit comments

Comments
 (0)