Skip to content

Commit d9e6aa7

Browse files
authored
[AMDGPU] Update LiveInterval def index for early-clobber (#79285)
On converting an instruction to an early-clobber definition in convertToThreeAddress, we must also update live intervals for the register to start at the early-clobber index.
1 parent d8d2dea commit d9e6aa7

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3780,8 +3780,28 @@ MachineInstr *SIInstrInfo::convertToThreeAddress(MachineInstr &MI,
37803780
for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I)
37813781
MIB.add(MI.getOperand(I));
37823782
updateLiveVariables(LV, MI, *MIB);
3783-
if (LIS)
3783+
if (LIS) {
37843784
LIS->ReplaceMachineInstrInMaps(MI, *MIB);
3785+
// SlotIndex of defs needs to be updated when converting to early-clobber
3786+
MachineOperand &Def = MIB->getOperand(0);
3787+
if (Def.isEarlyClobber() && Def.isReg() &&
3788+
LIS->hasInterval(Def.getReg())) {
3789+
SlotIndex OldIndex = LIS->getInstructionIndex(*MIB).getRegSlot(false);
3790+
SlotIndex NewIndex = LIS->getInstructionIndex(*MIB).getRegSlot(true);
3791+
auto &LI = LIS->getInterval(Def.getReg());
3792+
auto UpdateDefIndex = [&](LiveRange &LR) {
3793+
auto S = LR.find(OldIndex);
3794+
if (S != LR.end() && S->start == OldIndex) {
3795+
assert(S->valno && S->valno->def == OldIndex);
3796+
S->start = NewIndex;
3797+
S->valno->def = NewIndex;
3798+
}
3799+
};
3800+
UpdateDefIndex(LI);
3801+
for (auto &SR : LI.subranges())
3802+
UpdateDefIndex(SR);
3803+
}
3804+
}
37853805
return MIB;
37863806
}
37873807

llvm/test/CodeGen/AMDGPU/acc-ldst.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefix=GCN %s
2+
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -verify-machineinstrs -early-live-intervals < %s | FileCheck -enable-var-scope --check-prefix=GCN %s
23

34
declare <32 x float> @llvm.amdgcn.mfma.f32.32x32x1f32(float, float, <32 x float>, i32, i32, i32)
45
declare <4 x i32> @llvm.amdgcn.mfma.i32.4x4x4i8(i32, i32, <4 x i32>, i32, i32, i32)

llvm/test/CodeGen/AMDGPU/mfma-no-register-aliasing.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: llc -mtriple=amdgcn -mcpu=gfx908 -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefixes=GCN,GREEDY,GREEDY908 %s
22
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefixes=GCN,GREEDY,GREEDY90A %s
3+
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -early-live-intervals -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefixes=GCN,GREEDY,GREEDY90A %s
34
; RUN: llc -mtriple=amdgcn -mcpu=gfx940 -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefixes=GCN,GREEDY,GREEDY90A %s
45
; RUN: llc -global-isel -mtriple=amdgcn -mcpu=gfx90a -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefixes=GCN,GREEDY,GREEDY90A-GISEL %s
56
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -sgpr-regalloc=fast -vgpr-regalloc=fast -verify-machineinstrs < %s | FileCheck -enable-var-scope --check-prefixes=GCN,FAST %s

0 commit comments

Comments
 (0)