[llvm] [DSE] Split memory intrinsics if they are dead in the middle (PR #75478)

Nabeel Omer via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 07:53:50 PDT 2024


================
@@ -0,0 +1,113 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt < %s -passes=dse -S | FileCheck %s
+
+; Check a dbg.assign is inserted that sets the dead middle bits to no-location (see tryToSplitMiddle).
+
+define void @_Z22overwrite_middle_localv() !dbg !23 {
+; CHECK-LABEL: define void @_Z22overwrite_middle_localv(
+; CHECK-SAME: ) !dbg [[DBG23:![0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[BLOB:%.*]] = alloca [1000 x i8], align 16, !DIAssignID [[DIASSIGNID33:![0-9]+]]
+; CHECK-NEXT:      #dbg_assign(i1 undef, [[META28:![0-9]+]], !DIExpression(), [[DIASSIGNID33]], ptr [[BLOB]], !DIExpression(), [[META34:![0-9]+]])
+; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i8, ptr [[BLOB]], i64 976
+; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) [[TMP0]], i8 5, i64 24, i1 false), !dbg [[META34]], !DIAssignID [[DIASSIGNID35:![0-9]+]]
+; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(10) [[BLOB]], i8 5, i64 10, i1 false), !dbg [[META34]], !DIAssignID [[DIASSIGNID35]]
+; CHECK-NEXT:      #dbg_assign(i1 undef, [[META28]], !DIExpression(), [[DIASSIGNID35]], ptr [[BLOB]], !DIExpression(), [[META34]])
+; CHECK-NEXT:      #dbg_assign(i1 undef, [[META28]], !DIExpression(DW_OP_LLVM_fragment, 80, 7920), [[META36:![0-9]+]], ptr undef, !DIExpression(), [[META34]])
+; CHECK-NEXT:    [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[BLOB]], i64 10, !dbg [[META34]]
+; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(980) [[ADD_PTR]], i8 3, i64 980, i1 false), !dbg [[META34]], !DIAssignID [[DIASSIGNID37:![0-9]+]]
+; CHECK-NEXT:      #dbg_assign(i1 undef, [[META28]], !DIExpression(DW_OP_LLVM_fragment, 80, 7840), [[DIASSIGNID37]], ptr [[ADD_PTR]], !DIExpression(), [[META34]])
+; CHECK-NEXT:    call void @_Z3escPc(ptr noundef nonnull [[BLOB]]), !dbg [[META34]]
+; CHECK-NEXT:    ret void, !dbg [[META34]]
+;
+entry:
+  %blob = alloca [1000 x i8], align 16, !DIAssignID !33
+  #dbg_assign(i1 undef, !28, !DIExpression(), !33, ptr %blob, !DIExpression(), !34)
+  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1000) %blob, i8 5, i64 1000, i1 false), !dbg !34, !DIAssignID !35
+  #dbg_assign(i1 undef, !28, !DIExpression(), !35, ptr %blob, !DIExpression(), !34)
+  %add.ptr = getelementptr inbounds i8, ptr %blob, i64 10, !dbg !34
+  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(980) %add.ptr, i8 3, i64 980, i1 false), !dbg !34, !DIAssignID !36
+  #dbg_assign(i1 undef, !28, !DIExpression(DW_OP_LLVM_fragment, 80, 7840), !36, ptr %add.ptr, !DIExpression(), !34)
+  call void @_Z3escPc(ptr noundef nonnull %blob), !dbg !34
+  ret void, !dbg !34
+}
+
+declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
+
+declare void @_Z3escPc(ptr noundef)
+
+declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!15, !16, !17, !18, !19, !20, !21}
+!llvm.ident = !{!22}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, imports: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debuginfo.cpp", directory: "/home", checksumkind: CSK_MD5, checksum: "3dc84462c14a3d86dd372d0473fa13aa")
+!2 = !{!3}
+!3 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !4, entity: !5, file: !14, line: 81)
+!4 = !DINamespace(name: "std", scope: null)
+!5 = !DISubprogram(name: "memset", scope: !6, file: !6, line: 61, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
+!6 = !DIFile(filename: "/usr/include/string.h", directory: "", checksumkind: CSK_MD5, checksum: "3fc3efdf2e52b973f380a6e7608374ff")
+!7 = !DISubroutineType(types: !8)
+!8 = !{!9, !9, !10, !11}
+!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !12, line: 13, baseType: !13)
+!12 = !DIFile(filename: "build_upstream/lib/clang/18/include/__stddef_size_t.h", directory: "/home", checksumkind: CSK_MD5, checksum: "405db6ea5fb824de326715f26fa9fab5")
+!13 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
+!14 = !DIFile(filename: "/usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/cstring", directory: "")
+!15 = !{i32 7, !"Dwarf Version", i32 5}
+!16 = !{i32 2, !"Debug Info Version", i32 3}
+!17 = !{i32 1, !"wchar_size", i32 4}
+!18 = !{i32 8, !"PIC Level", i32 2}
+!19 = !{i32 7, !"PIE Level", i32 2}
+!20 = !{i32 7, !"uwtable", i32 2}
+!21 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
+!22 = !{!"clang version 18.0.0"}
----------------
omern1 wrote:

I have whittled it down further but some of the metadata is used in the test by the `dbg_assign`s, is there anything else you think I should remove?

https://github.com/llvm/llvm-project/pull/75478


More information about the llvm-commits mailing list