130 lines · plain
1; RUN: opt %s -S -passes=dse -o - | FileCheck %s2 3;; $ cat test.cpp4;; void esc(int*);5;; void shortenEnd() {6;; int local[20];7;; __builtin_memset(local, 0, 6 * 4);8;; __builtin_memset(local + 4, 8, 10 * 4);9;; esc(local);10;; }11;; void shortenStart() {12;; int local2[10];13;; __builtin_memset(local2, 0, 10 * 4);14;; __builtin_memset(local2, 8, 4 * 4);15;; esc(local2);16;; }17;; IR grabbed before dse in:18;; clang++ -O2 -g -Xclang -fexperimental-assignment-tracking19 20;; DeadStoreElimination will shorten the first store in shortenEnd from [0,21;; 192) bits to [0, 128) bits. Check that we get an unlinked dbg.assign covering22;; the deleted bits [128, 192) (offset=128 size=64). It will shorten also the23;; first store in shortenStart from [0, 320) bits to [128, 320). Check that we24;; get an unlinked dbg.assign covering the deleted bits [0, 128) (offset=025;; size=128).26 27; CHECK: @_Z10shortenEndv28; CHECK: call void @llvm.memset{{.*}}, !DIAssignID ![[ID:[0-9]+]]29; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 192), ![[ID:[0-9]+]], ptr %local, !DIExpression(),30; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR]], !DIExpression(DW_OP_LLVM_fragment, 128, 64), ![[UniqueID1:[0-9]+]], ptr poison, !DIExpression(),31 32; CHECK: @_Z12shortenStartv33; CHECK: call void @llvm.memset{{.*}}, !DIAssignID ![[ID2:[0-9]+]]34; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR2:[0-9]+]], !DIExpression(), ![[ID2]], ptr %local2, !DIExpression(),35; CHECK-NEXT: #dbg_assign(i8 0, ![[VAR2]], !DIExpression(DW_OP_LLVM_fragment, 0, 128), ![[UniqueID2:[0-9]+]], ptr poison, !DIExpression(),36 37; CHECK-DAG: ![[ID]] = distinct !DIAssignID()38; CHECK-DAG: ![[UniqueID1]] = distinct !DIAssignID()39; CHECK-DAG: ![[UniqueID2]] = distinct !DIAssignID()40 41define dso_local void @_Z10shortenEndv() local_unnamed_addr #0 !dbg !7 {42entry:43 %local = alloca [20 x i32], align 16, !DIAssignID !1644 call void @llvm.dbg.assign(metadata i1 poison, metadata !11, metadata !DIExpression(), metadata !16, metadata ptr %local, metadata !DIExpression()), !dbg !1745 call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %local) #5, !dbg !1846 %arraydecay = getelementptr inbounds [20 x i32], ptr %local, i64 0, i64 0, !dbg !1947 call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %local, i8 0, i64 24, i1 false), !dbg !19, !DIAssignID !2048 call void @llvm.dbg.assign(metadata i8 0, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 192), metadata !20, metadata ptr %local, metadata !DIExpression()), !dbg !1749 %add.ptr = getelementptr inbounds [20 x i32], ptr %local, i64 0, i64 4, !dbg !2150 call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %add.ptr, i8 8, i64 40, i1 false), !dbg !22, !DIAssignID !2351 call void @llvm.dbg.assign(metadata i1 poison, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 128, 320), metadata !23, metadata ptr %add.ptr, metadata !DIExpression()), !dbg !1752 call void @_Z3escPi(ptr noundef nonnull %arraydecay), !dbg !2453 call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %local) #5, !dbg !2554 ret void, !dbg !2555}56 57declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)58declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)59declare !dbg !26 dso_local void @_Z3escPi(ptr noundef) local_unnamed_addr60declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)61 62define dso_local void @_Z12shortenStartv() local_unnamed_addr #0 !dbg !31 {63entry:64 %local2 = alloca [10 x i32], align 16, !DIAssignID !3765 call void @llvm.dbg.assign(metadata i1 poison, metadata !33, metadata !DIExpression(), metadata !37, metadata ptr %local2, metadata !DIExpression()), !dbg !3866 call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %local2) #5, !dbg !3967 %arraydecay = getelementptr inbounds [10 x i32], ptr %local2, i64 0, i64 0, !dbg !4068 call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %local2, i8 0, i64 40, i1 false), !dbg !40, !DIAssignID !4169 call void @llvm.dbg.assign(metadata i8 0, metadata !33, metadata !DIExpression(), metadata !41, metadata ptr %local2, metadata !DIExpression()), !dbg !3870 call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %local2, i8 8, i64 16, i1 false), !dbg !42, !DIAssignID !4371 call void @llvm.dbg.assign(metadata i1 poison, metadata !33, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 128), metadata !43, metadata ptr %local2, metadata !DIExpression()), !dbg !3872 call void @_Z3escPi(ptr noundef nonnull %arraydecay), !dbg !4473 call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %local2) #5, !dbg !4574 ret void, !dbg !4575}76 77declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)78 79!llvm.dbg.cu = !{!0}80!llvm.module.flags = !{!2, !3, !4, !5, !1000}81!llvm.ident = !{!6}82 83!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)84!1 = !DIFile(filename: "test.cpp", directory: "/")85!2 = !{i32 7, !"Dwarf Version", i32 5}86!3 = !{i32 2, !"Debug Info Version", i32 3}87!4 = !{i32 1, !"wchar_size", i32 4}88!5 = !{i32 7, !"uwtable", i32 1}89!6 = !{!"clang version 14.0.0"}90!7 = distinct !DISubprogram(name: "shortenEnd", linkageName: "_Z10shortenEndv", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)91!8 = !DISubroutineType(types: !9)92!9 = !{null}93!10 = !{!11}94!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 3, type: !12)95!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 640, elements: !14)96!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)97!14 = !{!15}98!15 = !DISubrange(count: 20)99!16 = distinct !DIAssignID()100!17 = !DILocation(line: 0, scope: !7)101!18 = !DILocation(line: 3, column: 3, scope: !7)102!19 = !DILocation(line: 4, column: 3, scope: !7)103!20 = distinct !DIAssignID()104!21 = !DILocation(line: 5, column: 26, scope: !7)105!22 = !DILocation(line: 5, column: 3, scope: !7)106!23 = distinct !DIAssignID()107!24 = !DILocation(line: 6, column: 3, scope: !7)108!25 = !DILocation(line: 7, column: 1, scope: !7)109!26 = !DISubprogram(name: "esc", linkageName: "_Z3escPi", scope: !1, file: !1, line: 1, type: !27, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !30)110!27 = !DISubroutineType(types: !28)111!28 = !{null, !29}112!29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)113!30 = !{}114!31 = distinct !DISubprogram(name: "shortenStart", linkageName: "_Z12shortenStartv", scope: !1, file: !1, line: 8, type: !8, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !32)115!32 = !{!33}116!33 = !DILocalVariable(name: "local2", scope: !31, file: !1, line: 9, type: !34)117!34 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, size: 320, elements: !35)118!35 = !{!36}119!36 = !DISubrange(count: 10)120!37 = distinct !DIAssignID()121!38 = !DILocation(line: 0, scope: !31)122!39 = !DILocation(line: 9, column: 3, scope: !31)123!40 = !DILocation(line: 10, column: 3, scope: !31)124!41 = distinct !DIAssignID()125!42 = !DILocation(line: 11, column: 3, scope: !31)126!43 = distinct !DIAssignID()127!44 = !DILocation(line: 12, column: 3, scope: !31)128!45 = !DILocation(line: 13, column: 1, scope: !31)129!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}130