[llvm] r256188 - Fix PR24563 (LiveDebugVariables unconditionally propagates all DBG_VALUEs)

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 12:03:01 PST 2015


Author: adrian
Date: Mon Dec 21 14:03:00 2015
New Revision: 256188

URL: http://llvm.org/viewvc/llvm-project?rev=256188&view=rev
Log:
Fix PR24563 (LiveDebugVariables unconditionally propagates all DBG_VALUEs)

LiveDebugVariables unconditionally propagates all DBG_VALUE down the
dominator tree, which happens to work fine if there already is another
DBG_VALUE or the DBG_VALUE happends to describe a single-assignment vreg
but is otherwise wrong if the DBG_VALUE is coming from only one of the
predecessors.

In r255759 we introduced a proper data flow analysis scheduled after
LiveDebugVariables that correctly propagates DBG_VALUEs across basic block
boundaries. With the new pass in place, the incorrect propagation in
LiveDebugVariables can be retired witout loosing any of the benefits
where LiveDebugVariables happened to do the right thing.

Added:
    llvm/trunk/test/DebugInfo/X86/bbjoin.ll
Modified:
    llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp
    llvm/trunk/test/DebugInfo/X86/live-debug-values.ll

Modified: llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp?rev=256188&r1=256187&r2=256188&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveDebugVariables.cpp Mon Dec 21 14:03:00 2015
@@ -534,65 +534,49 @@ bool LDVImpl::collectDebugValues(Machine
   return Changed;
 }
 
-void UserValue::extendDef(SlotIndex Idx, unsigned LocNo,
-                          LiveRange *LR, const VNInfo *VNI,
-                          SmallVectorImpl<SlotIndex> *Kills,
+/// We only propagate DBG_VALUES locally here. LiveDebugValues performs a
+/// data-flow analysis to propagate them beyond basic block boundaries.
+void UserValue::extendDef(SlotIndex Idx, unsigned LocNo, LiveRange *LR,
+                          const VNInfo *VNI, SmallVectorImpl<SlotIndex> *Kills,
                           LiveIntervals &LIS, MachineDominatorTree &MDT,
                           UserValueScopes &UVS) {
-  SmallVector<SlotIndex, 16> Todo;
-  Todo.push_back(Idx);
-  do {
-    SlotIndex Start = Todo.pop_back_val();
-    MachineBasicBlock *MBB = LIS.getMBBFromIndex(Start);
-    SlotIndex Stop = LIS.getMBBEndIdx(MBB);
-    LocMap::iterator I = locInts.find(Start);
-
-    // Limit to VNI's live range.
-    bool ToEnd = true;
-    if (LR && VNI) {
-      LiveInterval::Segment *Segment = LR->getSegmentContaining(Start);
-      if (!Segment || Segment->valno != VNI) {
-        if (Kills)
-          Kills->push_back(Start);
-        continue;
-      }
-      if (Segment->end < Stop)
-        Stop = Segment->end, ToEnd = false;
+  SlotIndex Start = Idx;
+  MachineBasicBlock *MBB = LIS.getMBBFromIndex(Start);
+  SlotIndex Stop = LIS.getMBBEndIdx(MBB);
+  LocMap::iterator I = locInts.find(Start);
+
+  // Limit to VNI's live range.
+  bool ToEnd = true;
+  if (LR && VNI) {
+    LiveInterval::Segment *Segment = LR->getSegmentContaining(Start);
+    if (!Segment || Segment->valno != VNI) {
+      if (Kills)
+        Kills->push_back(Start);
+      return;
     }
+    if (Segment->end < Stop)
+      Stop = Segment->end, ToEnd = false;
+  }
+
+  // There could already be a short def at Start.
+  if (I.valid() && I.start() <= Start) {
+    // Stop when meeting a different location or an already extended interval.
+    Start = Start.getNextSlot();
+    if (I.value() != LocNo || I.stop() != Start)
+      return;
+    // This is a one-slot placeholder. Just skip it.
+    ++I;
+  }
+
+  // Limited by the next def.
+  if (I.valid() && I.start() < Stop)
+    Stop = I.start(), ToEnd = false;
+  // Limited by VNI's live range.
+  else if (!ToEnd && Kills)
+    Kills->push_back(Stop);
 
-    // There could already be a short def at Start.
-    if (I.valid() && I.start() <= Start) {
-      // Stop when meeting a different location or an already extended interval.
-      Start = Start.getNextSlot();
-      if (I.value() != LocNo || I.stop() != Start)
-        continue;
-      // This is a one-slot placeholder. Just skip it.
-      ++I;
-    }
-
-    // Limited by the next def.
-    if (I.valid() && I.start() < Stop)
-      Stop = I.start(), ToEnd = false;
-    // Limited by VNI's live range.
-    else if (!ToEnd && Kills)
-      Kills->push_back(Stop);
-
-    if (Start >= Stop)
-      continue;
-
+  if (Start < Stop)
     I.insert(Start, Stop, LocNo);
-
-    // If we extended to the MBB end, propagate down the dominator tree.
-    if (!ToEnd)
-      continue;
-    const std::vector<MachineDomTreeNode*> &Children =
-      MDT.getNode(MBB)->getChildren();
-    for (unsigned i = 0, e = Children.size(); i != e; ++i) {
-      MachineBasicBlock *MBB = Children[i]->getBlock();
-      if (UVS.dominates(MBB))
-        Todo.push_back(LIS.getMBBStartIdx(MBB));
-    }
-  } while (!Todo.empty());
 }
 
 void

Added: llvm/trunk/test/DebugInfo/X86/bbjoin.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/bbjoin.ll?rev=256188&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/bbjoin.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/bbjoin.ll Mon Dec 21 14:03:00 2015
@@ -0,0 +1,101 @@
+; RUN: llc -mtriple=x86_64-apple-macosx10.9.0 %s -stop-after=livedebugvars \
+; RUN:   -o %t.s | FileCheck %s
+; Generated from:
+; void g(int *);
+; int f() {
+;   int x = 23;
+;   g(&x);
+;   if (x == 42)
+;     ++x;
+;   return x; // check that x is not a constant here.
+; }
+; CHECK: ![[X:.*]] = !DILocalVariable(name: "x",
+; CHECK: bb.0.entry:
+; CHECK:   DBG_VALUE 23, 0, ![[X]],
+; CHECK:   DBG_VALUE debug-use %rdi, debug-use _, ![[X]]
+; CHECK: bb.1.if.then:
+; CHECK:   DBG_VALUE debug-use %rdi, debug-use _, ![[X]],
+; CHECK: bb.2.if.end:
+; CHECK-NOT:  DBG_VALUE 23, 0, ![[X]],
+; CHECK:   RETQ %eax
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; Function Attrs: nounwind ssp uwtable
+define i32 @f() #0 !dbg !4 {
+entry:
+  %x = alloca i32, align 4
+  %0 = bitcast i32* %x to i8*, !dbg !14
+  call void @llvm.lifetime.start(i64 4, i8* %0) #4, !dbg !14
+  tail call void @llvm.dbg.value(metadata i32 23, i64 0, metadata !9, metadata !15), !dbg !16
+  store i32 23, i32* %x, align 4, !dbg !16, !tbaa !17
+  tail call void @llvm.dbg.value(metadata i32* %x, i64 0, metadata !9, metadata !15), !dbg !16
+  call void @g(i32* nonnull %x) #4, !dbg !21
+  call void @llvm.dbg.value(metadata i32* %x, i64 0, metadata !9, metadata !15), !dbg !16
+  %1 = load i32, i32* %x, align 4, !dbg !22, !tbaa !17
+  %cmp = icmp eq i32 %1, 42, !dbg !24
+  br i1 %cmp, label %if.then, label %if.end, !dbg !25
+
+if.then:                                          ; preds = %entry
+  call void @llvm.dbg.value(metadata i32 43, i64 0, metadata !9, metadata !15), !dbg !16
+  store i32 43, i32* %x, align 4, !dbg !26, !tbaa !17
+  br label %if.end, !dbg !26
+
+if.end:                                           ; preds = %if.then, %entry
+  %2 = phi i32 [ 43, %if.then ], [ %1, %entry ], !dbg !27
+  call void @llvm.dbg.value(metadata i32* %x, i64 0, metadata !9, metadata !15), !dbg !16
+  call void @llvm.lifetime.end(i64 4, i8* %0) #4, !dbg !28
+  ret i32 %2, !dbg !29
+}
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.start(i64, i8* nocapture) #1
+
+declare void @g(i32*) #4
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.end(i64, i8* nocapture) #1
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3
+
+attributes #0 = { nounwind ssp uwtable }
+attributes #1 = { argmemonly nounwind }
+attributes #3 = { nounwind readnone }
+attributes #4 = { nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!10, !11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 255890) (llvm/trunk 255919)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
+!1 = !DIFile(filename: "constant.c", directory: "")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, variables: !8)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!8 = !{!9}
+!9 = !DILocalVariable(name: "x", scope: !4, file: !1, line: 3, type: !7)
+!10 = !{i32 2, !"Dwarf Version", i32 2}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"PIC Level", i32 2}
+!13 = !{!"clang version 3.8.0 (trunk 255890) (llvm/trunk 255919)"}
+!14 = !DILocation(line: 3, column: 3, scope: !4)
+!15 = !DIExpression()
+!16 = !DILocation(line: 3, column: 7, scope: !4)
+!17 = !{!18, !18, i64 0}
+!18 = !{!"int", !19, i64 0}
+!19 = !{!"omnipotent char", !20, i64 0}
+!20 = !{!"Simple C/C++ TBAA"}
+!21 = !DILocation(line: 4, column: 3, scope: !4)
+!22 = !DILocation(line: 5, column: 7, scope: !23)
+!23 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 7)
+!24 = !DILocation(line: 5, column: 9, scope: !23)
+!25 = !DILocation(line: 5, column: 7, scope: !4)
+!26 = !DILocation(line: 6, column: 5, scope: !23)
+!27 = !DILocation(line: 7, column: 10, scope: !4)
+!28 = !DILocation(line: 8, column: 1, scope: !4)
+!29 = !DILocation(line: 7, column: 3, scope: !4)

Modified: llvm/trunk/test/DebugInfo/X86/live-debug-values.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/live-debug-values.ll?rev=256188&r1=256187&r2=256188&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/live-debug-values.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/live-debug-values.ll Mon Dec 21 14:03:00 2015
@@ -30,9 +30,8 @@
 ; DBG_VALUE for variable "n" is extended into BB#5 from its predecessors BB#3
 ; and BB#4.
 ; CHECK:       .LBB0_5:
-; CHECK-NEXT:  #DEBUG_VALUE: main:argv <- %RSI
 ; CHECK-NEXT:  #DEBUG_VALUE: main:n <- %EBX
-
+; CHECK-NEXT:  #DEBUG_VALUE: main:argv <- %RSI
 
 ; ModuleID = 'LiveDebugValues.c'
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"




More information about the llvm-commits mailing list