1; RUN: opt -passes=mldst-motion -S %s -o - \ 2; RUN: | FileCheck %s 3; RUN: opt --try-experimental-debuginfo-iterators -passes=mldst-motion -S %s -o - \ 4; RUN: | FileCheck %s 5 6;; $ cat test.cpp 7;; int cond; 8;; void esc(int*); 9;; void fun() { 10;; int a[4]; 11;; if (cond) 12;; a[1] = 1; 13;; else 14;; a[1] = 2; 15;; esc(a); 16;; } 17;; 18;; 19;; mldst-motion will merge and sink the stores in if.then and if.else into 20;; if.end. Ensure the merged store has a DIAssignID linking it to the two 21;; dbg.assign intrinsics which have been left in their original blocks. 22 23; CHECK: if.then: 24; CHECK-NEXT: #dbg_assign(i32 1,{{.+}}, !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[ID:[0-9]+]], ptr %1, !DIExpression(), 25 26; CHECK: if.else: 27; CHECK-NEXT: #dbg_assign(i32 2,{{.+}}, !DIExpression(DW_OP_LLVM_fragment, 32, 32), ![[ID]], ptr %1, !DIExpression(), 28 29; CHECK: if.end: 30; CHECK: store i32 %.sink, ptr %1, align 4{{.+}}, !DIAssignID ![[ID]] 31 32@cond = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0 33 34define dso_local void @_Z3funv() !dbg !11 { 35entry: 36 %a = alloca [4 x i32], align 16, !DIAssignID !19 37 call void @llvm.dbg.assign(metadata i1 undef, metadata !15, metadata !DIExpression(), metadata !19, metadata ptr %a, metadata !DIExpression()), !dbg !20 38 call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %a) #4, !dbg !21 39 %0 = load i32, ptr @cond, align 4, !dbg !22 40 %tobool.not = icmp eq i32 %0, 0, !dbg !22 41 br i1 %tobool.not, label %if.else, label %if.then, !dbg !28 42 43if.then: ; preds = %entry 44 %arrayidx = getelementptr inbounds [4 x i32], ptr %a, i64 0, i64 1, !dbg !29 45 store i32 1, ptr %arrayidx, align 4, !dbg !30, !DIAssignID !31 46 call void @llvm.dbg.assign(metadata i32 1, metadata !15, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !31, metadata ptr %arrayidx, metadata !DIExpression()), !dbg !20 47 br label %if.end, !dbg !29 48 49if.else: ; preds = %entry 50 %arrayidx1 = getelementptr inbounds [4 x i32], ptr %a, i64 0, i64 1, !dbg !32 51 store i32 2, ptr %arrayidx1, align 4, !dbg !33, !DIAssignID !34 52 call void @llvm.dbg.assign(metadata i32 2, metadata !15, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !34, metadata ptr %arrayidx1, metadata !DIExpression()), !dbg !20 53 br label %if.end 54 55if.end: ; preds = %if.else, %if.then 56 %arraydecay = getelementptr inbounds [4 x i32], ptr %a, i64 0, i64 0, !dbg !35 57 call void @_Z3escPi(ptr noundef nonnull %arraydecay), !dbg !36 58 call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %a) #4, !dbg !37 59 ret void, !dbg !37 60} 61 62declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) 63declare !dbg !38 dso_local void @_Z3escPi(ptr noundef) 64declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) 65declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) 66 67!llvm.dbg.cu = !{!2} 68!llvm.module.flags = !{!6, !7, !8, !9, !1000} 69!llvm.ident = !{!10} 70 71!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 72!1 = distinct !DIGlobalVariable(name: "cond", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true) 73!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) 74!3 = !DIFile(filename: "test.cpp", directory: "/") 75!4 = !{!0} 76!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 77!6 = !{i32 7, !"Dwarf Version", i32 5} 78!7 = !{i32 2, !"Debug Info Version", i32 3} 79!8 = !{i32 1, !"wchar_size", i32 4} 80!9 = !{i32 7, !"uwtable", i32 1} 81!10 = !{!"clang version 14.0.0"} 82!11 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !3, file: !3, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14) 83!12 = !DISubroutineType(types: !13) 84!13 = !{null} 85!14 = !{!15} 86!15 = !DILocalVariable(name: "a", scope: !11, file: !3, line: 4, type: !16) 87!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !5, size: 128, elements: !17) 88!17 = !{!18} 89!18 = !DISubrange(count: 4) 90!19 = distinct !DIAssignID() 91!20 = !DILocation(line: 0, scope: !11) 92!21 = !DILocation(line: 4, column: 3, scope: !11) 93!22 = !DILocation(line: 5, column: 7, scope: !23) 94!23 = distinct !DILexicalBlock(scope: !11, file: !3, line: 5, column: 7) 95!28 = !DILocation(line: 5, column: 7, scope: !11) 96!29 = !DILocation(line: 6, column: 5, scope: !23) 97!30 = !DILocation(line: 6, column: 10, scope: !23) 98!31 = distinct !DIAssignID() 99!32 = !DILocation(line: 8, column: 5, scope: !23) 100!33 = !DILocation(line: 8, column: 10, scope: !23) 101!34 = distinct !DIAssignID() 102!35 = !DILocation(line: 9, column: 7, scope: !11) 103!36 = !DILocation(line: 9, column: 3, scope: !11) 104!37 = !DILocation(line: 10, column: 1, scope: !11) 105!38 = !DISubprogram(name: "esc", linkageName: "_Z3escPi", scope: !3, file: !3, line: 2, type: !39, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !42) 106!39 = !DISubroutineType(types: !40) 107!40 = !{null, !41} 108!41 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64) 109!42 = !{} 110!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 111