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.
8 ; void Process(const unsigned int *p)
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
17 ; We check that when the machine loop invariant pass hoists instructions
18 ; out of a loop the debug information is not retained.
20 ; CHECK-LABEL: bb.0.entry:
21 ; CHECK: MOV64rm $rip, 1, $noreg, target-flags(x86-gotpcrel) @x, $noreg :: (load (s64) from got)
22 ; CHECK-LABEL: bb.1.while.body:
25 source_filename = "t.c"
26 target triple = "x86_64-unknown-linux-gnu"
28 @x = common local_unnamed_addr global i32 0, align 4, !dbg !0
30 ; Function Attrs: noreturn nounwind uwtable
31 define void @Process(i32* nocapture readonly %p) local_unnamed_addr !dbg !9 {
33 tail call void @llvm.dbg.value(metadata i32* %p, i64 0, metadata !16, metadata !17), !dbg !18
34 br label %while.body, !dbg !19
36 while.body: ; preds = %while.body, %entry
37 %p.addr.0 = phi i32* [ %p, %entry ], [ %incdec.ptr, %while.body ]
38 tail call void @llvm.dbg.value(metadata i32* %p.addr.0, i64 0, metadata !16, metadata !17), !dbg !18
39 %incdec.ptr = getelementptr inbounds i32, i32* %p.addr.0, i64 1, !dbg !20
40 tail call void @llvm.dbg.value(metadata i32* %incdec.ptr, i64 0, metadata !16, metadata !17), !dbg !18
41 %0 = load i32, i32* %p.addr.0, align 4, !dbg !21, !tbaa !22
42 store i32 %0, i32* @x, align 4, !dbg !26, !tbaa !22
43 br label %while.body, !dbg !27, !llvm.loop !29
46 ; Function Attrs: nounwind readnone
47 declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
50 !llvm.module.flags = !{!6, !7}
53 !0 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "x", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true), expr: !DIExpression())
54 !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)
55 !2 = !DIFile(filename: "t.c", directory: "/home/test")
58 !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
59 !6 = !{i32 2, !"Dwarf Version", i32 4}
60 !7 = !{i32 2, !"Debug Info Version", i32 3}
61 !8 = !{!"clang version 4.0.0 "}
62 !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)
63 !10 = !DISubroutineType(types: !11)
65 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
66 !13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14)
67 !14 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
69 !16 = !DILocalVariable(name: "p", arg: 1, scope: !9, file: !2, line: 2, type: !12)
71 !18 = !DILocation(line: 2, column: 34, scope: !9)
72 !19 = !DILocation(line: 4, column: 3, scope: !9)
73 !20 = !DILocation(line: 5, column: 11, scope: !9)
74 !21 = !DILocation(line: 5, column: 9, scope: !9)
75 !22 = !{!23, !23, i64 0}
76 !23 = !{!"int", !24, i64 0}
77 !24 = !{!"omnipotent char", !25, i64 0}
79 !26 = !DILocation(line: 5, column: 7, scope: !9)
80 !27 = !DILocation(line: 4, column: 3, scope: !28)
81 !28 = !DILexicalBlockFile(scope: !9, file: !2, discriminator: 1)
82 !29 = distinct !{!29, !19, !20}
87 tracksRegLiveness: true
89 - { id: 0, class: gr64 }
90 - { id: 1, class: gr64 }
91 - { id: 2, class: gr64 }
92 - { id: 3, class: gr32 }
93 - { id: 4, class: gr64 }
96 successors: %bb.1.while.body(0x80000000)
99 DBG_VALUE $rdi, _, !16, !17, debug-location !18
101 DBG_VALUE %2, _, !16, !17, debug-location !18
104 successors: %bb.1.while.body(0x80000000)
106 %0 = PHI %2, %bb.0.entry, %1, %bb.1.while.body
107 DBG_VALUE %0, _, !16, !17, debug-location !18
108 %1 = ADD64ri8 %0, 4, implicit-def dead $eflags, debug-location !20
109 DBG_VALUE %1, _, !16, !17, debug-location !18
110 %3 = MOV32rm %0, 1, _, 0, _, debug-location !21 :: (load (s32) from %ir.p.addr.0, !tbaa !22)
111 %4 = MOV64rm $rip, 1, _, target-flags(x86-gotpcrel) @x, _, debug-location !26 :: (load (s64) from got)
112 MOV32mr killed %4, 1, _, 0, _, killed %3, debug-location !26 :: (store (s32) into @x, !tbaa !22)
113 JMP_1 %bb.1.while.body, debug-location !27