165 lines · plain
1; RUN: opt %s -passes=sroa -o - -S \2; RUN: | FileCheck %s3 4;; Generated from this C++ source:5;; __attribute__((nodebug)) struct Blob {int P[6];} Glob;6;; __attribute__((nodebug)) int Cond;7;; __attribute__((nodebug)) Blob *C;8;; __attribute__((nodebug)) void call(int);9;; 10;; void f() {11;; int A[16];12;; __attribute__ ((nodebug)) int B[16];13;; // A[0:6) <- Glob14;; __builtin_memmove(&A[0], &Glob, sizeof(Blob));15;; call(0);16;; // B[8:14) <- Glob17;; __builtin_memmove(&B[8], &Glob, sizeof(Blob)); 18;; call(A[0]);19;; // A[8:14) <- A[0:6)20;; __builtin_memmove(&A[8], &A[0], sizeof(Blob));21;; call(A[8]);22;; if (Cond)23;; // C <- A[8:14)24;; __builtin_memmove(C, &A[8], sizeof(Blob));25;; else26;; // C <- B[8:14)27;; __builtin_memmove(C, &B[8], sizeof(Blob)); 28;; }29;; 30;; using:31;; clang test.cpp -emit-llvm -S -g -O2 -Xclang -disable-llvm-passes -o - \32;; | opt -passes=declare-to-assign -o test.ll - -S33 34;; We're interested in variable A and the second memmove with A as a dest (the35;; third memmove in the source). SROA is going to chop up A so that the only36;; Alloca'd slice remaining is what were originally elements 1 through 537;; inclusive (element 0 is promoted). Incidentally, the memmove later becomes a38;; memcpy. Check that the dbg.assign address and fragment are correct and39;; ensure the DIAssignID still links it to the memmove(/memcpy).40 41; CHECK: %A.sroa.0.sroa.5 = alloca [5 x i32]42; 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]+]]43;; Here's the dbg.assign for element 0 - it's not important for the test.44; CHECK-NEXT: #dbg_value({{.*}}!DIExpression(DW_OP_LLVM_fragment, 0, 32){{.*}})45;; This is the dbg.assign we care about:46; CHECK-NEXT: #dbg_assign(i1 undef, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 32, 160), ![[ID]], ptr %A.sroa.0.sroa.5, !DIExpression(),47 48; CHECK: ![[VAR]] = !DILocalVariable(name: "A"49 50source_filename = "test.cpp"51target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"52target triple = "x86_64-unknown-linux-gnu"53 54%struct.Blob = type { [6 x i32] }55 56@Glob = dso_local global %struct.Blob zeroinitializer, align 457@Cond = dso_local global i32 0, align 458@C = dso_local global ptr null, align 859 60; Function Attrs: mustprogress uwtable61define dso_local void @_Z1fv() #0 !dbg !9 {62entry:63 %A = alloca [16 x i32], align 16, !DIAssignID !1864 call void @llvm.dbg.assign(metadata i1 undef, metadata !13, metadata !DIExpression(), metadata !18, metadata ptr %A, metadata !DIExpression()), !dbg !1965 %B = alloca [16 x i32], align 1666 call void @llvm.lifetime.start.p0(i64 64, ptr %A) #5, !dbg !2067 call void @llvm.lifetime.start.p0(i64 64, ptr %B) #5, !dbg !2168 %arrayidx = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 0, !dbg !2269 call void @llvm.memmove.p0.p0.i64(ptr align 16 %arrayidx, ptr align 4 @Glob, i64 24, i1 false), !dbg !23, !DIAssignID !2470 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 !1971 call void @_Z4calli(i32 noundef 0), !dbg !2572 %arrayidx1 = getelementptr inbounds [16 x i32], ptr %B, i64 0, i64 8, !dbg !2673 call void @llvm.memmove.p0.p0.i64(ptr align 16 %arrayidx1, ptr align 4 @Glob, i64 24, i1 false), !dbg !2774 %arrayidx2 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 0, !dbg !2875 %0 = load i32, ptr %arrayidx2, align 16, !dbg !2876 call void @_Z4calli(i32 noundef %0), !dbg !3377 %arrayidx3 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 8, !dbg !3478 %arrayidx4 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 0, !dbg !3579 call void @llvm.memmove.p0.p0.i64(ptr align 16 %arrayidx3, ptr align 16 %arrayidx4, i64 24, i1 false), !dbg !36, !DIAssignID !3780 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 !1981 %arrayidx5 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 8, !dbg !3882 %1 = load i32, ptr %arrayidx5, align 16, !dbg !3883 call void @_Z4calli(i32 noundef %1), !dbg !3984 %2 = load i32, ptr @Cond, align 4, !dbg !4085 %tobool = icmp ne i32 %2, 0, !dbg !4086 br i1 %tobool, label %if.then, label %if.else, !dbg !4287 88if.then: ; preds = %entry89 %3 = load ptr, ptr @C, align 8, !dbg !4390 %arrayidx6 = getelementptr inbounds [16 x i32], ptr %A, i64 0, i64 8, !dbg !4691 call void @llvm.memmove.p0.p0.i64(ptr align 4 %3, ptr align 16 %arrayidx6, i64 24, i1 false), !dbg !4792 br label %if.end, !dbg !4793 94if.else: ; preds = %entry95 %4 = load ptr, ptr @C, align 8, !dbg !4896 %arrayidx7 = getelementptr inbounds [16 x i32], ptr %B, i64 0, i64 8, !dbg !4997 call void @llvm.memmove.p0.p0.i64(ptr align 4 %4, ptr align 16 %arrayidx7, i64 24, i1 false), !dbg !5098 br label %if.end99 100if.end: ; preds = %if.else, %if.then101 call void @llvm.lifetime.end.p0(i64 64, ptr %B) #5, !dbg !51102 call void @llvm.lifetime.end.p0(i64 64, ptr %A) #5, !dbg !51103 ret void, !dbg !51104}105 106declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1107declare void @llvm.dbg.declare(metadata, metadata, metadata) #2108declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3109declare void @_Z4calli(i32 noundef) #4110declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1111declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2112 113 114!llvm.dbg.cu = !{!0}115!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !1000}116!llvm.ident = !{!8}117 118!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)119!1 = !DIFile(filename: "test.cpp", directory: "/")120!2 = !{i32 7, !"Dwarf Version", i32 5}121!3 = !{i32 2, !"Debug Info Version", i32 3}122!4 = !{i32 1, !"wchar_size", i32 4}123!5 = !{i32 8, !"PIC Level", i32 2}124!6 = !{i32 7, !"PIE Level", i32 2}125!7 = !{i32 7, !"uwtable", i32 2}126!8 = !{!"clang version 16.0.0"}127!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)128!10 = !DISubroutineType(types: !11)129!11 = !{null}130!12 = !{!13}131!13 = !DILocalVariable(name: "A", scope: !9, file: !1, line: 7, type: !14)132!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !15, size: 512, elements: !16)133!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)134!16 = !{!17}135!17 = !DISubrange(count: 16)136!18 = distinct !DIAssignID()137!19 = !DILocation(line: 0, scope: !9)138!20 = !DILocation(line: 7, column: 3, scope: !9)139!21 = !DILocation(line: 8, column: 3, scope: !9)140!22 = !DILocation(line: 10, column: 22, scope: !9)141!23 = !DILocation(line: 10, column: 3, scope: !9)142!24 = distinct !DIAssignID()143!25 = !DILocation(line: 11, column: 3, scope: !9)144!26 = !DILocation(line: 13, column: 22, scope: !9)145!27 = !DILocation(line: 13, column: 3, scope: !9)146!28 = !DILocation(line: 14, column: 8, scope: !9)147!33 = !DILocation(line: 14, column: 3, scope: !9)148!34 = !DILocation(line: 16, column: 22, scope: !9)149!35 = !DILocation(line: 16, column: 29, scope: !9)150!36 = !DILocation(line: 16, column: 3, scope: !9)151!37 = distinct !DIAssignID()152!38 = !DILocation(line: 17, column: 8, scope: !9)153!39 = !DILocation(line: 17, column: 3, scope: !9)154!40 = !DILocation(line: 18, column: 7, scope: !41)155!41 = distinct !DILexicalBlock(scope: !9, file: !1, line: 18, column: 7)156!42 = !DILocation(line: 18, column: 7, scope: !9)157!43 = !DILocation(line: 20, column: 23, scope: !41)158!46 = !DILocation(line: 20, column: 27, scope: !41)159!47 = !DILocation(line: 20, column: 5, scope: !41)160!48 = !DILocation(line: 23, column: 23, scope: !41)161!49 = !DILocation(line: 23, column: 27, scope: !41)162!50 = !DILocation(line: 23, column: 5, scope: !41)163!51 = !DILocation(line: 24, column: 1, scope: !9)164!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}165