[llvm] 98c1d11 - [Assignment Tracking][16/*] Account for assignment tracking in mldst-motion

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 03:30:46 PST 2022


Author: OCHyams
Date: 2022-11-15T11:28:20Z
New Revision: 98c1d11492a61884b63dda7aa8f201443ff0e402

URL: https://github.com/llvm/llvm-project/commit/98c1d11492a61884b63dda7aa8f201443ff0e402
DIFF: https://github.com/llvm/llvm-project/commit/98c1d11492a61884b63dda7aa8f201443ff0e402.diff

LOG: [Assignment Tracking][16/*] Account for assignment tracking in mldst-motion

The Assignment Tracking debug-info feature is outlined in this RFC:
https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

mldst-motion will merge and sink the stores in if-diamond branches into the
common successor. Attach a merged DIAssignID to the merged store.

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D133311

Added: 
    llvm/test/DebugInfo/Generic/assignment-tracking/mldst-motion/diamond.ll

Modified: 
    llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp b/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
index 5f4d12040cc34..253a850d9479c 100644
--- a/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
+++ b/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
@@ -250,6 +250,7 @@ void MergedLoadStoreMotion::sinkStoresAndGEPs(BasicBlock *BB, StoreInst *S0,
   S0->andIRFlags(S1);
   S0->dropUnknownNonDebugMetadata();
   S0->applyMergedLocation(S0->getDebugLoc(), S1->getDebugLoc());
+  S0->mergeDIAssignID(S1);
 
   // Create the new store to be inserted at the join point.
   StoreInst *SNew = cast<StoreInst>(S0->clone());

diff  --git a/llvm/test/DebugInfo/Generic/assignment-tracking/mldst-motion/diamond.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/mldst-motion/diamond.ll
new file mode 100644
index 0000000000000..3270c2566bc5a
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/assignment-tracking/mldst-motion/diamond.ll
@@ -0,0 +1,107 @@
+; RUN: opt -passes=mldst-motion -S %s -o - -experimental-assignment-tracking \
+; RUN: | FileCheck %s
+
+;; $ cat test.cpp
+;; int cond;
+;; void esc(int*);
+;; void fun() {
+;;   int a[4];
+;;   if (cond)
+;;     a[1] = 1;
+;;   else
+;;     a[1] = 2;
+;;   esc(a);
+;; }
+;;
+;;
+;; mldst-motion will merge and sink the stores in if.then and if.else into
+;; if.end. Ensure the merged store has a DIAssignID linking it to the two
+;; dbg.assign intrinsics which have been left in their original blocks.
+
+; CHECK: if.then:
+; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 1,{{.+}}, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata ![[ID:[0-9]+]], metadata ptr %1, metadata !DIExpression())
+
+; CHECK: if.else:
+; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 2,{{.+}}, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata ![[ID]], metadata ptr %1, metadata !DIExpression())
+
+; CHECK: if.end:
+; CHECK: store i32 %.sink, ptr %1, align 4{{.+}}, !DIAssignID ![[ID]]
+
+ at cond = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
+
+define dso_local void @_Z3funv() !dbg !11 {
+entry:
+  %a = alloca [4 x i32], align 16, !DIAssignID !19
+  call void @llvm.dbg.assign(metadata i1 undef, metadata !15, metadata !DIExpression(), metadata !19, metadata ptr %a, metadata !DIExpression()), !dbg !20
+  call void @llvm.lifetime.start.p0i8(i64 16, ptr nonnull %a) #4, !dbg !21
+  %0 = load i32, i32* @cond, align 4, !dbg !22
+  %tobool.not = icmp eq i32 %0, 0, !dbg !22
+  br i1 %tobool.not, label %if.else, label %if.then, !dbg !28
+
+if.then:                                          ; preds = %entry
+  %arrayidx = getelementptr inbounds [4 x i32], ptr %a, i64 0, i64 1, !dbg !29
+  store i32 1, ptr %arrayidx, align 4, !dbg !30, !DIAssignID !31
+  call void @llvm.dbg.assign(metadata i32 1, metadata !15, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !31, metadata ptr %arrayidx, metadata !DIExpression()), !dbg !20
+  br label %if.end, !dbg !29
+
+if.else:                                          ; preds = %entry
+  %arrayidx1 = getelementptr inbounds [4 x i32], ptr %a, i64 0, i64 1, !dbg !32
+  store i32 2, ptr %arrayidx1, align 4, !dbg !33, !DIAssignID !34
+  call void @llvm.dbg.assign(metadata i32 2, metadata !15, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32), metadata !34, metadata ptr %arrayidx1, metadata !DIExpression()), !dbg !20
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+  %arraydecay = getelementptr inbounds [4 x i32], ptr %a, i64 0, i64 0, !dbg !35
+  call void @_Z3escPi(ptr noundef nonnull %arraydecay), !dbg !36
+  call void @llvm.lifetime.end.p0i8(i64 16, ptr nonnull %a) #4, !dbg !37
+  ret void, !dbg !37
+}
+
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
+declare !dbg !38 dso_local void @_Z3escPi(i32* noundef)
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
+declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!6, !7, !8, !9}
+!llvm.ident = !{!10}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "cond", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "test.cpp", directory: "/")
+!4 = !{!0}
+!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!6 = !{i32 7, !"Dwarf Version", i32 5}
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{i32 1, !"wchar_size", i32 4}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{!"clang version 14.0.0"}
+!11 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !3, file: !3, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14)
+!12 = !DISubroutineType(types: !13)
+!13 = !{null}
+!14 = !{!15}
+!15 = !DILocalVariable(name: "a", scope: !11, file: !3, line: 4, type: !16)
+!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !5, size: 128, elements: !17)
+!17 = !{!18}
+!18 = !DISubrange(count: 4)
+!19 = distinct !DIAssignID()
+!20 = !DILocation(line: 0, scope: !11)
+!21 = !DILocation(line: 4, column: 3, scope: !11)
+!22 = !DILocation(line: 5, column: 7, scope: !23)
+!23 = distinct !DILexicalBlock(scope: !11, file: !3, line: 5, column: 7)
+!28 = !DILocation(line: 5, column: 7, scope: !11)
+!29 = !DILocation(line: 6, column: 5, scope: !23)
+!30 = !DILocation(line: 6, column: 10, scope: !23)
+!31 = distinct !DIAssignID()
+!32 = !DILocation(line: 8, column: 5, scope: !23)
+!33 = !DILocation(line: 8, column: 10, scope: !23)
+!34 = distinct !DIAssignID()
+!35 = !DILocation(line: 9, column: 7, scope: !11)
+!36 = !DILocation(line: 9, column: 3, scope: !11)
+!37 = !DILocation(line: 10, column: 1, scope: !11)
+!38 = !DISubprogram(name: "esc", linkageName: "_Z3escPi", scope: !3, file: !3, line: 2, type: !39, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !42)
+!39 = !DISubroutineType(types: !40)
+!40 = !{null, !41}
+!41 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
+!42 = !{}


        


More information about the llvm-commits mailing list