1 # RUN: llc -run-pass=livedebugvalues -o - %s | FileCheck %s
3 # This test is used to acknowledge situation when spill register is killed
4 # in instruction after the spill occurs.
5 # Generated MIR is changed in order to test case when instruction after
6 # possible spill, say instruction B, kills register different than than
7 # the one that is used in possible spill, say instruction A. In that case
8 # the instruction A is not recognized as spill. Changed instructions are
9 # commented in MIR below.
12 # A - possible spill instruction with register R2
13 # B - instruction that kills R3
17 # CHECK: DBG_VALUE $rbp, 0, !37, !DIExpression(DW_OP_constu, 44, DW_OP_minus), debug-location !58
18 # CHECK-NOT: DBG_VALUE $rbp, 0, !36, !DIExpression(DW_OP_constu, 48, DW_OP_minus), debug-location !57
21 ; ModuleID = '<stdin>'
22 source_filename = "<stdin>"
23 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
24 target triple = "x86_64-unknown-linux-gnu"
26 %struct.firstStruct = type { i32, i8, %struct.secondStruct* }
27 %struct.secondStruct = type { i32, i8, i8* }
28 %struct.thirdStruct = type { %struct.fourthStruct, i32*, i8* }
29 %struct.fourthStruct = type { i32, i32, i32, i32 }
31 @.str = private unnamed_addr constant [7 x i8] c"Error:\00", align 1
32 @firstStruct = common local_unnamed_addr global %struct.firstStruct zeroinitializer, align 8, !dbg !0
34 ; Function Attrs: nounwind uwtable
35 define i32 @foo(i32 %variable2, i32 %variable1) local_unnamed_addr #0 !dbg !31 {
37 %const1 = bitcast i64 -9223372036854775808 to i64
38 %0 = bitcast i64 %const1 to i64
39 call void @llvm.dbg.value(metadata i32 %variable2, metadata !36, metadata !DIExpression()), !dbg !57
40 call void @llvm.dbg.value(metadata i32 %variable1, metadata !37, metadata !DIExpression()), !dbg !58
41 %call = tail call %struct.firstStruct* @func1(i32 %variable1)
42 %1 = ptrtoint %struct.firstStruct* %call to i64
44 %tobool = icmp eq i64 %2, 0
45 br i1 %tobool, label %cleanup, label %if.end
47 if.end: ; preds = %entry
48 %call1 = tail call %struct.thirdStruct* @func2(i32 %variable2, i32 %variable1)
49 %3 = ptrtoint %struct.thirdStruct* %call1 to i64
51 %tobool2 = icmp eq i64 %4, 0
52 br i1 %tobool2, label %if.then3, label %private.exit
54 if.then3: ; preds = %if.end
55 %5 = inttoptr i64 %2 to %struct.firstStruct*
56 %variableLocal11 = bitcast %struct.firstStruct* %5 to i32*
57 %6 = load i32, i32* %variableLocal11, align 8
58 %variableLocal2 = getelementptr inbounds %struct.firstStruct, %struct.firstStruct* %5, i64 0, i32 1
59 %7 = load i8, i8* %variableLocal2, align 4
60 tail call void @func3(i32 %6, i8 zeroext %7, i8 zeroext 5, i8* inttoptr (i64 or (i64 ptrtoint ([7 x i8]* @.str to i64), i64 -92238) to i8*), i32 %variable2)
63 private.exit: ; preds = %if.end
64 %8 = bitcast i64 %const1 to i64
65 %9 = ptrtoint %struct.thirdStruct* %call1 to i64
67 %11 = inttoptr i64 %10 to i8*
68 %call5.i = tail call i8* @memset(i8* %11, i32 0, i64 16)
69 %call6 = tail call i32 @func4(%struct.thirdStruct* %call1)
70 %tobool7 = icmp eq i32 %call6, 0
71 br i1 %tobool7, label %cleanup, label %if.then8
73 if.then8: ; preds = %private.exit
74 %12 = inttoptr i64 %2 to %struct.firstStruct*
75 tail call void @func5(%struct.thirdStruct* %call1, i32 0)
76 %rc_db = getelementptr inbounds %struct.firstStruct, %struct.firstStruct* %12, i64 0, i32 2
77 %13 = bitcast %struct.secondStruct** %rc_db to i64*
78 %14 = load i64, i64* %13, align 8
79 %tobool9 = icmp eq i64 %14, 0
80 br i1 %tobool9, label %cleanup, label %land.lhs.true
82 land.lhs.true: ; preds = %if.then8
83 %15 = inttoptr i64 %4 to %struct.thirdStruct*
84 %tot_perf2 = bitcast %struct.thirdStruct* %15 to i32*
85 %16 = load i32, i32* %tot_perf2, align 8
86 %tobool11 = icmp eq i32 %16, 0
87 br i1 %tobool11, label %lor.lhs.false, label %if.then14
89 lor.lhs.false: ; preds = %land.lhs.true
90 %17 = inttoptr i64 %4 to %struct.thirdStruct*
91 %tot_bw = getelementptr inbounds %struct.thirdStruct, %struct.thirdStruct* %17, i64 0, i32 0, i32 1
92 %18 = load i32, i32* %tot_bw, align 4
93 %tobool13 = icmp eq i32 %18, 0
94 br i1 %tobool13, label %cleanup, label %if.then14
96 if.then14: ; preds = %lor.lhs.false, %land.lhs.true
97 %19 = inttoptr i64 %14 to %struct.secondStruct*
98 %mc_origin = getelementptr inbounds %struct.secondStruct, %struct.secondStruct* %19, i64 0, i32 2
99 %20 = bitcast i8** %mc_origin to i64*
100 %21 = load i64, i64* %20, align 8
101 %22 = inttoptr i64 %21 to i8*
102 tail call void @func6(%struct.thirdStruct* %call1, i32 %variable1, i8* %22)
105 cleanup: ; preds = %if.then14, %lor.lhs.false, %if.then8, %private.exit, %if.then3, %entry
106 %retval.0 = phi i32 [ 0, %if.then3 ], [ 0, %entry ], [ 1, %lor.lhs.false ], [ 1, %if.then8 ], [ 1, %private.exit ], [ 1, %if.then14 ]
110 declare %struct.firstStruct* @func1(i32) local_unnamed_addr
112 declare %struct.thirdStruct* @func2(i32, i32) local_unnamed_addr
114 declare void @func3(i32, i8 zeroext, i8 zeroext, i8*, i32) local_unnamed_addr
116 declare i32 @func4(%struct.thirdStruct*) local_unnamed_addr
118 declare void @func5(%struct.thirdStruct*, i32) local_unnamed_addr
120 declare void @func6(%struct.thirdStruct*, i32, i8*) local_unnamed_addr
122 declare i8* @__memset_to_buf(i64, i8*, i32, i64) local_unnamed_addr
124 declare i8* @memset(i8*, i32, i64) local_unnamed_addr
126 ; Function Attrs: nounwind readnone speculatable
127 declare void @llvm.dbg.value(metadata, metadata, metadata) #1
129 ; Function Attrs: nounwind
130 declare void @llvm.stackprotector(i8*, i8**) #2
132 attributes #0 = { nounwind uwtable "no-frame-pointer-elim-non-leaf" }
133 attributes #1 = { nounwind readnone speculatable }
134 attributes #2 = { nounwind }
137 !llvm.module.flags = !{!27, !28, !29}
140 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
141 !1 = distinct !DIGlobalVariable(name: "firstStruct", scope: !2, file: !3, line: 23, type: !11, isLocal: false, isDefinition: true)
142 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !10)
143 !3 = !DIFile(filename: "inlineSpillerTest.c", directory: "/")
146 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
147 !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !8, line: 98, baseType: !9)
148 !8 = !DIFile(filename: "/tmp.h", directory: "/tmp")
149 !9 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)
151 !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "firstStruct", file: !3, line: 18, size: 128, elements: !12)
152 !12 = !{!13, !16, !19}
153 !13 = !DIDerivedType(tag: DW_TAG_member, name: "elem1", scope: !11, file: !3, line: 20, baseType: !14, size: 32)
154 !14 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32", file: !3, line: 4, baseType: !15)
155 !15 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
156 !16 = !DIDerivedType(tag: DW_TAG_member, name: "elem2", scope: !11, file: !3, line: 21, baseType: !17, size: 8, offset: 32)
157 !17 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8", file: !3, line: 5, baseType: !18)
158 !18 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
159 !19 = !DIDerivedType(tag: DW_TAG_member, name: "elem3", scope: !11, file: !3, line: 22, baseType: !20, size: 64, offset: 64)
160 !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)
161 !21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "secondStruct", file: !3, line: 11, size: 128, elements: !22)
162 !22 = !{!23, !24, !25}
163 !23 = !DIDerivedType(tag: DW_TAG_member, name: "structMember", scope: !21, file: !3, line: 13, baseType: !14, size: 32)
164 !24 = !DIDerivedType(tag: DW_TAG_member, name: "elem4", scope: !21, file: !3, line: 14, baseType: !17, size: 8, offset: 32)
165 !25 = !DIDerivedType(tag: DW_TAG_member, name: "elem5", scope: !21, file: !3, line: 15, baseType: !26, size: 64, offset: 64)
166 !26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
167 !27 = !{i32 2, !"Dwarf Version", i32 4}
168 !28 = !{i32 2, !"Debug Info Version", i32 3}
169 !29 = !{i32 7, !"PIC Level", i32 2}
170 !30 = !{!"clang version 4.0.0 "}
171 !31 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 50, type: !32, isLocal: false, isDefinition: true, scopeLine: 52, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !35)
172 !32 = !DISubroutineType(types: !33)
173 !33 = !{!34, !14, !14}
174 !34 = !DIDerivedType(tag: DW_TAG_typedef, name: "boolean", file: !3, line: 6, baseType: !6)
175 !35 = !{!36, !37, !38, !54, !55}
176 !36 = !DILocalVariable(name: "variable2", arg: 1, scope: !31, file: !3, line: 50, type: !14)
177 !37 = !DILocalVariable(name: "variable1", arg: 2, scope: !31, file: !3, line: 51, type: !14)
178 !38 = !DILocalVariable(name: "localVariable5", scope: !31, file: !3, line: 53, type: !39)
179 !39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !40, size: 64)
180 !40 = !DIDerivedType(tag: DW_TAG_typedef, name: "thirdStruct_", file: !3, line: 37, baseType: !41)
181 !41 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "thirdStruct", file: !3, line: 32, size: 256, elements: !42)
182 !42 = !{!43, !51, !53}
183 !43 = !DIDerivedType(tag: DW_TAG_member, name: "elem6", scope: !41, file: !3, line: 34, baseType: !44, size: 128)
184 !44 = !DIDerivedType(tag: DW_TAG_typedef, name: "fourthStruct_", file: !3, line: 30, baseType: !45)
185 !45 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "fourthStruct", file: !3, line: 25, size: 128, elements: !46)
186 !46 = !{!47, !48, !49, !50}
187 !47 = !DIDerivedType(tag: DW_TAG_member, name: "elem7", scope: !45, file: !3, line: 26, baseType: !14, size: 32)
188 !48 = !DIDerivedType(tag: DW_TAG_member, name: "elem8", scope: !45, file: !3, line: 27, baseType: !14, size: 32, offset: 32)
189 !49 = !DIDerivedType(tag: DW_TAG_member, name: "elem9", scope: !45, file: !3, line: 28, baseType: !34, size: 32, offset: 64)
190 !50 = !DIDerivedType(tag: DW_TAG_member, name: "elem10", scope: !45, file: !3, line: 29, baseType: !34, size: 32, offset: 96)
191 !51 = !DIDerivedType(tag: DW_TAG_member, name: "elem11", scope: !41, file: !3, line: 35, baseType: !52, size: 64, offset: 128)
192 !52 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
193 !53 = !DIDerivedType(tag: DW_TAG_member, name: "elem12", scope: !41, file: !3, line: 36, baseType: !26, size: 64, offset: 192)
194 !54 = !DILocalVariable(name: "variable5", scope: !31, file: !3, line: 54, type: !34)
195 !55 = !DILocalVariable(name: "variable6", scope: !31, file: !3, line: 55, type: !56)
196 !56 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
197 !57 = !DILocation(line: 50, column: 34, scope: !31)
198 !58 = !DILocation(line: 51, column: 34, scope: !31)
204 exposesReturnsTwice: false
206 regBankSelected: false
208 tracksRegLiveness: true
211 - { reg: '$edi', virtual-reg: '' }
212 - { reg: '$esi', virtual-reg: '' }
214 isFrameAddressTaken: false
215 isReturnAddressTaken: false
225 hasOpaqueSPAdjustment: false
227 hasMustTailInVarArgFunc: false
231 - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default,
232 callee-saved-register: '$rbx', callee-saved-restored: true }
233 - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default,
234 callee-saved-register: '$r12', callee-saved-restored: true }
235 - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default,
236 callee-saved-register: '$r13', callee-saved-restored: true }
237 - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default,
238 callee-saved-register: '$r14', callee-saved-restored: true }
239 - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,
240 callee-saved-register: '$r15', callee-saved-restored: true }
241 - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,
242 callee-saved-register: '', callee-saved-restored: true }
244 - { id: 0, name: '', type: spill-slot, offset: -64, size: 4, alignment: 4,
245 stack-id: default, callee-saved-register: '', callee-saved-restored: true,
246 debug-info-variable: '', debug-info-expression: '',
247 debug-info-location: '' }
248 - { id: 1, name: '', type: spill-slot, offset: -60, size: 4, alignment: 4,
249 stack-id: default, callee-saved-register: '', callee-saved-restored: true,
250 debug-info-variable: '', debug-info-expression: '',
251 debug-info-location: '' }
255 successors: %bb.9(0x30000000), %bb.1(0x50000000)
256 liveins: $edi, $esi, $r15, $r14, $r13, $r12, $rbx
258 frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp
259 CFI_INSTRUCTION def_cfa_offset 16
260 CFI_INSTRUCTION offset $rbp, -16
261 $rbp = frame-setup MOV64rr $rsp
262 CFI_INSTRUCTION def_cfa_register $rbp
263 frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp
264 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
265 frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp
266 frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp
267 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
268 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp
269 CFI_INSTRUCTION offset $rbx, -56
270 CFI_INSTRUCTION offset $r12, -48
271 CFI_INSTRUCTION offset $r13, -40
272 CFI_INSTRUCTION offset $r14, -32
273 CFI_INSTRUCTION offset $r15, -24
274 DBG_VALUE $edi, $noreg, !36, !DIExpression(), debug-location !57
275 DBG_VALUE $esi, $noreg, !37, !DIExpression(), debug-location !58
277 DBG_VALUE $ebx, $noreg, !37, !DIExpression(), debug-location !58
279 DBG_VALUE $r15d, $noreg, !36, !DIExpression(), debug-location !57
280 renamable $r14 = MOV64ri -9223372036854775808
282 CALL64pcrel32 @func1, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
284 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags
285 renamable $r13 = AND64rr killed renamable $r13, renamable $r14, implicit-def $eflags
286 JCC_1 %bb.9, 4, implicit $eflags
289 successors: %bb.2(0x30000000), %bb.3(0x50000000)
290 liveins: $ebx, $r13, $r14, $r15d
292 ; The instruction below is inserted additionally in order to test part of the code.
293 $r12d = MOV32rr $r15d
294 MOV32mr $rbp, 1, $noreg, -48, $noreg, renamable $r15d :: (store 4 into %stack.0)
295 ; The instruction below is altered ($r15d -> $r12d) in order to test part of the code.
296 ; The original instruction "$edi = MOV32rr killed $r15d
297 $edi = MOV32rr killed $r12d
298 MOV32mr $rbp, 1, $noreg, -44, $noreg, renamable $ebx :: (store 4 into %stack.1)
299 $esi = MOV32rr killed $ebx
300 CALL64pcrel32 @func2, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
303 renamable $r15 = AND64ri8 killed renamable $r15, -123, implicit-def $eflags
304 JCC_1 %bb.2, 4, implicit $eflags
307 successors: %bb.9(0x30000000), %bb.4(0x50000000)
308 liveins: $r12, $r13, $r14, $r15
310 renamable $r14 = OR64rr killed renamable $r14, renamable $r12, implicit-def dead $eflags
311 $esi = XOR32rr undef $esi, undef $esi, implicit-def dead $eflags
312 dead $edx = MOV32ri 16, implicit-def $rdx
313 $rdi = MOV64rr killed $r14
314 CALL64pcrel32 @memset, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $esi, implicit $rdx, implicit-def $rsp, implicit-def $ssp, implicit-def dead $rax
316 CALL64pcrel32 @func4, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax
317 renamable $ecx = MOV32ri 1
318 TEST32rr killed renamable $eax, renamable $eax, implicit-def $eflags
319 JCC_1 %bb.9, 4, implicit $eflags
322 successors: %bb.8(0x30000000), %bb.5(0x50000000)
323 liveins: $r12, $r13, $r15
325 $esi = XOR32rr undef $esi, undef $esi, implicit-def dead $eflags
327 CALL64pcrel32 @func5, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $esi, implicit-def $rsp, implicit-def $ssp
328 renamable $rax = MOV64rm killed renamable $r13, 1, $noreg, 8, $noreg :: (load 8 from %ir.13)
329 TEST64rr renamable $rax, renamable $rax, implicit-def $eflags
330 JCC_1 %bb.8, 4, implicit $eflags
333 successors: %bb.6(0x30000000), %bb.7(0x50000000)
334 liveins: $rax, $r12, $r15
336 CMP32mi8 renamable $r15, 1, $noreg, 0, $noreg, 0, implicit-def $eflags :: (load 4 from %ir.tot_perf2, align 8)
337 JCC_1 %bb.7, 5, implicit $eflags
340 successors: %bb.8(0x30000000), %bb.7(0x50000000)
341 liveins: $rax, $r12, $r15
343 CMP32mi8 killed renamable $r15, 1, $noreg, 4, $noreg, 0, implicit-def $eflags :: (load 4 from %ir.tot_bw)
344 JCC_1 %bb.8, 4, implicit $eflags
347 successors: %bb.8(0x80000000)
350 renamable $rdx = MOV64rm killed renamable $rax, 1, $noreg, 8, $noreg :: (load 8 from %ir.20)
351 $rdi = MOV64rr killed $r12
352 $esi = MOV32rm $rbp, 1, $noreg, -44, $noreg :: (load 4 from %stack.1)
353 CALL64pcrel32 @func6, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $esi, implicit $rdx, implicit-def $rsp, implicit-def $ssp
356 successors: %bb.9(0x80000000)
358 renamable $ecx = MOV32ri 1
362 successors: %bb.9(0x80000000)
365 renamable $edi = MOV32rm renamable $r13, 1, $noreg, 0, $noreg :: (load 4 from %ir.variableLocal11, align 8)
366 renamable $esi = MOVZX32rm8 killed renamable $r13, 1, $noreg, 4, $noreg :: (load 1 from %ir.variableLocal2, align 4)
367 renamable $ecx = MOV32ri @.str, implicit-def $rcx
368 renamable $rcx = OR64ri32 killed renamable $rcx, -92238, implicit-def dead $eflags
370 $r8d = MOV32rm $rbp, 1, $noreg, -48, $noreg :: (load 4 from %stack.0)
371 CALL64pcrel32 @func3, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit $edx, implicit $rcx, implicit $r8d, implicit-def $rsp, implicit-def $ssp
372 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags
377 $eax = MOV32rr killed $ecx
378 $rsp = ADD64ri8 $rsp, 8, implicit-def dead $eflags
379 $rbx = POP64r implicit-def $rsp, implicit $rsp
380 $r12 = POP64r implicit-def $rsp, implicit $rsp
381 $r13 = POP64r implicit-def $rsp, implicit $rsp
382 $r14 = POP64r implicit-def $rsp, implicit $rsp
383 $r15 = POP64r implicit-def $rsp, implicit $rsp
384 $rbp = POP64r implicit-def $rsp, implicit $rsp