1; RUN: llc %s -stop-after=finalize-isel -o - \ 2; RUN: | FileCheck %s --implicit-check-not=DBG 3 4 5; RUN: llc --try-experimental-debuginfo-iterators %s -stop-after=finalize-isel -o - \ 6; RUN: | FileCheck %s --implicit-check-not=DBG 7 8;; Tiny loop with a store sunk out of it: 9;; void e(); 10;; void es(int*); 11;; int *g; 12;; int getInt(); 13;; int f(int a, int b) { 14;; int z = getInt(); 15;; while (g) { 16;; e(); 17;; a = z; 18;; } 19;; es(&a); 20;; return a; 21;; } 22;; 23;; Store to `a` has been sunk out the loop - there's a dbg.assign left in the 24;; loop that is linked the store that is now outside it. Check that the memory 25;; location is not used inside the loop and is reinstated after the sunk store. 26 27; CHECK-DAG: ![[A:[0-9]+]] = !DILocalVariable(name: "a", 28 29; CHECK-LABEL: bb.0.entry: 30; CHECK: DBG_VALUE $edi, $noreg, ![[A]], !DIExpression() 31; CHECK: CALL64pcrel32 @getInt{{.*}}debug-instr-number 1 32 33; CHECK-LABEL: bb.2.while.body: 34; CHECK: DBG_INSTR_REF ![[A]], !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 6) 35 36; CHECK-LABEL: bb.3.while.end: 37; CHECK: MOV32mr %stack.0.a.addr, 1, $noreg, 0, $noreg, %1 38; CHECK-NEXT: DBG_VALUE %stack.0.a.addr, $noreg, ![[A]], !DIExpression(DW_OP_deref) 39 40target triple = "x86_64-unknown-linux-gnu" 41 42@g = dso_local local_unnamed_addr global ptr null, align 8, !dbg !0 43 44; Function Attrs: mustprogress uwtable 45define dso_local noundef i32 @_Z1fii(i32 noundef %a, i32 noundef %b) local_unnamed_addr #0 !dbg !12 { 46entry: 47 %a.addr = alloca i32, align 4, !DIAssignID !18 48 call void @llvm.dbg.assign(metadata i1 undef, metadata !16, metadata !DIExpression(), metadata !18, metadata ptr %a.addr, metadata !DIExpression()), !dbg !19 49 call void @llvm.dbg.assign(metadata i32 %a, metadata !16, metadata !DIExpression(), metadata !20, metadata ptr %a.addr, metadata !DIExpression()), !dbg !19 50 %z = call i32 @getInt() 51 %0 = load ptr, ptr @g, align 8, !dbg !22 52 %tobool.not1 = icmp eq ptr %0, null, !dbg !22 53 br i1 %tobool.not1, label %while.end, label %while.body, !dbg !27 54 55while.body: ; preds = %entry, %while.body 56 tail call void @_Z1ev(), !dbg !28 57 call void @llvm.dbg.assign(metadata i32 %z, metadata !16, metadata !DIExpression(), metadata !20, metadata ptr %a.addr, metadata !DIExpression()), !dbg !19 58 %1 = load ptr, ptr @g, align 8, !dbg !22 59 %tobool.not = icmp eq ptr %1, null, !dbg !22 60 br i1 %tobool.not, label %while.end, label %while.body, !dbg !27, !llvm.loop !30 61 62while.end: ; preds = %while.body, %entry 63 %storemerge.lcssa = phi i32 [ %a, %entry ], [ %b, %while.body ] 64 store i32 %storemerge.lcssa, ptr %a.addr, align 4, !DIAssignID !20 65 call void @_Z2esPi(ptr noundef nonnull %a.addr), !dbg !35 66 %2 = load i32, ptr %a.addr, align 4, !dbg !36 67 %r = add i32 %2, %z 68 ret i32 %r, !dbg !37 69} 70 71declare !dbg !38 dso_local void @_Z1ev() local_unnamed_addr #1 72declare !dbg !42 dso_local void @_Z2esPi(ptr noundef) local_unnamed_addr #1 73declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2 74declare dso_local i32 @getInt() 75 76!llvm.dbg.cu = !{!2} 77!llvm.module.flags = !{!7, !8, !9, !10, !1000} 78!llvm.ident = !{!11} 79 80!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 81!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, isLocal: false, isDefinition: true) 82!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None) 83!3 = !DIFile(filename: "test.cpp", directory: "/") 84!4 = !{!0} 85!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64) 86!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 87!7 = !{i32 7, !"Dwarf Version", i32 5} 88!8 = !{i32 2, !"Debug Info Version", i32 3} 89!9 = !{i32 1, !"wchar_size", i32 4} 90!10 = !{i32 7, !"uwtable", i32 1} 91!11 = !{!"clang version 14.0.0"} 92!12 = distinct !DISubprogram(name: "f", linkageName: "_Z1fii", scope: !3, file: !3, line: 5, type: !13, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15) 93!13 = !DISubroutineType(types: !14) 94!14 = !{!6, !6, !6} 95!15 = !{!16, !17} 96!16 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !3, line: 5, type: !6) 97!17 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !3, line: 5, type: !6) 98!18 = distinct !DIAssignID() 99!19 = !DILocation(line: 0, scope: !12) 100!20 = distinct !DIAssignID() 101!21 = distinct !DIAssignID() 102!22 = !DILocation(line: 6, column: 10, scope: !12) 103!27 = !DILocation(line: 6, column: 3, scope: !12) 104!28 = !DILocation(line: 7, column: 5, scope: !29) 105!29 = distinct !DILexicalBlock(scope: !12, file: !3, line: 6, column: 13) 106!30 = distinct !{!30, !27, !31, !32} 107!31 = !DILocation(line: 9, column: 3, scope: !12) 108!32 = !{!"llvm.loop.mustprogress"} 109!35 = !DILocation(line: 10, column: 3, scope: !12) 110!36 = !DILocation(line: 11, column: 10, scope: !12) 111!37 = !DILocation(line: 11, column: 3, scope: !12) 112!38 = !DISubprogram(name: "e", linkageName: "_Z1ev", scope: !3, file: !3, line: 2, type: !39, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !41) 113!39 = !DISubroutineType(types: !40) 114!40 = !{null} 115!41 = !{} 116!42 = !DISubprogram(name: "es", linkageName: "_Z2esPi", scope: !3, file: !3, line: 3, type: !43, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !41) 117!43 = !DISubroutineType(types: !44) 118!44 = !{null, !5} 119!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 120