[PATCH] D100270: [debug-info] MemCpyOpt should merge the debug location when replace multiple block-local instruction with a new memset

Yuanbo Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 01:12:02 PDT 2021


yuanboli233 updated this revision to Diff 336769.
yuanboli233 added a comment.

Thanks for the suggestions from @djtodoro! Format revised and changed to SmallVector.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100270/new/

https://reviews.llvm.org/D100270

Files:
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
  llvm/test/Transforms/MemCpyOpt/memset-merged-loc.ll


Index: llvm/test/Transforms/MemCpyOpt/memset-merged-loc.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/MemCpyOpt/memset-merged-loc.ll
@@ -0,0 +1,50 @@
+; RUN: opt -memcpyopt -S < %s | FileCheck %s
+; CHECK: !{{[0-9]+}} = !DILocation(line: 0, scope: !{{[0-9]+}})
+
+; Function Attrs: ssp
+define void @test3(i32* %P) #0 !dbg !6 {
+entry:
+  %arrayidx = getelementptr inbounds i32, i32* %P, i64 1, !dbg !13
+  call void @llvm.dbg.value(metadata i32* %arrayidx, metadata !9, metadata !DIExpression()), !dbg !13
+  store i32 0, i32* %arrayidx, align 4, !dbg !14
+  %add.ptr = getelementptr inbounds i32, i32* %P, i64 2, !dbg !15
+  call void @llvm.dbg.value(metadata i32* %add.ptr, metadata !11, metadata !DIExpression()), !dbg !15
+  %0 = bitcast i32* %add.ptr to i8*, !dbg !16
+  call void @llvm.dbg.value(metadata i8* %0, metadata !12, metadata !DIExpression()), !dbg !16
+  tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 11, i1 false), !dbg !17
+  ret void, !dbg !18
+}
+
+; Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
+declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #1
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+attributes #0 = { ssp }
+attributes #1 = { argmemonly nofree nosync nounwind willreturn writeonly }
+attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!0}
+!llvm.debugify = !{!3, !4}
+!llvm.module.flags = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "bugpoint-reduced-simplified.bc", directory: "/")
+!2 = !{}
+!3 = !{i32 6}
+!4 = !{i32 3}
+!5 = !{i32 2, !"Debug Info Version", i32 3}
+!6 = distinct !DISubprogram(name: "test3", linkageName: "test3", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+!7 = !DISubroutineType(types: !2)
+!8 = !{!9, !11, !12}
+!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
+!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+!11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 3, type: !10)
+!12 = !DILocalVariable(name: "3", scope: !6, file: !1, line: 4, type: !10)
+!13 = !DILocation(line: 1, column: 1, scope: !6)
+!14 = !DILocation(line: 2, column: 1, scope: !6)
+!15 = !DILocation(line: 3, column: 1, scope: !6)
+!16 = !DILocation(line: 4, column: 1, scope: !6)
+!17 = !DILocation(line: 5, column: 1, scope: !6)
+!18 = !DILocation(line: 6, column: 1, scope: !6)
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -484,8 +484,14 @@
                                                    : Range.TheStores) dbgs()
                                               << *SI << '\n';
                dbgs() << "With: " << *AMemSet << '\n');
-    if (!Range.TheStores.empty())
-      AMemSet->setDebugLoc(Range.TheStores[0]->getDebugLoc());
+    if (!Range.TheStores.empty()) {
+      SmallVector<const DILocation *, 4> StoreLocs;
+      for (auto StoreInst : Range.TheStores) {
+        StoreLocs.push_back(StoreInst->getDebugLoc().get());
+      }
+      DebugLoc DgbLoc = DebugLoc(DILocation::getMergedLocations(StoreLocs));
+      AMemSet->setDebugLoc(DgbLoc);
+    }
 
     if (MSSAU) {
       assert(LastMemDef && MemInsertPoint &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100270.336769.patch
Type: text/x-patch
Size: 3713 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210412/5260e9e7/attachment.bin>


More information about the llvm-commits mailing list