Skip to content

Commit 67b9d48

Browse files
committed
AMDGPU: Delete spills of undef values
It would be a bit more logical to preserve the undef and do the normal expansion, but this is less work. This avoids verifier errors in a future patch which starts deleting liveness from registers after allocation failures which results in spills of undef values. https://reviews.llvm.org/D122607
1 parent 5e727e8 commit 67b9d48

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,13 @@ bool SIRegisterInfo::spillSGPR(MachineBasicBlock::iterator MI, int Index,
19561956
RegScavenger *RS, SlotIndexes *Indexes,
19571957
LiveIntervals *LIS, bool OnlyToVGPR,
19581958
bool SpillToPhysVGPRLane) const {
1959+
if (MI->getOperand(0).isUndef()) {
1960+
if (Indexes)
1961+
Indexes->removeMachineInstrFromMaps(*MI);
1962+
MI->eraseFromParent();
1963+
return true;
1964+
}
1965+
19591966
SGPRSpillBuilder SB(*this, *ST.getInstrInfo(), isWave32, MI, Index, RS);
19601967

19611968
ArrayRef<SpilledReg> VGPRSpills =
@@ -2377,6 +2384,11 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
23772384
case AMDGPU::SI_SPILL_WWM_AV32_SAVE: {
23782385
const MachineOperand *VData = TII->getNamedOperand(*MI,
23792386
AMDGPU::OpName::vdata);
2387+
if (VData->isUndef()) {
2388+
MI->eraseFromParent();
2389+
return true;
2390+
}
2391+
23802392
assert(TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg() ==
23812393
MFI->getStackPtrOffsetReg());
23822394

llvm/test/CodeGen/AMDGPU/sgpr-spill-partially-undef.mir

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,45 @@ body: |
5454
SI_SPILL_S64_SAVE renamable $sgpr4_sgpr5, %stack.0, implicit $exec, implicit $sgpr96_sgpr97_sgpr98_sgpr99, implicit $sgpr32 :: (store (s64) into %stack.0, align 4, addrspace 5)
5555
5656
...
57+
58+
---
59+
name: sgpr_spill_s32_undef
60+
tracksRegLiveness: true
61+
machineFunctionInfo:
62+
isEntryFunction: true
63+
hasSpilledSGPRs: true
64+
scratchRSrcReg: '$sgpr96_sgpr97_sgpr98_sgpr99'
65+
stackPtrOffsetReg: '$sgpr32'
66+
stack:
67+
- { id: 0, type: spill-slot, size: 4, alignment: 4, stack-id: sgpr-spill }
68+
body: |
69+
bb.0:
70+
; CHECK-LABEL: name: sgpr_spill_s32_undef
71+
; CHECK: body:
72+
; CHECK-NEXT: bb.0:
73+
; CHECK-NOT: {{.+}}
74+
; CHECK: ...
75+
SI_SPILL_S32_SAVE undef $sgpr8, %stack.0, implicit $exec, implicit $sgpr96_sgpr97_sgpr98_sgpr99, implicit $sgpr32 :: (store (s32) into %stack.0, align 4, addrspace 5)
76+
77+
...
78+
79+
---
80+
name: sgpr_spill_s64_undef
81+
tracksRegLiveness: true
82+
machineFunctionInfo:
83+
isEntryFunction: true
84+
hasSpilledSGPRs: true
85+
scratchRSrcReg: '$sgpr96_sgpr97_sgpr98_sgpr99'
86+
stackPtrOffsetReg: '$sgpr32'
87+
stack:
88+
- { id: 0, type: spill-slot, size: 8, alignment: 4, stack-id: sgpr-spill }
89+
body: |
90+
bb.0:
91+
; CHECK-LABEL: name: sgpr_spill_s64_undef
92+
; CHECK: body:
93+
; CHECK-NEXT: bb.0:
94+
; CHECK-NOT: {{.+}}
95+
; CHECK: ...
96+
SI_SPILL_S64_SAVE undef $sgpr8_sgpr9, %stack.0, implicit $exec, implicit $sgpr96_sgpr97_sgpr98_sgpr99, implicit $sgpr32 :: (store (s64) into %stack.0, align 4, addrspace 5)
97+
98+
...

llvm/test/CodeGen/AMDGPU/spill-agpr-partially-undef.mir

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,37 @@ body: |
7171
; CHECK-NEXT: BUFFER_STORE_DWORD_OFFSET killed $vgpr0, $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 4, 0, 0, implicit $exec, implicit killed $agpr0_agpr1 :: (store (s32) into %stack.0 + 4, addrspace 5)
7272
SI_SPILL_A64_SAVE killed $agpr0_agpr1, %stack.0, $sgpr32, 0, implicit $exec :: (store (s64) into %stack.0, addrspace 5)
7373
...
74+
75+
---
76+
name: spill_a32_undef
77+
tracksRegLiveness: true
78+
stack:
79+
- { id: 0, type: spill-slot, size: 4, alignment: 4 }
80+
machineFunctionInfo:
81+
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3'
82+
stackPtrOffsetReg: '$sgpr32'
83+
frameOffsetReg: '$sgpr33'
84+
body: |
85+
bb.0:
86+
; CHECK-LABEL: name: spill_a32_undef
87+
; CHECK: S_ENDPGM 0
88+
SI_SPILL_A32_SAVE undef $agpr0, %stack.0, $sgpr32, 0, implicit $exec :: (store (s32) into %stack.0, addrspace 5)
89+
S_ENDPGM 0
90+
...
91+
92+
---
93+
name: spill_a64_undef
94+
tracksRegLiveness: true
95+
stack:
96+
- { id: 0, type: spill-slot, size: 8, alignment: 4 }
97+
machineFunctionInfo:
98+
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3'
99+
stackPtrOffsetReg: '$sgpr32'
100+
frameOffsetReg: '$sgpr33'
101+
body: |
102+
bb.0:
103+
; CHECK-LABEL: name: spill_a64_undef
104+
; CHECK: S_ENDPGM 0
105+
SI_SPILL_A64_SAVE undef $agpr0_agpr1, %stack.0, $sgpr32, 0, implicit $exec :: (store (s64) into %stack.0, addrspace 5)
106+
S_ENDPGM 0
107+
...

llvm/test/CodeGen/AMDGPU/vgpr-spill.mir

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,37 @@ body: |
153153
; CHECK-NEXT: BUFFER_STORE_DWORD_OFFSET killed $vgpr3, $sgpr0_sgpr1_sgpr2_sgpr3, $sgpr32, 12, 0, 0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3 :: (store (s32) into %stack.0 + 12, addrspace 5)
154154
SI_SPILL_V128_SAVE killed $vgpr0_vgpr1_vgpr2_vgpr3, %stack.0, $sgpr32, 0, implicit $exec :: (store (s128) into %stack.0, addrspace 5)
155155
...
156+
157+
---
158+
name: spill_v32_undef
159+
tracksRegLiveness: true
160+
stack:
161+
- { id: 0, type: spill-slot, size: 4, alignment: 4 }
162+
machineFunctionInfo:
163+
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3'
164+
stackPtrOffsetReg: '$sgpr32'
165+
frameOffsetReg: '$sgpr33'
166+
body: |
167+
bb.0:
168+
; CHECK-LABEL: name: spill_v32_undef
169+
; CHECK: S_NOP 0, implicit undef $vgpr0
170+
SI_SPILL_V32_SAVE undef $vgpr0, %stack.0, $sgpr32, 0, implicit $exec :: (store (s32) into %stack.0, addrspace 5)
171+
S_NOP 0, implicit undef $vgpr0
172+
...
173+
174+
---
175+
name: spill_v64_undef
176+
tracksRegLiveness: true
177+
stack:
178+
- { id: 0, type: spill-slot, size: 8, alignment: 4 }
179+
machineFunctionInfo:
180+
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3'
181+
stackPtrOffsetReg: '$sgpr32'
182+
frameOffsetReg: '$sgpr33'
183+
body: |
184+
bb.0:
185+
; CHECK-LABEL: name: spill_v64_undef
186+
; CHECK: S_NOP 0, implicit undef $vgpr0_vgpr1
187+
SI_SPILL_V64_SAVE undef $vgpr0_vgpr1, %stack.0, $sgpr32, 0, implicit $exec :: (store (s64) into %stack.0, addrspace 5)
188+
S_NOP 0, implicit undef $vgpr0_vgpr1
189+
...

0 commit comments

Comments
 (0)