Index: lib/CodeGen/MachineLICM.cpp =================================================================== --- lib/CodeGen/MachineLICM.cpp +++ lib/CodeGen/MachineLICM.cpp @@ -1336,6 +1336,8 @@ // Otherwise, splice the instruction to the preheader. Preheader->splice(Preheader->getFirstTerminator(),MI->getParent(),MI); + MI->setDebugLoc(DebugLoc()); + // Update register pressure for BBs from header to this block. UpdateBackTraceRegPressure(MI); Index: test/CodeGen/ARM/debug-info-branch-folding.ll =================================================================== --- test/CodeGen/ARM/debug-info-branch-folding.ll +++ test/CodeGen/ARM/debug-info-branch-folding.ll @@ -3,11 +3,12 @@ target triple = "thumbv7-apple-macosx10.6.7" ;CHECK: vadd.f32 q4, q8, q8 -;CHECK-NEXT: Ltmp1 -;CHECK-NEXT: LBB0_1 +;CHECK: LBB0_1: +;CHECK-NOT: beq LBB0_1 -;CHECK:@DEBUG_VALUE: x <- %Q4{{$}} -;CHECK-NEXT:@DEBUG_VALUE: y <- %Q4{{$}} +;CHECK: @DEBUG_VALUE: x <- %Q4{{$}} +;CHECK-NEXT: @DEBUG_VALUE: y <- %Q4{{$}} +;CHECK: beq LBB0_1 @.str = external constant [13 x i8] Index: test/DebugInfo/MIR/X86/mlicm-hoist.mir =================================================================== --- test/DebugInfo/MIR/X86/mlicm-hoist.mir +++ test/DebugInfo/MIR/X86/mlicm-hoist.mir @@ -0,0 +1,203 @@ +--- | + ; RUN: llc -run-pass=machinelicm -o - %s | FileCheck %s + ; Line numbers should not be retained when loop invariant instructions are hoisted. + ; Doing so causes poor stepping bevavior. + ; + ; Created from: + ; int x; + ; int y; + ; + ; bool Process(const unsigned int *pData) + ; { + ; int compare = 0; + ; while (1) + ; { + ; int op = *pData++; + ; switch (op) + ; { + ; case 1: + ; x = *pData++; + ; y = *pData++; + ; break; + ; } + ; } + ; return false; + ; } + ; + ; with clang -emit-llvm -S -O2 -g -o t.ll + ; llc -relocation-model=pic -stop-after=machine-combine -O2 t.ll -o t.mir + ; + ; We check that when the machine loop invariant pass hoists instructions + ; out of a loop the debug information is not retained. + ; + ; CHECK-LABEL: bb.0.entry: + ; CHECK: MOV64rm %rip, 1, _, target-flags(x86-gotpcrel) @x, _ :: (load 8 from got) + ; CHECK: MOV64rm %rip, 1, _, target-flags(x86-gotpcrel) @y, _ :: (load 8 from got) + ; CHECK-LABEL: bb.1.while.cond: + ; + ; ModuleID = 'tx.ll' + source_filename = "t.cpp" + target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + target triple = "x86_64-unknown-linux-gnu" + + @x = local_unnamed_addr global i32 0, align 4, !dbg !0 + @y = local_unnamed_addr global i32 0, align 4, !dbg !5 + + ; Function Attrs: noreturn nounwind uwtable + define zeroext i1 @_Z7ProcessPKj(i32* nocapture readonly %pData) local_unnamed_addr #0 !dbg !10 { + entry: + tail call void @llvm.dbg.value(metadata i32* %pData, i64 0, metadata !18, metadata !22), !dbg !23 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !19, metadata !22), !dbg !24 + br label %while.cond, !dbg !25 + + while.cond: ; preds = %while.cond, %sw.bb, %entry + %pData.addr.0 = phi i32* [ %pData, %entry ], [ %incdec.ptr2, %sw.bb ], [ %incdec.ptr, %while.cond ] + tail call void @llvm.dbg.value(metadata i32* %pData.addr.0, i64 0, metadata !18, metadata !22), !dbg !23 + %incdec.ptr = getelementptr inbounds i32, i32* %pData.addr.0, i64 1, !dbg !26 + tail call void @llvm.dbg.value(metadata i32* %incdec.ptr, i64 0, metadata !18, metadata !22), !dbg !23 + %0 = load i32, i32* %pData.addr.0, align 4, !dbg !27, !tbaa !28 + tail call void @llvm.dbg.value(metadata i32 %0, i64 0, metadata !20, metadata !22), !dbg !32 + %cond = icmp eq i32 %0, 1, !dbg !33 + br i1 %cond, label %sw.bb, label %while.cond, !dbg !33 + + sw.bb: ; preds = %while.cond + %incdec.ptr1 = getelementptr inbounds i32, i32* %pData.addr.0, i64 2, !dbg !34 + tail call void @llvm.dbg.value(metadata i32* %incdec.ptr1, i64 0, metadata !18, metadata !22), !dbg !23 + %sunkaddr = ptrtoint i32* %pData.addr.0 to i64, !dbg !36 + %sunkaddr1 = add i64 %sunkaddr, 4, !dbg !36 + %sunkaddr2 = inttoptr i64 %sunkaddr1 to i32*, !dbg !36 + %1 = load i32, i32* %sunkaddr2, align 4, !dbg !36, !tbaa !28 + store i32 %1, i32* @x, align 4, !dbg !37, !tbaa !28 + %incdec.ptr2 = getelementptr inbounds i32, i32* %pData.addr.0, i64 3, !dbg !38 + tail call void @llvm.dbg.value(metadata i32* %incdec.ptr2, i64 0, metadata !18, metadata !22), !dbg !23 + %2 = load i32, i32* %incdec.ptr1, align 4, !dbg !39, !tbaa !28 + store i32 %2, i32* @y, align 4, !dbg !40, !tbaa !28 + br label %while.cond, !dbg !41 + } + + ; Function Attrs: nounwind readnone + declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + + attributes #0 = { noreturn nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + attributes #1 = { nounwind readnone } + + !llvm.dbg.cu = !{!1} + !llvm.module.flags = !{!7, !8} + !llvm.ident = !{!9} + + !0 = distinct !DIGlobalVariable(name: "x", scope: !1, file: !2, line: 1, type: !6, isLocal: false, isDefinition: true) + !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 4.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4) + !2 = !DIFile(filename: "t.cpp", directory: "/home/test") + !3 = !{} + !4 = !{!0, !5} + !5 = distinct !DIGlobalVariable(name: "y", scope: !1, file: !2, line: 2, type: !6, isLocal: false, isDefinition: true) + !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) + !7 = !{i32 2, !"Dwarf Version", i32 4} + !8 = !{i32 2, !"Debug Info Version", i32 3} + !9 = !{!"clang version 4.0.0 "} + !10 = distinct !DISubprogram(name: "Process", linkageName: "_Z7ProcessPKj", scope: !2, file: !2, line: 4, type: !11, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !1, variables: !17) + !11 = !DISubroutineType(types: !12) + !12 = !{!13, !14} + !13 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) + !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64) + !15 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !16) + !16 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) + !17 = !{!18, !19, !20} + !18 = !DILocalVariable(name: "pData", arg: 1, scope: !10, file: !2, line: 4, type: !14) + !19 = !DILocalVariable(name: "compare", scope: !10, file: !2, line: 6, type: !6) + !20 = !DILocalVariable(name: "op", scope: !21, file: !2, line: 9, type: !6) + !21 = distinct !DILexicalBlock(scope: !10, file: !2, line: 8, column: 3) + !22 = !DIExpression() + !23 = !DILocation(line: 4, column: 34, scope: !10) + !24 = !DILocation(line: 6, column: 7, scope: !10) + !25 = !DILocation(line: 7, column: 3, scope: !10) + !26 = !DILocation(line: 9, column: 20, scope: !21) + !27 = !DILocation(line: 9, column: 14, scope: !21) + !28 = !{!29, !29, i64 0} + !29 = !{!"int", !30, i64 0} + !30 = !{!"omnipotent char", !31, i64 0} + !31 = !{!"Simple C++ TBAA"} + !32 = !DILocation(line: 9, column: 9, scope: !21) + !33 = !DILocation(line: 10, column: 5, scope: !21) + !34 = !DILocation(line: 13, column: 17, scope: !35) + !35 = distinct !DILexicalBlock(scope: !21, file: !2, line: 11, column: 5) + !36 = !DILocation(line: 13, column: 11, scope: !35) + !37 = !DILocation(line: 13, column: 9, scope: !35) + !38 = !DILocation(line: 14, column: 17, scope: !35) + !39 = !DILocation(line: 14, column: 11, scope: !35) + !40 = !DILocation(line: 14, column: 9, scope: !35) + !41 = !DILocation(line: 15, column: 7, scope: !35) + +... +--- +name: _Z7ProcessPKj +alignment: 4 +exposesReturnsTwice: false +legalized: false +regBankSelected: false +selected: false +tracksRegLiveness: true +registers: + - { id: 0, class: gr64 } + - { id: 1, class: gr64 } + - { id: 2, class: gr64 } + - { id: 3, class: gr64 } + - { id: 4, class: gr32 } + - { id: 5, class: gr32 } + - { id: 6, class: gr32 } + - { id: 7, class: gr64 } + - { id: 8, class: gr32 } + - { id: 9, class: gr64 } +liveins: + - { reg: '%rdi', virtual-reg: '%3' } +frameInfo: + isFrameAddressTaken: false + isReturnAddressTaken: false + hasStackMap: false + hasPatchPoint: false + stackSize: 0 + offsetAdjustment: 0 + maxAlignment: 0 + adjustsStack: false + hasCalls: false + maxCallFrameSize: 0 + hasOpaqueSPAdjustment: false + hasVAStart: false + hasMustTailInVarArgFunc: false +body: | + bb.0.entry: + successors: %bb.1.while.cond(0x80000000) + liveins: %rdi + + DBG_VALUE debug-use %rdi, debug-use _, !18, !22, debug-location !23 + %3 = COPY %rdi + DBG_VALUE debug-use %3, debug-use _, !18, !22, debug-location !23 + DBG_VALUE 0, debug-use _, !19, !22, debug-location !24 + + bb.1.while.cond: + successors: %bb.2.sw.bb(0x40000000), %bb.1.while.cond(0x40000000) + + %0 = PHI %3, %bb.0.entry, %1, %bb.1.while.cond, %2, %bb.2.sw.bb + DBG_VALUE debug-use %0, debug-use _, !18, !22, debug-location !23 + %1 = ADD64ri8 %0, 4, implicit-def dead %eflags, debug-location !26 + DBG_VALUE debug-use %1, debug-use _, !18, !22, debug-location !23 + %4 = MOV32rm %0, 1, _, 0, _, debug-location !27 :: (load 4 from %ir.pData.addr.0, !tbaa !28) + DBG_VALUE debug-use %4, debug-use _, !20, !22, debug-location !32 + %5 = SUB32ri8 %4, 1, implicit-def %eflags, debug-location !33 + JNE_1 %bb.1.while.cond, implicit %eflags, debug-location !33 + JMP_1 %bb.2.sw.bb, debug-location !33 + + bb.2.sw.bb: + successors: %bb.1.while.cond(0x80000000) + + %6 = MOV32rm %0, 1, _, 4, _, debug-location !36 :: (load 4 from %ir.sunkaddr2, !tbaa !28) + %7 = MOV64rm %rip, 1, _, target-flags(x86-gotpcrel) @x, _, debug-location !37 :: (load 8 from got) + MOV32mr killed %7, 1, _, 0, _, killed %6, debug-location !37 :: (store 4 into @x, !tbaa !28) + %2 = ADD64ri8 %0, 12, implicit-def dead %eflags, debug-location !38 + DBG_VALUE debug-use %2, debug-use _, !18, !22, debug-location !23 + %8 = MOV32rm %0, 1, _, 8, _, debug-location !39 :: (load 4 from %ir.incdec.ptr1, !tbaa !28) + %9 = MOV64rm %rip, 1, _, target-flags(x86-gotpcrel) @y, _, debug-location !40 :: (load 8 from got) + MOV32mr killed %9, 1, _, 0, _, killed %8, debug-location !40 :: (store 4 into @y, !tbaa !28) + JMP_1 %bb.1.while.cond, debug-location !41 + +...