Index: lib/CodeGen/LiveDebugValues.cpp =================================================================== --- lib/CodeGen/LiveDebugValues.cpp +++ lib/CodeGen/LiveDebugValues.cpp @@ -431,9 +431,26 @@ // has its kill flag set. Return false if we don't find such a register. Reg = 0; for (const MachineOperand &MO : MI.operands()) { - if (MO.isReg() && MO.isUse() && MO.isKill()) { - Reg = MO.getReg(); - break; + if (MO.isReg() && MO.isUse()) { + if(MO.isKill()) { + Reg = MO.getReg(); + break; + } + else { + // Check wether next instruction kills the spilled register. + MachineBasicBlock::const_iterator MII = &MI; + MII++; + if (MI.getParent()->instr_end() == MII) + continue; + for (const MachineOperand &MONext : MII->operands()) + if (MONext.isReg() && MONext.isKill()) { + unsigned RegNext = MONext.getReg(); + if(RegNext == MO.getReg()){ + Reg = RegNext; + break; + } + } + } } } return Reg != 0; Index: test/DebugInfo/X86/kill-after-spill.ll =================================================================== --- /dev/null +++ test/DebugInfo/X86/kill-after-spill.ll @@ -0,0 +1,214 @@ +; RUN: llc < %s | FileCheck %s +; +; This test is used to acknowledge situation when spill register is killed +; in istruction after the spill occurs + +; CHECK: # %bb.1 +; CHECK-NEXT: #DEBUG_VALUE: foo:variable2 <- %r15d +; CHECK-NEXT: #DEBUG_VALUE: foo:variable1 <- %ebx +; CHECK-NEXT: movl %r15d, -48(%rbp) # 4-byte Spill +; CHECK-NEXT: #DEBUG_VALUE: foo:variable2 <- [DW_OP_constu 48, DW_OP_minus] [%rbp+0] +; CHECK-NEXT: movl %r15d, %edi +; CHECK-NEXT: movl %ebx, -44(%rbp) # 4-byte Spill +; CHECK-NEXT: #DEBUG_VALUE: foo:variable1 <- [DW_OP_constu 44, DW_OP_minus] [%rbp+0] +; CHECK-NEXT: movl %ebx, %esi + +; ModuleID = 'inlineSpillerTest.c' +source_filename = "inlineSpillerTest.c" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux" + +%struct.firstStruct = type { i32, i8, %struct.secondStruct* } +%struct.secondStruct = type { i32, i8, i8* } +%struct.thirdStruct = type { %struct.fourthStruct, i32*, i8* } +%struct.fourthStruct = type { i32, i32, i32, i32 } + +@.str = private unnamed_addr constant [7 x i8] c"Error:\00", align 1 +@firstStruct = common local_unnamed_addr global %struct.firstStruct zeroinitializer, align 8, !dbg !0 + +; Function Attrs: nounwind uwtable +define i32 @foo(i32 %variable2, i32 %variable1) local_unnamed_addr #0 !dbg !31 { +entry: + tail call void @llvm.dbg.value(metadata i32 %variable2, i64 0, metadata !36, metadata !57), !dbg !58 + tail call void @llvm.dbg.value(metadata i32 %variable1, i64 0, metadata !37, metadata !57), !dbg !59 + %call = tail call %struct.firstStruct* @func1(i32 %variable1) + %0 = ptrtoint %struct.firstStruct* %call to i64 + %1 = and i64 %0, -9223372036854775808 + %2 = inttoptr i64 %1 to %struct.firstStruct* + %tobool = icmp eq i64 %1, 0 + br i1 %tobool, label %cleanup, label %if.end + +if.end: ; preds = %entry + %call1 = tail call %struct.thirdStruct* @func2(i32 %variable2, i32 %variable1) + %3 = ptrtoint %struct.thirdStruct* %call1 to i64 + %4 = and i64 %3, -9223372036854775808 + %tobool2 = icmp eq i64 %4, 0 + br i1 %tobool2, label %if.then3, label %if.end4 + +if.then3: ; preds = %if.end + %variableLocal1 = getelementptr inbounds %struct.firstStruct, %struct.firstStruct* %2, i64 0, i32 0 + %5 = load i32, i32* %variableLocal1, align 8 + %6 = tail call i32 @llvm.bswap.i32(i32 %5) + %variableLocal2 = getelementptr inbounds %struct.firstStruct, %struct.firstStruct* %2, i64 0, i32 1 + %7 = load i8, i8* %variableLocal2, align 4 + 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 -9223372036854775808) to i8*), i32 %variable2) + br label %cleanup + +if.end4: ; preds = %if.end + %8 = inttoptr i64 %4 to %struct.thirdStruct* + %9 = or i64 %3, -9223372036854775808 + %10 = inttoptr i64 %9 to i8* + %11 = inttoptr i64 %4 to i8* + %12 = tail call i64 @llvm.objectsize.i64.p0i8(i8* %11, i1 false) + %sext.i = shl i64 %12, 32 + %conv1.i = ashr exact i64 %sext.i, 32 + switch i64 %conv1.i, label %cond.true.i [ + i64 -1, label %cond.false.i + i64 0, label %cond.false.i + ] + +cond.true.i: ; preds = %if.end4 + %call.i = tail call i8* @__memset_to_buf(i64 %conv1.i, i8* %10, i32 0, i64 16) + br label %private.exit + +cond.false.i: ; preds = %if.end4, %if.end4 + %call5.i = tail call i8* @memset(i8* %10, i32 0, i64 16) + br label %private.exit + +private.exit: ; preds = %cond.true.i, %cond.false.i + %call6 = tail call i32 @func4(%struct.thirdStruct* %call1) + %tobool7 = icmp eq i32 %call6, 0 + br i1 %tobool7, label %cleanup, label %if.then8 + +if.then8: ; preds = %private.exit + tail call void @func5(%struct.thirdStruct* %call1, i32 0) + %rc_db = getelementptr inbounds %struct.firstStruct, %struct.firstStruct* %2, i64 0, i32 2 + %13 = bitcast %struct.secondStruct** %rc_db to i64* + %14 = load i64, i64* %13, align 8 + %15 = and i64 %14, -129 + %tobool9 = icmp eq i64 %15, 0 + br i1 %tobool9, label %cleanup, label %land.lhs.true + +land.lhs.true: ; preds = %if.then8 + %tot_perf = getelementptr inbounds %struct.thirdStruct, %struct.thirdStruct* %8, i64 0, i32 0, i32 0 + %16 = load i32, i32* %tot_perf, align 8 + %tobool11 = icmp eq i32 %16, 0 + br i1 %tobool11, label %lor.lhs.false, label %if.then14 + +lor.lhs.false: ; preds = %land.lhs.true + %tot_bw = getelementptr inbounds %struct.thirdStruct, %struct.thirdStruct* %8, i64 0, i32 0, i32 1 + %17 = load i32, i32* %tot_bw, align 4 + %tobool13 = icmp eq i32 %17, 0 + br i1 %tobool13, label %cleanup, label %if.then14 + +if.then14: ; preds = %lor.lhs.false, %land.lhs.true + %18 = tail call i64 @llvm.bswap.i64(i64 %15) + %19 = inttoptr i64 %18 to %struct.secondStruct* + %mc_origin = getelementptr inbounds %struct.secondStruct, %struct.secondStruct* %19, i64 0, i32 2 + %20 = bitcast i8** %mc_origin to i64* + %21 = load i64, i64* %20, align 8 + %22 = tail call i64 @llvm.bswap.i64(i64 %21) + %23 = inttoptr i64 %22 to i8* + tail call void @func6(%struct.thirdStruct* %call1, i32 %variable1, i8* %23) + br label %cleanup + +cleanup: ; preds = %if.then14, %private.exit, %if.then8, %lor.lhs.false, %entry, %if.then3 + %retval.0 = phi i32 [ 0, %if.then3 ], [ 0, %entry ], [ 1, %lor.lhs.false ], [ 1, %if.then8 ], [ 1, %private.exit ], [ 1, %if.then14 ] + ret i32 %retval.0 +} + +declare %struct.firstStruct* @func1(i32) local_unnamed_addr + +declare %struct.thirdStruct* @func2(i32, i32) local_unnamed_addr + +declare void @func3(i32, i8 zeroext, i8 zeroext, i8*, i32) local_unnamed_addr + +declare i32 @func4(%struct.thirdStruct*) local_unnamed_addr + +declare void @func5(%struct.thirdStruct*, i32) local_unnamed_addr + +declare void @func6(%struct.thirdStruct*, i32, i8*) local_unnamed_addr + +; Function Attrs: nounwind readnone +declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) + +declare i8* @__memset_to_buf(i64, i8*, i32, i64) local_unnamed_addr + +declare i8* @memset(i8*, i32, i64) local_unnamed_addr + +; Function Attrs: nounwind readnone +declare i64 @llvm.bswap.i64(i64) + +; Function Attrs: nounwind readnone +declare i32 @llvm.bswap.i32(i32) + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) + +attributes #0 = { nounwind uwtable "no-frame-pointer-elim-non-leaf" } + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!27, !28, !29} +!llvm.ident = !{!30} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "firstStruct", scope: !2, file: !3, line: 23, type: !11, isLocal: false, isDefinition: true) +!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) +!3 = !DIFile(filename: "inlineSpillerTest.c", directory: "/") +!4 = !{} +!5 = !{!6, !7} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !8, line: 98, baseType: !9) +!8 = !DIFile(filename: "/tmp.h", directory: "/tmp") +!9 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned) +!10 = !{!0} +!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "firstStruct", file: !3, line: 18, size: 128, elements: !12) +!12 = !{!13, !16, !19} +!13 = !DIDerivedType(tag: DW_TAG_member, name: "elem1", scope: !11, file: !3, line: 20, baseType: !14, size: 32) +!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32", file: !3, line: 4, baseType: !15) +!15 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "elem2", scope: !11, file: !3, line: 21, baseType: !17, size: 8, offset: 32) +!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8", file: !3, line: 5, baseType: !18) +!18 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char) +!19 = !DIDerivedType(tag: DW_TAG_member, name: "elem3", scope: !11, file: !3, line: 22, baseType: !20, size: 64, offset: 64) +!20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64) +!21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "secondStruct", file: !3, line: 11, size: 128, elements: !22) +!22 = !{!23, !24, !25} +!23 = !DIDerivedType(tag: DW_TAG_member, name: "structMember", scope: !21, file: !3, line: 13, baseType: !14, size: 32) +!24 = !DIDerivedType(tag: DW_TAG_member, name: "elem4", scope: !21, file: !3, line: 14, baseType: !17, size: 8, offset: 32) +!25 = !DIDerivedType(tag: DW_TAG_member, name: "elem5", scope: !21, file: !3, line: 15, baseType: !26, size: 64, offset: 64) +!26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) +!27 = !{i32 2, !"Dwarf Version", i32 4} +!28 = !{i32 2, !"Debug Info Version", i32 3} +!29 = !{i32 1, !"PIC Level", i32 2} +!30 = !{!"clang version 4.0.0 "} +!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, variables: !35) +!32 = !DISubroutineType(types: !33) +!33 = !{!34, !14, !14} +!34 = !DIDerivedType(tag: DW_TAG_typedef, name: "boolean", file: !3, line: 6, baseType: !6) +!35 = !{!36, !37, !38, !54, !55} +!36 = !DILocalVariable(name: "variable2", arg: 1, scope: !31, file: !3, line: 50, type: !14) +!37 = !DILocalVariable(name: "variable1", arg: 2, scope: !31, file: !3, line: 51, type: !14) +!38 = !DILocalVariable(name: "localVariable5", scope: !31, file: !3, line: 53, type: !39) +!39 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !40, size: 64) +!40 = !DIDerivedType(tag: DW_TAG_typedef, name: "thirdStruct_", file: !3, line: 37, baseType: !41) +!41 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "thirdStruct", file: !3, line: 32, size: 256, elements: !42) +!42 = !{!43, !51, !53} +!43 = !DIDerivedType(tag: DW_TAG_member, name: "elem6", scope: !41, file: !3, line: 34, baseType: !44, size: 128) +!44 = !DIDerivedType(tag: DW_TAG_typedef, name: "fourthStruct_", file: !3, line: 30, baseType: !45) +!45 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "fourthStruct", file: !3, line: 25, size: 128, elements: !46) +!46 = !{!47, !48, !49, !50} +!47 = !DIDerivedType(tag: DW_TAG_member, name: "elem7", scope: !45, file: !3, line: 26, baseType: !14, size: 32) +!48 = !DIDerivedType(tag: DW_TAG_member, name: "elem8", scope: !45, file: !3, line: 27, baseType: !14, size: 32, offset: 32) +!49 = !DIDerivedType(tag: DW_TAG_member, name: "elem9", scope: !45, file: !3, line: 28, baseType: !34, size: 32, offset: 64) +!50 = !DIDerivedType(tag: DW_TAG_member, name: "elem10", scope: !45, file: !3, line: 29, baseType: !34, size: 32, offset: 96) +!51 = !DIDerivedType(tag: DW_TAG_member, name: "elem11", scope: !41, file: !3, line: 35, baseType: !52, size: 64, offset: 128) +!52 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64) +!53 = !DIDerivedType(tag: DW_TAG_member, name: "elem12", scope: !41, file: !3, line: 36, baseType: !26, size: 64, offset: 192) +!54 = !DILocalVariable(name: "variable5", scope: !31, file: !3, line: 54, type: !34) +!55 = !DILocalVariable(name: "variable6", scope: !31, file: !3, line: 55, type: !56) +!56 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) +!57 = !DIExpression() +!58 = !DILocation(line: 50, column: 34, scope: !31) +!59 = !DILocation(line: 51, column: 34, scope: !31) +