1# RUN: llc -mtriple riscv64 -mattr=+m,+v -run-pass=prologepilog \
2# RUN:     -riscv-v-vector-bits-min=512 -o - %s | FileCheck %s
3#
4# Stack layout of this program
5# |--------------------------| -- <-- Incoming SP
6# | a7 (Vaarg)               |
7# | ------------------------ | -- <-- New SP + vlenb  + 72
8# | a6 (Vaarg)               |
9# | ------------------------ | -- <-- New SP + vlenb  + 64
10# | ra (Callee-saved reg)    |
11# | ------------------------ | -- <-- New SP + vlenb  + 56
12# | s0 (Callee-saved reg)    |
13# | ------------------------ | -- <-- New SP + vlenb  + 48
14# | s1 (Callee-saved reg)    |
15# | ------------------------ | -- <-- New SP + vlenb  + 40
16# | 8 bytes of padding       |
17# | ------------------------ | -- <-- New SP + vlenb
18# | v8 (RVV objects)         |
19# | ------------------------ | -- <-- New SP + 32
20# | buf1                     |
21# |--------------------------| -- <-- New SP + 16
22# | Stack ID 5               |
23# |--------------------------| -- <-- New SP + 8
24# | Stack ID 6               |
25# |--------------------------| -- <-- New SP
26
27--- |
28  ; ModuleID = 'wrong-stack-offset-for-rvv-object.ll'
29  source_filename = "wrong-stack-offset-for-rvv-object.ll"
30  target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
31  target triple = "riscv64"
32
33  %struct = type { i32 }
34
35  define void @asm_fprintf(%struct %file, i8* %p, [10 x i8]* %buf, i8* %arrayidx3, <2 x i8>* %0, i8* %1, ...) #0 {
36  entry:
37    %buf1 = alloca [10 x i8], i32 0, align 8
38    %arrayidx32 = getelementptr inbounds [10 x i8], [10 x i8]* %buf, i64 0, i64 1
39    br label %while.cond
40
41  while.cond:                                       ; preds = %while.cond, %sw.bb, %entry
42    %incdec.ptr = getelementptr inbounds i8, i8* undef, i64 1
43    %2 = load i8, i8* null, align 1
44    %3 = zext i8 0 to i64
45    %cond = icmp eq i64 %3, 0
46    br i1 %cond, label %sw.bb, label %while.cond
47
48  sw.bb:                                            ; preds = %while.cond
49    %4 = load i8, i8* null, align 1
50    store <2 x i8> zeroinitializer, <2 x i8>* %0, align 1
51    %call = call i32 (i8*, ...) @fprintf(i8* %p)
52    br label %while.cond
53  }
54
55  declare i32 @fprintf(i8*, ...) #0
56
57  attributes #0 = { "target-features"="+m,+v" }
58
59...
60---
61name:            asm_fprintf
62alignment:       4
63exposesReturnsTwice: false
64legalized:       false
65regBankSelected: false
66selected:        false
67failedISel:      false
68tracksRegLiveness: true
69hasWinCFI:       false
70failsVerification: false
71tracksDebugUserValues: true
72registers:       []
73liveins:
74  - { reg: '$x11', virtual-reg: '' }
75  - { reg: '$x14', virtual-reg: '' }
76  - { reg: '$x16', virtual-reg: '' }
77  - { reg: '$x17', virtual-reg: '' }
78frameInfo:
79  isFrameAddressTaken: false
80  isReturnAddressTaken: false
81  hasStackMap:     false
82  hasPatchPoint:   false
83  stackSize:       0
84  offsetAdjustment: 0
85  maxAlignment:    8
86  adjustsStack:    false
87  hasCalls:        true
88  stackProtector:  ''
89  maxCallFrameSize: 4294967295
90  cvBytesOfCalleeSavedRegisters: 0
91  hasOpaqueSPAdjustment: false
92  hasVAStart:      false
93  hasMustTailInVarArgFunc: false
94  hasTailCall:     false
95  localFrameSize:  0
96  savePoint:       ''
97  restorePoint:    ''
98fixedStack:
99  - { id: 0, type: default, offset: -8, size: 8, alignment: 8, stack-id: default,
100      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
101      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
102  - { id: 1, type: default, offset: -16, size: 8, alignment: 16, stack-id: default,
103      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
104      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
105  - { id: 2, type: default, offset: -16, size: 8, alignment: 16, stack-id: default,
106      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
107      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
108stack:
109  - { id: 0, name: buf1, type: default, offset: 0, size: 1, alignment: 8,
110      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
111      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
112  - { id: 1, name: '', type: spill-slot, offset: 0, size: 8, alignment: 8,
113      stack-id: scalable-vector, callee-saved-register: '', callee-saved-restored: true,
114      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
115callSites:       []
116debugValueSubstitutions: []
117constants:       []
118machineFunctionInfo:
119  varArgsFrameIndex: -1
120  varArgsSaveSize: 16
121body:             |
122  ; CHECK-LABEL: name: asm_fprintf
123  ; CHECK: stack:
124  ; CHECK-NEXT:  - { id: 0, name: buf1, type: default, offset: -48, size: 1, alignment: 8,
125  ; CHECK-NEXT:      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
126  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
127  ; CHECK-NEXT:  - { id: 1, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8,
128  ; CHECK-NEXT:      stack-id: scalable-vector, callee-saved-register: '', callee-saved-restored: true,
129  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
130  ; CHECK-NEXT:  - { id: 2, name: '', type: spill-slot, offset: -24, size: 8, alignment: 8,
131  ; CHECK-NEXT:      stack-id: default, callee-saved-register: '$x1', callee-saved-restored: true,
132  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
133  ; CHECK-NEXT:  - { id: 3, name: '', type: spill-slot, offset: -32, size: 8, alignment: 8,
134  ; CHECK-NEXT:      stack-id: default, callee-saved-register: '$x8', callee-saved-restored: true,
135  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
136  ; CHECK-NEXT:  - { id: 4, name: '', type: spill-slot, offset: -40, size: 8, alignment: 8,
137  ; CHECK-NEXT:      stack-id: default, callee-saved-register: '$x9', callee-saved-restored: true,
138  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
139  ; CHECK-NEXT:  - { id: 5, name: '', type: default, offset: -56, size: 8, alignment: 8,
140  ; CHECK-NEXT:      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
141  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
142  ; CHECK-NEXT:  - { id: 6, name: '', type: default, offset: -64, size: 8, alignment: 8,
143  ; CHECK-NEXT:      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
144  ; CHECK-NEXT:      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
145  ; CHECK: bb.0.entry:
146  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
147  ; CHECK-NEXT:   liveins: $x11, $x14, $x16, $x17, $x1, $x8, $x9
148  ; CHECK-NEXT: {{  $}}
149  ; CHECK-NEXT:   $x2 = frame-setup ADDI $x2, -80
150  ; CHECK-NEXT:   frame-setup CFI_INSTRUCTION def_cfa_offset 80
151  ; CHECK-NEXT:   SD killed $x1, $x2, 56 :: (store (s64) into %stack.2)
152  ; CHECK-NEXT:   SD killed $x8, $x2, 48 :: (store (s64) into %stack.3)
153  ; CHECK-NEXT:   SD killed $x9, $x2, 40 :: (store (s64) into %stack.4)
154  ; CHECK-NEXT:   frame-setup CFI_INSTRUCTION offset $x1, -24
155  ; CHECK-NEXT:   frame-setup CFI_INSTRUCTION offset $x8, -32
156  ; CHECK-NEXT:   frame-setup CFI_INSTRUCTION offset $x9, -40
157  ; CHECK-NEXT:   $x10 = frame-setup PseudoReadVLENB
158  ; CHECK-NEXT:   $x10 = frame-setup SLLI killed $x10, 1
159  ; CHECK-NEXT:   $x2 = frame-setup SUB $x2, killed $x10
160  ; CHECK-NEXT:   renamable $x8 = COPY $x14
161  ; CHECK-NEXT:   renamable $x9 = COPY $x11
162  ; CHECK-NEXT:   $x10 = PseudoReadVLENB
163  ; CHECK-NEXT:   $x10 = SLLI killed $x10, 1
164  ; CHECK-NEXT:   $x10 = ADD $x2, killed $x10
165  ; CHECK-NEXT:   SD killed renamable $x17, killed $x10, 72 :: (store (s64))
166  ; CHECK-NEXT:   $x10 = PseudoReadVLENB
167  ; CHECK-NEXT:   $x10 = SLLI killed $x10, 1
168  ; CHECK-NEXT:   $x10 = ADD $x2, killed $x10
169  ; CHECK-NEXT:   SD killed renamable $x16, killed $x10, 64 :: (store (s64) into %fixed-stack.1, align 16)
170  ; CHECK-NEXT:   dead $x0 = PseudoVSETIVLI 2, 69 /* e8, mf8, ta, mu */, implicit-def $vl, implicit-def $vtype
171  ; CHECK-NEXT:   renamable $v8 = PseudoVMV_V_I_MF8 0, 2, 3 /* e8 */, implicit $vl, implicit $vtype
172  ; CHECK-NEXT:   $x10 = ADDI $x2, 32
173  ; CHECK-NEXT:   PseudoVSPILL_M1 killed renamable $v8, killed $x10 :: (store unknown-size into %stack.1, align 8)
174  ; CHECK-NEXT: {{  $}}
175  ; CHECK-NEXT: bb.1.while.cond:
176  ; CHECK-NEXT:   successors: %bb.2(0x30000000), %bb.1(0x50000000)
177  ; CHECK-NEXT:   liveins: $x8, $x9
178  ; CHECK-NEXT: {{  $}}
179  ; CHECK-NEXT:   BNE $x0, $x0, %bb.1
180  ; CHECK-NEXT:   PseudoBR %bb.2
181  ; CHECK-NEXT: {{  $}}
182  ; CHECK-NEXT: bb.2.sw.bb:
183  ; CHECK-NEXT:   successors: %bb.1(0x80000000)
184  ; CHECK-NEXT:   liveins: $x8, $x9
185  ; CHECK-NEXT: {{  $}}
186  ; CHECK-NEXT:   dead $x0 = PseudoVSETIVLI 2, 69 /* e8, mf8, ta, mu */, implicit-def $vl, implicit-def $vtype
187  ; CHECK-NEXT:   $x10 = ADDI $x2, 32
188  ; CHECK-NEXT:   renamable $v8 = PseudoVRELOAD_M1 killed $x10 :: (load unknown-size from %stack.1, align 8)
189  ; CHECK-NEXT:   PseudoVSE8_V_MF8 killed renamable $v8, renamable $x8, 2, 3 /* e8 */, implicit $vl, implicit $vtype :: (store (s16) into %ir.0, align 1)
190  ; CHECK-NEXT:   $x10 = COPY renamable $x9
191  ; CHECK-NEXT:   PseudoCALL target-flags(riscv-plt) @fprintf, csr_ilp32d_lp64d, implicit-def dead $x1, implicit killed $x10, implicit-def $x2, implicit-def dead $x10
192  ; CHECK-NEXT:   PseudoBR %bb.1
193  bb.0.entry:
194    successors: %bb.1(0x80000000)
195    liveins: $x11, $x14, $x16, $x17
196
197    renamable $x8 = COPY $x14
198    renamable $x9 = COPY $x11
199    SD killed renamable $x17, %fixed-stack.0, 0 :: (store (s64))
200    SD killed renamable $x16, %fixed-stack.1, 0 :: (store (s64) into %fixed-stack.1, align 16)
201    dead $x0 = PseudoVSETIVLI 2, 69, implicit-def $vl, implicit-def $vtype
202    renamable $v8 = PseudoVMV_V_I_MF8 0, 2, 3, implicit $vl, implicit $vtype
203    PseudoVSPILL_M1 killed renamable $v8, %stack.1 :: (store unknown-size into %stack.1, align 8)
204
205  bb.1.while.cond:
206    successors: %bb.2(0x30000000), %bb.1(0x50000000)
207    liveins: $x8, $x9
208
209    BNE $x0, $x0, %bb.1
210    PseudoBR %bb.2
211
212  bb.2.sw.bb:
213    successors: %bb.1(0x80000000)
214    liveins: $x8, $x9
215
216    dead $x0 = PseudoVSETIVLI 2, 69, implicit-def $vl, implicit-def $vtype
217    renamable $v8 = PseudoVRELOAD_M1 %stack.1 :: (load unknown-size from %stack.1, align 8)
218    PseudoVSE8_V_MF8 killed renamable $v8, renamable $x8, 2, 3, implicit $vl, implicit $vtype :: (store (s16) into %ir.0, align 1)
219    ADJCALLSTACKDOWN 0, 0, implicit-def dead $x2, implicit $x2
220    $x10 = COPY renamable $x9
221    PseudoCALL target-flags(riscv-plt) @fprintf, csr_ilp32d_lp64d, implicit-def dead $x1, implicit killed $x10, implicit-def $x2, implicit-def dead $x10
222    ADJCALLSTACKUP 0, 0, implicit-def dead $x2, implicit $x2
223    PseudoBR %bb.1
224
225...
226