1# This test used to crash MIRPrinter::convertStackObjects():
2# MFI can contain some dead stack objects after PEI pass, but objects storage
3# contains not dead objects only. So using objects IDs as offset in the storage
4# caused out of bounds access.
5
6# RUN: llc -march=amdgcn -run-pass=si-lower-sgpr-spills,prologepilog -verify-machineinstrs -o - %s | FileCheck %s
7
8# CHECK-LABEL: name:            foo
9# CHECK: {{^}}fixedStack:      []
10# CHECK: stack:           []
11
12# CHECK-LABEL: name:            bar
13# CHECK: fixedStack:      []
14# CHECK-NEXT: {{^}}stack:
15# CHECK-NEXT:  - { id:
16
17
18---
19name:            foo
20liveins:
21  - { reg: '$sgpr30_sgpr31', virtual-reg: '' }
22body:             |
23  bb.0:
24    S_SETPC_B64_return killed renamable $sgpr30_sgpr31
25
26...
27---
28name:            bar
29tracksRegLiveness: true
30liveins:
31  - { reg: '$vgpr0', virtual-reg: '' }
32  - { reg: '$vgpr1', virtual-reg: '' }
33  - { reg: '$vgpr2', virtual-reg: '' }
34  - { reg: '$sgpr30_sgpr31', virtual-reg: '' }
35stack:
36  - { id: 0, name: '', type: spill-slot, offset: 0, size: 8, alignment: 4,
37      stack-id: sgpr-spill, callee-saved-register: '', callee-saved-restored: true,
38      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
39machineFunctionInfo:
40  scratchRSrcReg:  '$sgpr0_sgpr1_sgpr2_sgpr3'
41  stackPtrOffsetReg: '$sgpr32'
42body:             |
43  bb.0:
44    liveins: $vgpr0, $vgpr1, $vgpr2, $sgpr30_sgpr31
45
46    renamable $vgpr41 = COPY $vgpr2, implicit $exec
47    renamable $vgpr40 = COPY $vgpr1, implicit $exec
48    renamable $vcc = V_CMP_NE_U32_e64 42, killed $vgpr0, implicit $exec
49    $sgpr4_sgpr5 = S_AND_SAVEEXEC_B64 $vcc, implicit-def $exec, implicit-def $scc, implicit $exec
50    renamable $sgpr34_sgpr35 = S_XOR_B64 $exec, killed renamable $sgpr4_sgpr5, implicit-def dead $scc
51
52    ADJCALLSTACKUP 0, 0, implicit-def dead $scc, implicit-def $sgpr32, implicit $sgpr32
53    renamable $sgpr4_sgpr5 = SI_PC_ADD_REL_OFFSET target-flags(amdgpu-gotprel32-lo) @foo + 4, target-flags(amdgpu-gotprel32-hi) @foo + 12, implicit-def dead $scc
54    renamable $sgpr4_sgpr5 = S_LOAD_DWORDX2_IMM killed renamable $sgpr4_sgpr5, 0, 0, 0
55    SI_SPILL_S64_SAVE killed renamable $sgpr30_sgpr31, %stack.0, implicit $exec, implicit $sgpr0_sgpr1_sgpr2_sgpr3, implicit $sgpr32
56    dead $sgpr30_sgpr31 = SI_CALL killed renamable $sgpr4_sgpr5, @foo, csr_amdgpu_highregs, implicit $sgpr0_sgpr1_sgpr2_sgpr3
57    renamable $sgpr30_sgpr31 = SI_SPILL_S64_RESTORE %stack.0, implicit $exec, implicit $sgpr0_sgpr1_sgpr2_sgpr3, implicit $sgpr32
58    ADJCALLSTACKDOWN 0, 0, implicit-def dead $scc, implicit-def $sgpr32, implicit $sgpr32
59
60    S_SETPC_B64_return killed renamable $sgpr30_sgpr31
61
62...
63
64