1 --- | 2 ; RUN: llc -run-pass=machinelicm -o - %s | FileCheck %s 3 ; Line numbers should not be retained when loop invariant instructions are hoisted. 4 ; Doing so causes poor stepping bevavior. 5 ; 6 ; Created from: 7 ; int x; 8 ; void Process(const unsigned int *p) 9 ; { 10 ; while (1) 11 ; x = *p++; 12 ; } 13 ; 14 ; with clang -emit-llvm -S -O2 -g -o t.ll t.c 15 ; llc -relocation-model=pic -stop-after=machine-combine -O2 t.ll -o t.mir 16 ; 17 ; We check that when the machine loop invariant pass hoists instructions 18 ; out of a loop the debug information is not retained. 19 ; 20 ; CHECK-LABEL: bb.0.entry: 21 ; CHECK: MOV64rm $rip, 1, $noreg, target-flags(x86-gotpcrel) @x, $noreg :: (load 8 from got) 22 ; CHECK-LABEL: bb.1.while.body: 23 ; 24 ; ModuleID = 'tx.ll' 25 source_filename = "t.c" 26 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 27 target triple = "x86_64-unknown-linux-gnu" 28 29 @x = common local_unnamed_addr global i32 0, align 4, !dbg !0 30 31 ; Function Attrs: noreturn nounwind uwtable 32 define void @Process(i32* nocapture readonly %p) local_unnamed_addr #0 !dbg !9 { 33 entry: 34 tail call void @llvm.dbg.value(metadata i32* %p, i64 0, metadata !16, metadata !17), !dbg !18 35 br label %while.body, !dbg !19 36 37 while.body: ; preds = %while.body, %entry 38 %p.addr.0 = phi i32* [ %p, %entry ], [ %incdec.ptr, %while.body ] 39 tail call void @llvm.dbg.value(metadata i32* %p.addr.0, i64 0, metadata !16, metadata !17), !dbg !18 40 %incdec.ptr = getelementptr inbounds i32, i32* %p.addr.0, i64 1, !dbg !20 41 tail call void @llvm.dbg.value(metadata i32* %incdec.ptr, i64 0, metadata !16, metadata !17), !dbg !18 42 %0 = load i32, i32* %p.addr.0, align 4, !dbg !21, !tbaa !22 43 store i32 %0, i32* @x, align 4, !dbg !26, !tbaa !22 44 br label %while.body, !dbg !27, !llvm.loop !29 45 } 46 47 ; Function Attrs: nounwind readnone 48 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 49 50 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" } 51 attributes #1 = { nounwind readnone } 52 attributes #2 = { nounwind } 53 54 !llvm.dbg.cu = !{!1} 55 !llvm.module.flags = !{!6, !7} 56 !llvm.ident = !{!8} 57 58 !0 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "x", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true), expr: !DIExpression()) 59 !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 4.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4) 60 !2 = !DIFile(filename: "t.c", directory: "/home/test") 61 !3 = !{} 62 !4 = !{!0} 63 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 64 !6 = !{i32 2, !"Dwarf Version", i32 4} 65 !7 = !{i32 2, !"Debug Info Version", i32 3} 66 !8 = !{!"clang version 4.0.0 "} 67 !9 = distinct !DISubprogram(name: "Process", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !1, retainedNodes: !15) 68 !10 = !DISubroutineType(types: !11) 69 !11 = !{null, !12} 70 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64) 71 !13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14) 72 !14 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 73 !15 = !{!16} 74 !16 = !DILocalVariable(name: "p", arg: 1, scope: !9, file: !2, line: 2, type: !12) 75 !17 = !DIExpression() 76 !18 = !DILocation(line: 2, column: 34, scope: !9) 77 !19 = !DILocation(line: 4, column: 3, scope: !9) 78 !20 = !DILocation(line: 5, column: 11, scope: !9) 79 !21 = !DILocation(line: 5, column: 9, scope: !9) 80 !22 = !{!23, !23, i64 0} 81 !23 = !{!"int", !24, i64 0} 82 !24 = !{!"omnipotent char", !25, i64 0} 83 !25 = !{!"Simple C/C++ TBAA"} 84 !26 = !DILocation(line: 5, column: 7, scope: !9) 85 !27 = !DILocation(line: 4, column: 3, scope: !28) 86 !28 = !DILexicalBlockFile(scope: !9, file: !2, discriminator: 1) 87 !29 = distinct !{!29, !19, !20} 88 89 ... 90 --- 91 name: Process 92 alignment: 4 93 exposesReturnsTwice: false 94 legalized: false 95 regBankSelected: false 96 selected: false 97 tracksRegLiveness: true 98 registers: 99 - { id: 0, class: gr64 } 100 - { id: 1, class: gr64 } 101 - { id: 2, class: gr64 } 102 - { id: 3, class: gr32 } 103 - { id: 4, class: gr64 } 104 liveins: 105 - { reg: '$rdi', virtual-reg: '%2' } 106 frameInfo: 107 isFrameAddressTaken: false 108 isReturnAddressTaken: false 109 hasStackMap: false 110 hasPatchPoint: false 111 stackSize: 0 112 offsetAdjustment: 0 113 maxAlignment: 0 114 adjustsStack: false 115 hasCalls: false 116 maxCallFrameSize: 0 117 hasOpaqueSPAdjustment: false 118 hasVAStart: false 119 hasMustTailInVarArgFunc: false 120 body: | 121 bb.0.entry: 122 successors: %bb.1.while.body(0x80000000) 123 liveins: $rdi 124 125 DBG_VALUE debug-use $rdi, debug-use _, !16, !17, debug-location !18 126 %2 = COPY $rdi 127 DBG_VALUE debug-use %2, debug-use _, !16, !17, debug-location !18 128 129 bb.1.while.body: 130 successors: %bb.1.while.body(0x80000000) 131 132 %0 = PHI %2, %bb.0.entry, %1, %bb.1.while.body 133 DBG_VALUE debug-use %0, debug-use _, !16, !17, debug-location !18 134 %1 = ADD64ri8 %0, 4, implicit-def dead $eflags, debug-location !20 135 DBG_VALUE debug-use %1, debug-use _, !16, !17, debug-location !18 136 %3 = MOV32rm %0, 1, _, 0, _, debug-location !21 :: (load 4 from %ir.p.addr.0, !tbaa !22) 137 %4 = MOV64rm $rip, 1, _, target-flags(x86-gotpcrel) @x, _, debug-location !26 :: (load 8 from got) 138 MOV32mr killed %4, 1, _, 0, _, killed %3, debug-location !26 :: (store 4 into @x, !tbaa !22) 139 JMP_1 %bb.1.while.body, debug-location !27 140 141 ... 142