390 lines · plain
1# RUN: llc -run-pass=livedebugvalues -o - %s -experimental-debug-variable-locations=false | FileCheck %s2#3# This test is used to acknowledge situation when spill register is killed4# in instruction after the spill occurs.5# Generated MIR is changed in order to test case when instruction after6# possible spill, say instruction B, kills register different than than7# the one that is used in possible spill, say instruction A. In that case8# the instruction A is not recognized as spill. Changed instructions are9# commented in MIR below.10#11# ...12# A - possible spill instruction with register R213# B - instruction that kills R314# ...15#16# CHECK: bb.1.if.end:17# CHECK: DBG_VALUE $rbp, 0, !37, !DIExpression(DW_OP_constu, 44, DW_OP_minus)18# CHECK-NOT: DBG_VALUE $rbp, 0, !36, !DIExpression(DW_OP_constu, 48, DW_OP_minus)19 20--- |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"25 26 %struct.firstStruct = type { i32, i8, ptr }27 %struct.secondStruct = type { i32, i8, ptr }28 %struct.thirdStruct = type { %struct.fourthStruct, ptr, ptr }29 %struct.fourthStruct = type { i32, i32, i32, i32 }30 31 @.str = private unnamed_addr constant [7 x i8] c"Error:\00", align 132 @firstStruct = common local_unnamed_addr global %struct.firstStruct zeroinitializer, align 8, !dbg !033 34 ; Function Attrs: nounwind uwtable35 define i32 @foo(i32 %variable2, i32 %variable1) local_unnamed_addr #0 !dbg !31 {36 entry:37 %const1 = bitcast i64 -9223372036854775808 to i6438 %0 = bitcast i64 %const1 to i6439 call void @llvm.dbg.value(metadata i32 %variable2, metadata !36, metadata !DIExpression()), !dbg !5740 call void @llvm.dbg.value(metadata i32 %variable1, metadata !37, metadata !DIExpression()), !dbg !5841 %call = tail call ptr @func1(i32 %variable1)42 %1 = ptrtoint ptr %call to i6443 %2 = and i64 %1, %044 %tobool = icmp eq i64 %2, 045 br i1 %tobool, label %cleanup, label %if.end46 47 if.end: ; preds = %entry48 %call1 = tail call ptr @func2(i32 %variable2, i32 %variable1)49 %3 = ptrtoint ptr %call1 to i6450 %4 = and i64 %3, -12351 %tobool2 = icmp eq i64 %4, 052 br i1 %tobool2, label %if.then3, label %private.exit53 54 if.then3: ; preds = %if.end55 %5 = inttoptr i64 %2 to ptr56 %variableLocal11 = bitcast ptr %5 to ptr57 %6 = load i32, ptr %variableLocal11, align 858 %variableLocal2 = getelementptr inbounds %struct.firstStruct, ptr %5, i64 0, i32 159 %7 = load i8, ptr %variableLocal2, align 460 %or = or i64 ptrtoint (ptr @.str to i64), -9223861 %ptr = inttoptr i64 %or to ptr62 tail call void @func3(i32 %6, i8 zeroext %7, i8 zeroext 5, ptr %ptr, i32 %variable2)63 br label %cleanup64 65 private.exit: ; preds = %if.end66 %8 = bitcast i64 %const1 to i6467 %9 = ptrtoint ptr %call1 to i6468 %10 = or i64 %9, %869 %11 = inttoptr i64 %10 to ptr70 %call5.i = tail call ptr @memset(ptr %11, i32 0, i64 16)71 %call6 = tail call i32 @func4(ptr %call1)72 %tobool7 = icmp eq i32 %call6, 073 br i1 %tobool7, label %cleanup, label %if.then874 75 if.then8: ; preds = %private.exit76 %12 = inttoptr i64 %2 to ptr77 tail call void @func5(ptr %call1, i32 0)78 %rc_db = getelementptr inbounds %struct.firstStruct, ptr %12, i64 0, i32 279 %13 = bitcast ptr %rc_db to ptr80 %14 = load i64, ptr %13, align 881 %tobool9 = icmp eq i64 %14, 082 br i1 %tobool9, label %cleanup, label %land.lhs.true83 84 land.lhs.true: ; preds = %if.then885 %15 = inttoptr i64 %4 to ptr86 %tot_perf2 = bitcast ptr %15 to ptr87 %16 = load i32, ptr %tot_perf2, align 888 %tobool11 = icmp eq i32 %16, 089 br i1 %tobool11, label %lor.lhs.false, label %if.then1490 91 lor.lhs.false: ; preds = %land.lhs.true92 %17 = inttoptr i64 %4 to ptr93 %tot_bw = getelementptr inbounds %struct.thirdStruct, ptr %17, i64 0, i32 0, i32 194 %18 = load i32, ptr %tot_bw, align 495 %tobool13 = icmp eq i32 %18, 096 br i1 %tobool13, label %cleanup, label %if.then1497 98 if.then14: ; preds = %lor.lhs.false, %land.lhs.true99 %19 = inttoptr i64 %14 to ptr100 %mc_origin = getelementptr inbounds %struct.secondStruct, ptr %19, i64 0, i32 2101 %20 = bitcast ptr %mc_origin to ptr102 %21 = load i64, ptr %20, align 8103 %22 = inttoptr i64 %21 to ptr104 tail call void @func6(ptr %call1, i32 %variable1, ptr %22)105 br label %cleanup106 107 cleanup: ; preds = %if.then14, %lor.lhs.false, %if.then8, %private.exit, %if.then3, %entry108 %retval.0 = phi i32 [ 0, %if.then3 ], [ 0, %entry ], [ 1, %lor.lhs.false ], [ 1, %if.then8 ], [ 1, %private.exit ], [ 1, %if.then14 ]109 ret i32 %retval.0110 }111 112 declare ptr @func1(i32) local_unnamed_addr113 114 declare ptr @func2(i32, i32) local_unnamed_addr115 116 declare void @func3(i32, i8 zeroext, i8 zeroext, ptr, i32) local_unnamed_addr117 118 declare i32 @func4(ptr) local_unnamed_addr119 120 declare void @func5(ptr, i32) local_unnamed_addr121 122 declare void @func6(ptr, i32, ptr) local_unnamed_addr123 124 declare ptr @__memset_to_buf(i64, ptr, i32, i64) local_unnamed_addr125 126 declare ptr @memset(ptr, i32, i64) local_unnamed_addr127 128 ; Function Attrs: nounwind readnone speculatable129 declare void @llvm.dbg.value(metadata, metadata, metadata) #1130 131 ; Function Attrs: nounwind132 declare void @llvm.stackprotector(ptr, ptr) #2133 134 attributes #0 = { nounwind uwtable "frame-pointer"="non-leaf" }135 attributes #1 = { nounwind readnone speculatable }136 attributes #2 = { nounwind }137 138 !llvm.dbg.cu = !{!2}139 !llvm.module.flags = !{!27, !28, !29}140 !llvm.ident = !{!30}141 142 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())143 !1 = distinct !DIGlobalVariable(name: "firstStruct", scope: !2, file: !3, line: 23, type: !11, isLocal: false, isDefinition: true)144 !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)145 !3 = !DIFile(filename: "inlineSpillerTest.c", directory: "/")146 !4 = !{}147 !5 = !{!6, !7}148 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)149 !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !8, line: 98, baseType: !9)150 !8 = !DIFile(filename: "/tmp.h", directory: "/tmp")151 !9 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)152 !10 = !{!0}153 !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "firstStruct", file: !3, line: 18, size: 128, elements: !12)154 !12 = !{!13, !16, !19}155 !13 = !DIDerivedType(tag: DW_TAG_member, name: "elem1", scope: !11, file: !3, line: 20, baseType: !14, size: 32)156 !14 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32", file: !3, line: 4, baseType: !15)157 !15 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)158 !16 = !DIDerivedType(tag: DW_TAG_member, name: "elem2", scope: !11, file: !3, line: 21, baseType: !17, size: 8, offset: 32)159 !17 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8", file: !3, line: 5, baseType: !18)160 !18 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)161 !19 = !DIDerivedType(tag: DW_TAG_member, name: "elem3", scope: !11, file: !3, line: 22, baseType: !20, size: 64, offset: 64)162 !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)163 !21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "secondStruct", file: !3, line: 11, size: 128, elements: !22)164 !22 = !{!23, !24, !25}165 !23 = !DIDerivedType(tag: DW_TAG_member, name: "structMember", scope: !21, file: !3, line: 13, baseType: !14, size: 32)166 !24 = !DIDerivedType(tag: DW_TAG_member, name: "elem4", scope: !21, file: !3, line: 14, baseType: !17, size: 8, offset: 32)167 !25 = !DIDerivedType(tag: DW_TAG_member, name: "elem5", scope: !21, file: !3, line: 15, baseType: !26, size: 64, offset: 64)168 !26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)169 !27 = !{i32 2, !"Dwarf Version", i32 4}170 !28 = !{i32 2, !"Debug Info Version", i32 3}171 !29 = !{i32 7, !"PIC Level", i32 2}172 !30 = !{!"clang version 4.0.0 "}173 !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)174 !32 = !DISubroutineType(types: !33)175 !33 = !{!34, !14, !14}176 !34 = !DIDerivedType(tag: DW_TAG_typedef, name: "boolean", file: !3, line: 6, baseType: !6)177 !35 = !{!36, !37, !38, !54, !55}178 !36 = !DILocalVariable(name: "variable2", arg: 1, scope: !31, file: !3, line: 50, type: !14)179 !37 = !DILocalVariable(name: "variable1", arg: 2, scope: !31, file: !3, line: 51, type: !14)180 !38 = !DILocalVariable(name: "localVariable5", scope: !31, file: !3, line: 53, type: !39)181 !39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !40, size: 64)182 !40 = !DIDerivedType(tag: DW_TAG_typedef, name: "thirdStruct_", file: !3, line: 37, baseType: !41)183 !41 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "thirdStruct", file: !3, line: 32, size: 256, elements: !42)184 !42 = !{!43, !51, !53}185 !43 = !DIDerivedType(tag: DW_TAG_member, name: "elem6", scope: !41, file: !3, line: 34, baseType: !44, size: 128)186 !44 = !DIDerivedType(tag: DW_TAG_typedef, name: "fourthStruct_", file: !3, line: 30, baseType: !45)187 !45 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "fourthStruct", file: !3, line: 25, size: 128, elements: !46)188 !46 = !{!47, !48, !49, !50}189 !47 = !DIDerivedType(tag: DW_TAG_member, name: "elem7", scope: !45, file: !3, line: 26, baseType: !14, size: 32)190 !48 = !DIDerivedType(tag: DW_TAG_member, name: "elem8", scope: !45, file: !3, line: 27, baseType: !14, size: 32, offset: 32)191 !49 = !DIDerivedType(tag: DW_TAG_member, name: "elem9", scope: !45, file: !3, line: 28, baseType: !34, size: 32, offset: 64)192 !50 = !DIDerivedType(tag: DW_TAG_member, name: "elem10", scope: !45, file: !3, line: 29, baseType: !34, size: 32, offset: 96)193 !51 = !DIDerivedType(tag: DW_TAG_member, name: "elem11", scope: !41, file: !3, line: 35, baseType: !52, size: 64, offset: 128)194 !52 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)195 !53 = !DIDerivedType(tag: DW_TAG_member, name: "elem12", scope: !41, file: !3, line: 36, baseType: !26, size: 64, offset: 192)196 !54 = !DILocalVariable(name: "variable5", scope: !31, file: !3, line: 54, type: !34)197 !55 = !DILocalVariable(name: "variable6", scope: !31, file: !3, line: 55, type: !56)198 !56 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)199 !57 = !DILocation(line: 50, column: 34, scope: !31)200 !58 = !DILocation(line: 51, column: 34, scope: !31)201 202...203---204name: foo205alignment: 16206exposesReturnsTwice: false207legalized: false208regBankSelected: false209selected: false210tracksRegLiveness: true211registers:212liveins:213 - { reg: '$edi', virtual-reg: '' }214 - { reg: '$esi', virtual-reg: '' }215frameInfo:216 isFrameAddressTaken: false217 isReturnAddressTaken: false218 hasStackMap: false219 hasPatchPoint: false220 stackSize: 56221 offsetAdjustment: -8222 maxAlignment: 4223 adjustsStack: true224 hasCalls: true225 stackProtector: ''226 maxCallFrameSize: 0227 hasOpaqueSPAdjustment: false228 hasVAStart: false229 hasMustTailInVarArgFunc: false230 savePoint: []231 restorePoint: []232fixedStack:233 - { id: 0, type: spill-slot, offset: -56, size: 8, alignment: 8, stack-id: default,234 callee-saved-register: '$rbx', callee-saved-restored: true }235 - { id: 1, type: spill-slot, offset: -48, size: 8, alignment: 16, stack-id: default,236 callee-saved-register: '$r12', callee-saved-restored: true }237 - { id: 2, type: spill-slot, offset: -40, size: 8, alignment: 8, stack-id: default,238 callee-saved-register: '$r13', callee-saved-restored: true }239 - { id: 3, type: spill-slot, offset: -32, size: 8, alignment: 16, stack-id: default,240 callee-saved-register: '$r14', callee-saved-restored: true }241 - { id: 4, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default,242 callee-saved-register: '$r15', callee-saved-restored: true }243 - { id: 5, type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default,244 callee-saved-register: '', callee-saved-restored: true }245stack:246 - { id: 0, name: '', type: spill-slot, offset: -64, size: 4, alignment: 4,247 stack-id: default, callee-saved-register: '', callee-saved-restored: true,248 debug-info-variable: '', debug-info-expression: '',249 debug-info-location: '' }250 - { id: 1, name: '', type: spill-slot, offset: -60, size: 4, alignment: 4,251 stack-id: default, callee-saved-register: '', callee-saved-restored: true,252 debug-info-variable: '', debug-info-expression: '',253 debug-info-location: '' }254constants:255body: |256 bb.0.entry:257 successors: %bb.9(0x30000000), %bb.1(0x50000000)258 liveins: $edi, $esi, $r15, $r14, $r13, $r12, $rbx259 260 frame-setup PUSH64r killed $rbp, implicit-def $rsp, implicit $rsp261 CFI_INSTRUCTION def_cfa_offset 16262 CFI_INSTRUCTION offset $rbp, -16263 $rbp = frame-setup MOV64rr $rsp264 CFI_INSTRUCTION def_cfa_register $rbp265 frame-setup PUSH64r killed $r15, implicit-def $rsp, implicit $rsp266 frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp267 frame-setup PUSH64r killed $r13, implicit-def $rsp, implicit $rsp268 frame-setup PUSH64r killed $r12, implicit-def $rsp, implicit $rsp269 frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp270 frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp271 CFI_INSTRUCTION offset $rbx, -56272 CFI_INSTRUCTION offset $r12, -48273 CFI_INSTRUCTION offset $r13, -40274 CFI_INSTRUCTION offset $r14, -32275 CFI_INSTRUCTION offset $r15, -24276 DBG_VALUE $edi, $noreg, !36, !DIExpression(), debug-location !57277 DBG_VALUE $esi, $noreg, !37, !DIExpression(), debug-location !58278 $ebx = MOV32rr $esi279 DBG_VALUE $ebx, $noreg, !37, !DIExpression(), debug-location !58280 $r15d = MOV32rr $edi281 DBG_VALUE $r15d, $noreg, !36, !DIExpression(), debug-location !57282 renamable $r14 = MOV64ri -9223372036854775808283 $edi = MOV32rr $ebx284 CALL64pcrel32 @func1, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax285 $r13 = MOV64rr $rax286 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags287 renamable $r13 = AND64rr killed renamable $r13, renamable $r14, implicit-def $eflags288 JCC_1 %bb.9, 4, implicit $eflags, debug-location !57289 290 bb.1.if.end:291 successors: %bb.2(0x30000000), %bb.3(0x50000000)292 liveins: $ebx, $r13, $r14, $r15d293 294 ; The instruction below is inserted additionally in order to test part of the code.295 $r12d = MOV32rr $r15d296 MOV32mr $rbp, 1, $noreg, -48, $noreg, renamable $r15d :: (store (s32) into %stack.0)297 ; The instruction below is altered ($r15d -> $r12d) in order to test part of the code.298 ; The original instruction "$edi = MOV32rr killed $r15d299 $edi = MOV32rr killed $r12d300 MOV32mr $rbp, 1, $noreg, -44, $noreg, renamable $ebx :: (store (s32) into %stack.1)301 $esi = MOV32rr killed $ebx302 CALL64pcrel32 @func2, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax303 $r12 = MOV64rr $rax304 $r15 = MOV64rr $r12305 renamable $r15 = AND64ri8 killed renamable $r15, -123, implicit-def $eflags306 JCC_1 %bb.2, 4, implicit $eflags, debug-location !57307 308 bb.3.private.exit:309 successors: %bb.9(0x30000000), %bb.4(0x50000000)310 liveins: $r12, $r13, $r14, $r15311 312 renamable $r14 = OR64rr killed renamable $r14, renamable $r12, implicit-def dead $eflags313 $esi = XOR32rr undef $esi, undef $esi, implicit-def dead $eflags314 dead $edx = MOV32ri 16, implicit-def $rdx315 $rdi = MOV64rr killed $r14316 CALL64pcrel32 @memset, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $esi, implicit $rdx, implicit-def $rsp, implicit-def $ssp, implicit-def dead $rax317 $rdi = MOV64rr $r12318 CALL64pcrel32 @func4, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax319 renamable $ecx = MOV32ri 1320 TEST32rr killed renamable $eax, renamable $eax, implicit-def $eflags321 JCC_1 %bb.9, 4, implicit $eflags, debug-location !57322 323 bb.4.if.then8:324 successors: %bb.8(0x30000000), %bb.5(0x50000000)325 liveins: $r12, $r13, $r15326 327 $esi = XOR32rr undef $esi, undef $esi, implicit-def dead $eflags328 $rdi = MOV64rr $r12329 CALL64pcrel32 @func5, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $esi, implicit-def $rsp, implicit-def $ssp330 renamable $rax = MOV64rm killed renamable $r13, 1, $noreg, 8, $noreg :: (load (s64) from %ir.13)331 TEST64rr renamable $rax, renamable $rax, implicit-def $eflags332 JCC_1 %bb.8, 4, implicit $eflags, debug-location !57333 334 bb.5.land.lhs.true:335 successors: %bb.6(0x30000000), %bb.7(0x50000000)336 liveins: $rax, $r12, $r15337 338 CMP32mi renamable $r15, 1, $noreg, 0, $noreg, 0, implicit-def $eflags :: (load (s32) from %ir.tot_perf2, align 8)339 JCC_1 %bb.7, 5, implicit $eflags, debug-location !57340 341 bb.6.lor.lhs.false:342 successors: %bb.8(0x30000000), %bb.7(0x50000000)343 liveins: $rax, $r12, $r15344 345 CMP32mi killed renamable $r15, 1, $noreg, 4, $noreg, 0, implicit-def $eflags :: (load (s32) from %ir.tot_bw)346 JCC_1 %bb.8, 4, implicit $eflags, debug-location !57347 348 bb.7.if.then14:349 successors: %bb.8(0x80000000)350 liveins: $rax, $r12351 352 renamable $rdx = MOV64rm killed renamable $rax, 1, $noreg, 8, $noreg :: (load (s64) from %ir.20)353 $rdi = MOV64rr killed $r12354 $esi = MOV32rm $rbp, 1, $noreg, -44, $noreg :: (load (s32) from %stack.1)355 CALL64pcrel32 @func6, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $esi, implicit $rdx, implicit-def $rsp, implicit-def $ssp, debug-location !57356 357 bb.8.cleanup:358 successors: %bb.9(0x80000000)359 360 renamable $ecx = MOV32ri 1361 JMP_1 %bb.9, debug-location !57362 363 bb.2.if.then3:364 successors: %bb.9(0x80000000)365 liveins: $r13366 367 renamable $edi = MOV32rm renamable $r13, 1, $noreg, 0, $noreg :: (load (s32) from %ir.variableLocal11, align 8)368 renamable $esi = MOVZX32rm8 killed renamable $r13, 1, $noreg, 4, $noreg :: (load (s8) from %ir.variableLocal2, align 4)369 renamable $ecx = MOV32ri @.str, implicit-def $rcx370 renamable $rcx = OR64ri32 killed renamable $rcx, -92238, implicit-def dead $eflags371 $edx = MOV32ri 5372 $r8d = MOV32rm $rbp, 1, $noreg, -48, $noreg :: (load (s32) from %stack.0)373 CALL64pcrel32 @func3, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit $esi, implicit $edx, implicit $rcx, implicit $r8d, implicit-def $rsp, implicit-def $ssp374 renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags, debug-location !57375 376 bb.9.cleanup:377 liveins: $ecx378 379 $eax = MOV32rr killed $ecx380 $rsp = ADD64ri32 $rsp, 8, implicit-def dead $eflags381 $rbx = POP64r implicit-def $rsp, implicit $rsp382 $r12 = POP64r implicit-def $rsp, implicit $rsp383 $r13 = POP64r implicit-def $rsp, implicit $rsp384 $r14 = POP64r implicit-def $rsp, implicit $rsp385 $r15 = POP64r implicit-def $rsp, implicit $rsp386 $rbp = POP64r implicit-def $rsp, implicit $rsp387 RET64 $eax, debug-location !57388 389...390