[llvm] 9b56cc9 - [DebugInfo] Salvage debug info when sinking loop invariant instructions

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 3 01:27:35 PDT 2020


Author: OCHyams
Date: 2020-04-03T09:19:26+01:00
New Revision: 9b56cc9361a471a3ce57da4c98f60e377cc43026

URL: https://github.com/llvm/llvm-project/commit/9b56cc9361a471a3ce57da4c98f60e377cc43026
DIFF: https://github.com/llvm/llvm-project/commit/9b56cc9361a471a3ce57da4c98f60e377cc43026.diff

LOG: [DebugInfo] Salvage debug info when sinking loop invariant instructions

Reviewed By: vsk, aprantl, djtodoro

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

Added: 
    llvm/test/DebugInfo/X86/licm-undef-dbg-value.ll

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index fbb01fe1563e..731089f929ff 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -501,6 +501,7 @@ bool llvm::sinkRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
         if (sink(I, LI, DT, CurLoop, SafetyInfo, MSSAU, ORE)) {
           if (!FreeInLoop) {
             ++II;
+            salvageDebugInfoOrMarkUndef(I);
             eraseInstruction(I, *SafetyInfo, CurAST, MSSAU);
           }
           Changed = true;

diff  --git a/llvm/test/DebugInfo/X86/licm-undef-dbg-value.ll b/llvm/test/DebugInfo/X86/licm-undef-dbg-value.ll
new file mode 100644
index 000000000000..09a18f937b3b
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/licm-undef-dbg-value.ll
@@ -0,0 +1,86 @@
+; RUN: opt -licm %s -S | FileCheck %s
+
+; CHECK: for.body:
+; CHECK-NEXT: llvm.dbg.value(metadata i8 undef
+
+; The load is loop invariant. Check that we leave an undef dbg.value behind
+; when licm sinks the instruction.
+
+; clang reduce.cpp -g -O2 -Xclang -disable-llvm-passes -emit-llvm -o reduce.ll
+; opt -simplifycfg -sroa -loop-rotate -o - -S reduce.ll
+; cat reduce.cpp
+; extern char a;
+; extern char b;
+; void use(char);
+; void fun() {
+;   char local = 0;
+;   for (;b;)
+;     local = a;
+;   use(local);
+; }
+
+ at b = external dso_local global i8, align 1
+ at a = external dso_local global i8, align 1
+
+define dso_local void @_Z3funv() !dbg !12 {
+entry:
+  call void @llvm.dbg.value(metadata i8 0, metadata !16, metadata !DIExpression()), !dbg !17
+  %0 = load i8, i8* @b, align 1, !dbg !18
+  %tobool1 = icmp ne i8 %0, 0, !dbg !18
+  br i1 %tobool1, label %for.body.lr.ph, label %for.end, !dbg !24
+
+for.body.lr.ph:                                   ; preds = %entry
+  br label %for.body, !dbg !24
+
+for.body:                                         ; preds = %for.body.lr.ph, %for.body
+  %1 = load i8, i8* @a, align 1, !dbg !25
+  call void @llvm.dbg.value(metadata i8 %1, metadata !16, metadata !DIExpression()), !dbg !17
+  %2 = load i8, i8* @b, align 1, !dbg !18
+  %tobool = icmp ne i8 %2, 0, !dbg !18
+  br i1 %tobool, label %for.body, label %for.cond.for.end_crit_edge, !dbg !24, !llvm.loop !26
+
+for.cond.for.end_crit_edge:                       ; preds = %for.body
+  %split = phi i8 [ %1, %for.body ]
+  br label %for.end, !dbg !24
+
+for.end:                                          ; preds = %for.cond.for.end_crit_edge, %entry
+  %local.0.lcssa = phi i8 [ %split, %for.cond.for.end_crit_edge ], [ 0, %entry ], !dbg !17
+  call void @llvm.dbg.value(metadata i8 %local.0.lcssa, metadata !16, metadata !DIExpression()), !dbg !17
+  call void @_Z3usec(i8 signext %local.0.lcssa), !dbg !28
+  ret void, !dbg !29
+}
+
+declare !dbg !4 dso_local void @_Z3usec(i8 signext)
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "reduce.cpp", directory: "/")
+!2 = !{}
+!3 = !{!4}
+!4 = !DISubprogram(name: "use", linkageName: "_Z3usec", scope: !1, file: !1, line: 3, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null, !7}
+!7 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!8 = !{i32 7, !"Dwarf Version", i32 4}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{i32 1, !"wchar_size", i32 4}
+!11 = !{!"clang version 11.0.0"}
+!12 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 4, type: !13, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
+!13 = !DISubroutineType(types: !14)
+!14 = !{null}
+!15 = !{!16}
+!16 = !DILocalVariable(name: "local", scope: !12, file: !1, line: 5, type: !7)
+!17 = !DILocation(line: 0, scope: !12)
+!18 = !DILocation(line: 6, column: 9, scope: !19)
+!19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 6, column: 3)
+!20 = distinct !DILexicalBlock(scope: !12, file: !1, line: 6, column: 3)
+!24 = !DILocation(line: 6, column: 3, scope: !20)
+!25 = !DILocation(line: 7, column: 13, scope: !19)
+!26 = distinct !{!26, !24, !27}
+!27 = !DILocation(line: 7, column: 13, scope: !20)
+!28 = !DILocation(line: 8, column: 3, scope: !12)
+!29 = !DILocation(line: 9, column: 1, scope: !12)


        


More information about the llvm-commits mailing list