1; RUN: opt %s -passes=sroa -o - -S \ 2; RUN: | FileCheck %s 3; RUN: opt --try-experimental-debuginfo-iterators %s -passes=sroa -o - -S \ 4; RUN: | FileCheck %s 5 6;; Generated from this C++ source: 7;; __attribute__((nodebug)) struct Blob {int P[6];} Glob; 8;; __attribute__((nodebug)) int Cond; 9;; __attribute__((nodebug)) Blob *C; 10;; __attribute__((nodebug)) void call(int); 11;; 12;; void f() { 13;; int A[16]; 14;; __attribute__ ((nodebug)) int B[16]; 15;; // A[0:6) <- Glob 16;; __builtin_memmove(&A[0], &Glob, sizeof(Blob)); 17;; call(0); 18;; // B[8:14) <- Glob 19;; __builtin_memmove(&B[8], &Glob, sizeof(Blob)); 20;; call(A[0]); 21;; // A[8:14) <- A[0:6) 22;; __builtin_memmove(&A[8], &A[0], sizeof(Blob)); 23;; call(A[8]); 24;; if (Cond) 25;; // C <- A[8:14) 26;; __builtin_memmove(C, &A[8], sizeof(Blob)); 27;; else 28;; // C <- B[8:14) 29;; __builtin_memmove(C, &B[8], sizeof(Blob)); 30;; } 31;; 32;; using: 33;; clang test.cpp -emit-llvm -S -g -O2 -Xclang -disable-llvm-passes -o - \ 34;; | opt -passes=declare-to-assign -o test.ll - -S 35 36;; We're interested in variable A and the second memmove with A as a dest (the 37;; third memmove in the source). SROA is going to chop up A so that the only 38;; Alloca'd slice remaining is what were originally elements 1 through 5 39;; inclusive (element 0 is promoted). Incidentally, the memmove later becomes a 40;; memcpy. Check that the dbg.assign address and fragment are correct and 41;; ensure the DIAssignID still links it to the memmove(/memcpy). 42 43; CHECK: %A.sroa.0.sroa.5 = alloca [5 x i32] 44; CHECK: llvm.memcpy{{.*}}(ptr align 4 %A.sroa.0.sroa.5, ptr align 4 getelementptr inbounds (i8, ptr @Glob, i64 4), i64 20, i1 false){{.*}}!DIAssignID ![[ID:[0-9]+]] 45;; Here's the dbg.assign for element 0 - it's not important for the test. 46; CHECK-NEXT: #dbg_value({{.*}}!DIExpression(DW_OP_LLVM_fragment, 0, 32){{.*}}) 47;; This is the dbg.assign we care about: 48; CHECK-NEXT: #dbg_assign(i1 undef, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 32, 160), ![[ID]], ptr %A.sroa.0.sroa.5, !DIExpression(), 49 50; CHECK: ![[VAR]] = !DILocalVariable(name: "A" 51 52source_filename = "test.cpp" 53target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 54target triple = "x86_64-unknown-linux-gnu" 55 56%struct.Blob = type { [6 x i32] } 57 58@Glob = dso_local global %struct.Blob zeroinitializer, align 4 59@Cond = dso_local global i32 0, align 4 60@C = dso_local global ptr null, align 8 61 62; Function Attrs: mustprogress uwtable 63define dso_local void @_Z1fv() #0 !dbg !9 { 64entry: 65 %A = alloca [16 x i32], align 16, !DIAssignID !18 66 call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(), metadata !18, metadata ptr %A, metadata !DIExpression()), !dbg !19 67 %B = alloca [16 x i32], align 16 68 call void @llvm.lifetime.start.p0(i64 64, ptr %A) #5, !dbg !20 69 call void @llvm.lifetime.start.p0(i64 64, ptr %B) #5, !dbg !21 70 %arrayidx = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 0, !dbg !22 71 call void @llvm.memmove.p0.p0.i64(ptr align 16 %arrayidx, ptr align 4 @Glob, i64 24, i1 false), !dbg !23, !DIAssignID !24 72 call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 192), metadata !24, metadata ptr %arrayidx, metadata !DIExpression()), !dbg !19 73 call void @_Z4calli(i32 noundef 0), !dbg !25 74 %arrayidx1 = getelementptr inbounds [16 x i32], ptr %B, i64 0, i64 8, !dbg !26 75 call void @llvm.memmove.p0.p0.i64(ptr align 16 %arrayidx1, ptr align 4 @Glob, i64 24, i1 false), !dbg !27 76 %arrayidx2 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 0, !dbg !28 77 %0 = load i32, ptr %arrayidx2, align 16, !dbg !28 78 call void @_Z4calli(i32 noundef %0), !dbg !33 79 %arrayidx3 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 8, !dbg !34 80 %arrayidx4 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 0, !dbg !35 81 call void @llvm.memmove.p0.p0.i64(ptr align 16 %arrayidx3, ptr align 16 %arrayidx4, i64 24, i1 false), !dbg !36, !DIAssignID !37 82 call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(DW_OP_LLVM_fragment, 256, 192), metadata !37, metadata ptr %arrayidx3, metadata !DIExpression()), !dbg !19 83 %arrayidx5 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 8, !dbg !38 84 %1 = load i32, ptr %arrayidx5, align 16, !dbg !38 85 call void @_Z4calli(i32 noundef %1), !dbg !39 86 %2 = load i32, ptr @Cond, align 4, !dbg !40 87 %tobool = icmp ne i32 %2, 0, !dbg !40 88 br i1 %tobool, label %if.then, label %if.else, !dbg !42 89 90if.then: ; preds = %entry 91 %3 = load ptr, ptr @C, align 8, !dbg !43 92 %arrayidx6 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 8, !dbg !46 93 call void @llvm.memmove.p0.p0.i64(ptr align 4 %3, ptr align 16 %arrayidx6, i64 24, i1 false), !dbg !47 94 br label %if.end, !dbg !47 95 96if.else: ; preds = %entry 97 %4 = load ptr, ptr @C, align 8, !dbg !48 98 %arrayidx7 = getelementptr inbounds [16 x i32], ptr %B, i64 0, i64 8, !dbg !49 99 call void @llvm.memmove.p0.p0.i64(ptr align 4 %4, ptr align 16 %arrayidx7, i64 24, i1 false), !dbg !50 100 br label %if.end 101 102if.end: ; preds = %if.else, %if.then 103 call void @llvm.lifetime.end.p0(i64 64, ptr %B) #5, !dbg !51 104 call void @llvm.lifetime.end.p0(i64 64, ptr %A) #5, !dbg !51 105 ret void, !dbg !51 106} 107 108declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 109declare void @llvm.dbg.declare(metadata, metadata, metadata) #2 110declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3 111declare void @_Z4calli(i32 noundef) #4 112declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1 113declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2 114 115 116!llvm.dbg.cu = !{!0} 117!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !1000} 118!llvm.ident = !{!8} 119 120!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) 121!1 = !DIFile(filename: "test.cpp", directory: "/") 122!2 = !{i32 7, !"Dwarf Version", i32 5} 123!3 = !{i32 2, !"Debug Info Version", i32 3} 124!4 = !{i32 1, !"wchar_size", i32 4} 125!5 = !{i32 8, !"PIC Level", i32 2} 126!6 = !{i32 7, !"PIE Level", i32 2} 127!7 = !{i32 7, !"uwtable", i32 2} 128!8 = !{!"clang version 16.0.0"} 129!9 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !1, file: !1, line: 6, type: !10, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) 130!10 = !DISubroutineType(types: !11) 131!11 = !{null} 132!12 = !{!13} 133!13 = !DILocalVariable(name: "A", scope: !9, file: !1, line: 7, type: !14) 134!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !15, size: 512, elements: !16) 135!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 136!16 = !{!17} 137!17 = !DISubrange(count: 16) 138!18 = distinct !DIAssignID() 139!19 = !DILocation(line: 0, scope: !9) 140!20 = !DILocation(line: 7, column: 3, scope: !9) 141!21 = !DILocation(line: 8, column: 3, scope: !9) 142!22 = !DILocation(line: 10, column: 22, scope: !9) 143!23 = !DILocation(line: 10, column: 3, scope: !9) 144!24 = distinct !DIAssignID() 145!25 = !DILocation(line: 11, column: 3, scope: !9) 146!26 = !DILocation(line: 13, column: 22, scope: !9) 147!27 = !DILocation(line: 13, column: 3, scope: !9) 148!28 = !DILocation(line: 14, column: 8, scope: !9) 149!33 = !DILocation(line: 14, column: 3, scope: !9) 150!34 = !DILocation(line: 16, column: 22, scope: !9) 151!35 = !DILocation(line: 16, column: 29, scope: !9) 152!36 = !DILocation(line: 16, column: 3, scope: !9) 153!37 = distinct !DIAssignID() 154!38 = !DILocation(line: 17, column: 8, scope: !9) 155!39 = !DILocation(line: 17, column: 3, scope: !9) 156!40 = !DILocation(line: 18, column: 7, scope: !41) 157!41 = distinct !DILexicalBlock(scope: !9, file: !1, line: 18, column: 7) 158!42 = !DILocation(line: 18, column: 7, scope: !9) 159!43 = !DILocation(line: 20, column: 23, scope: !41) 160!46 = !DILocation(line: 20, column: 27, scope: !41) 161!47 = !DILocation(line: 20, column: 5, scope: !41) 162!48 = !DILocation(line: 23, column: 23, scope: !41) 163!49 = !DILocation(line: 23, column: 27, scope: !41) 164!50 = !DILocation(line: 23, column: 5, scope: !41) 165!51 = !DILocation(line: 24, column: 1, scope: !9) 166!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true} 167