Skip to content

Commit 353322f

Browse files
authored
[AMDGPU] Fix end() iterator dereference in SILowerSGPRSpills (#88828)
1 parent 7257c37 commit 353322f

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

llvm/lib/Target/AMDGPU/SILowerSGPRSpills.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
278278
for (auto Reg : MFI->getSGPRSpillVGPRs()) {
279279
for (MachineBasicBlock *SaveBlock : SaveBlocks) {
280280
MachineBasicBlock::iterator InsertBefore = SaveBlock->begin();
281-
auto MIB = BuildMI(*SaveBlock, *InsertBefore, InsertBefore->getDebugLoc(),
281+
DebugLoc DL = SaveBlock->findDebugLoc(InsertBefore);
282+
auto MIB = BuildMI(*SaveBlock, InsertBefore, DL,
282283
TII->get(AMDGPU::IMPLICIT_DEF), Reg);
283284
MFI->setFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG);
284285
// Set SGPR_SPILL asm printer flag
@@ -294,10 +295,10 @@ void SILowerSGPRSpills::extendWWMVirtRegLiveness(MachineFunction &MF,
294295
for (MachineBasicBlock *RestoreBlock : RestoreBlocks) {
295296
MachineBasicBlock::iterator InsertBefore =
296297
RestoreBlock->getFirstTerminator();
298+
DebugLoc DL = RestoreBlock->findDebugLoc(InsertBefore);
297299
for (auto Reg : MFI->getSGPRSpillVGPRs()) {
298-
auto MIB =
299-
BuildMI(*RestoreBlock, *InsertBefore, InsertBefore->getDebugLoc(),
300-
TII->get(TargetOpcode::KILL));
300+
auto MIB = BuildMI(*RestoreBlock, InsertBefore, DL,
301+
TII->get(TargetOpcode::KILL));
301302
MIB.addReg(Reg);
302303
if (LIS)
303304
LIS->InsertMachineInstrInMaps(*MIB);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
2+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs -run-pass=si-lower-sgpr-spills -o - %s | FileCheck %s
3+
4+
# Test that the si-lower-sgpr-spills pass does not defeference a
5+
# machine instruction iterator that is equal to end().
6+
7+
---
8+
name: empty_prolog_block
9+
stack:
10+
- { id: 0, name: '', type: spill-slot, offset: 0, size: 32, alignment: 4,
11+
stack-id: sgpr-spill, callee-saved-register: '', callee-saved-restored: true,
12+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
13+
machineFunctionInfo:
14+
hasSpilledSGPRs: true
15+
body: |
16+
; CHECK-LABEL: name: empty_prolog_block
17+
; CHECK: bb.0:
18+
; CHECK-NEXT: successors: %bb.1(0x80000000)
19+
; CHECK-NEXT: liveins: $sgpr0
20+
; CHECK-NEXT: {{ $}}
21+
; CHECK-NEXT: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
22+
; CHECK-NEXT: {{ $}}
23+
; CHECK-NEXT: bb.1:
24+
; CHECK-NEXT: $sgpr0 = SI_RESTORE_S32_FROM_VGPR [[DEF]], 0
25+
; CHECK-NEXT: KILL [[DEF]]
26+
; CHECK-NEXT: S_ENDPGM 0
27+
bb.0:
28+
liveins: $sgpr0
29+
bb.1:
30+
renamable $sgpr0 = SI_SPILL_S32_RESTORE %stack.0, implicit $exec, implicit $sgpr32
31+
S_ENDPGM 0
32+
33+
...

0 commit comments

Comments
 (0)