[llvm] r261145 - Debug Info: Teach LdStHasDebugValue() (Local.cpp) about DIExpressions.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 17 12:02:26 PST 2016


Author: adrian
Date: Wed Feb 17 14:02:25 2016
New Revision: 261145

URL: http://llvm.org/viewvc/llvm-project?rev=261145&view=rev
Log:
Debug Info: Teach LdStHasDebugValue() (Local.cpp) about DIExpressions.
This function is used to check whether a dbg.value intrinsic has already
been inserted, but without comparing the DIExpression, it would erroneously
fire on split aggregates and only the first scalar would survive.

Found via http://reviews.llvm.org/D16867.
<rdar://problem/24456528>

Added:
    llvm/trunk/test/DebugInfo/ARM/sroa-complex.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/Local.cpp

Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=261145&r1=261144&r2=261145&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Wed Feb 17 14:02:25 2016
@@ -1025,7 +1025,8 @@ unsigned llvm::getOrEnforceKnownAlignmen
 ///
 
 /// See if there is a dbg.value intrinsic for DIVar before I.
-static bool LdStHasDebugValue(const DILocalVariable *DIVar, Instruction *I) {
+static bool LdStHasDebugValue(DILocalVariable *DIVar, DIExpression *DIExpr,
+                              Instruction *I) {
   // Since we can't guarantee that the original dbg.declare instrinsic
   // is removed by LowerDbgDeclare(), we need to make sure that we are
   // not inserting the same dbg.value intrinsic over and over.
@@ -1035,7 +1036,8 @@ static bool LdStHasDebugValue(const DILo
     if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(PrevI))
       if (DVI->getValue() == I->getOperand(0) &&
           DVI->getOffset() == 0 &&
-          DVI->getVariable() == DIVar)
+          DVI->getVariable() == DIVar &&
+          DVI->getExpression() == DIExpr)
         return true;
   }
   return false;
@@ -1049,9 +1051,6 @@ bool llvm::ConvertDebugDeclareToDebugVal
   auto *DIExpr = DDI->getExpression();
   assert(DIVar && "Missing variable");
 
-  if (LdStHasDebugValue(DIVar, SI))
-    return true;
-
   // If an argument is zero extended then use argument directly. The ZExt
   // may be zapped by an optimization pass in future.
   Argument *ExtendedArg = nullptr;
@@ -1066,25 +1065,25 @@ bool llvm::ConvertDebugDeclareToDebugVal
     // to the alloca described by DDI, if it's first operand is an extend,
     // we're guaranteed that before extension, the value was narrower than
     // the size of the alloca, hence the size of the described variable.
-    SmallVector<uint64_t, 3> NewDIExpr;
+    SmallVector<uint64_t, 3> Ops;
     unsigned PieceOffset = 0;
     // If this already is a bit piece, we drop the bit piece from the expression
     // and record the offset.
     if (DIExpr->isBitPiece()) {
-      NewDIExpr.append(DIExpr->elements_begin(), DIExpr->elements_end()-3);
+      Ops.append(DIExpr->elements_begin(), DIExpr->elements_end()-3);
       PieceOffset = DIExpr->getBitPieceOffset();
     } else {
-      NewDIExpr.append(DIExpr->elements_begin(), DIExpr->elements_end());
+      Ops.append(DIExpr->elements_begin(), DIExpr->elements_end());
     }
-    NewDIExpr.push_back(dwarf::DW_OP_bit_piece);
-    NewDIExpr.push_back(PieceOffset); //Offset
+    Ops.push_back(dwarf::DW_OP_bit_piece);
+    Ops.push_back(PieceOffset); // Offset
     const DataLayout &DL = DDI->getModule()->getDataLayout();
-    NewDIExpr.push_back(DL.getTypeSizeInBits(ExtendedArg->getType())); // Size
-    Builder.insertDbgValueIntrinsic(ExtendedArg, 0, DIVar,
-                                    Builder.createExpression(NewDIExpr),
-                                    DDI->getDebugLoc(), SI);
-  }
-  else
+    Ops.push_back(DL.getTypeSizeInBits(ExtendedArg->getType())); // Size
+    auto NewDIExpr = Builder.createExpression(Ops);
+    if (!LdStHasDebugValue(DIVar, NewDIExpr, SI))
+      Builder.insertDbgValueIntrinsic(ExtendedArg, 0, DIVar, NewDIExpr,
+                                      DDI->getDebugLoc(), SI);
+  } else if (!LdStHasDebugValue(DIVar, DIExpr, SI))
     Builder.insertDbgValueIntrinsic(SI->getOperand(0), 0, DIVar, DIExpr,
                                     DDI->getDebugLoc(), SI);
   return true;
@@ -1098,7 +1097,7 @@ bool llvm::ConvertDebugDeclareToDebugVal
   auto *DIExpr = DDI->getExpression();
   assert(DIVar && "Missing variable");
 
-  if (LdStHasDebugValue(DIVar, LI))
+  if (LdStHasDebugValue(DIVar, DIExpr, LI))
     return true;
 
   // We are now tracking the loaded value instead of the address. In the

Added: llvm/trunk/test/DebugInfo/ARM/sroa-complex.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/ARM/sroa-complex.ll?rev=261145&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/ARM/sroa-complex.ll (added)
+++ llvm/trunk/test/DebugInfo/ARM/sroa-complex.ll Wed Feb 17 14:02:25 2016
@@ -0,0 +1,60 @@
+; RUN: opt -sroa -S -o - %s | FileCheck %s
+; REQUIRES: object-emission
+target datalayout = "e-m:o-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "thumbv7-apple-unknown-macho"
+
+; generated from (-triple thumbv7-apple-unknown-macho):
+;   void f(_Complex double c) { c = 0; }
+
+; Function Attrs: nounwind
+define arm_aapcscc void @f([2 x i64] %c.coerce) #0 !dbg !4 {
+entry:
+  %c = alloca { double, double }, align 8
+  %0 = bitcast { double, double }* %c to [2 x i64]*
+  store [2 x i64] %c.coerce, [2 x i64]* %0, align 8
+  call void @llvm.dbg.declare(metadata { double, double }* %c, metadata !14, metadata !15), !dbg !16
+  %c.realp = getelementptr inbounds { double, double }, { double, double }* %c, i32 0, i32 0, !dbg !17
+  %c.imagp = getelementptr inbounds { double, double }, { double, double }* %c, i32 0, i32 1, !dbg !17
+  store double 0.000000e+00, double* %c.realp, align 8, !dbg !17
+  ; SROA will split the complex double into two i64 values, because there is
+  ; no native double data type available.
+  ; Test that debug info for both values survives:
+  ; CHECK: call void @llvm.dbg.value(metadata i64 0, i64 0,
+  ; CHECK-SAME:                      metadata ![[C:.*]], metadata ![[REAL:.*]])
+  store double 0.000000e+00, double* %c.imagp, align 8, !dbg !17
+  ; CHECK: call void @llvm.dbg.value(metadata i64 0, i64 0,
+  ; CHECK-SAME:                      metadata ![[C]], metadata ![[IMG:.*]])
+  ret void, !dbg !18
+}
+; CHECK: ![[REAL]] = !DIExpression(DW_OP_bit_piece, 0, 64)
+; CHECK: ![[IMG]] = !DIExpression(DW_OP_bit_piece, 64, 64)
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10, !11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 259998) (llvm/trunk 259999)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
+!1 = !DIFile(filename: "<stdin>", directory: "/")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DISubprogram(name: "f", scope: !5, file: !5, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, variables: !2)
+!5 = !DIFile(filename: "test.c", directory: "/")
+!6 = !DISubroutineType(types: !7)
+!7 = !{null, !8}
+!8 = !DIBasicType(name: "complex", size: 128, align: 64, encoding: DW_ATE_complex_float)
+!9 = !{i32 2, !"Dwarf Version", i32 2}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{i32 1, !"wchar_size", i32 4}
+!12 = !{i32 1, !"min_enum_size", i32 4}
+!13 = !{!"clang version 3.9.0 (trunk 259998) (llvm/trunk 259999)"}
+!14 = !DILocalVariable(name: "c", arg: 1, scope: !4, file: !5, line: 1, type: !8)
+!15 = !DIExpression()
+!16 = !DILocation(line: 1, column: 24, scope: !4)
+!17 = !DILocation(line: 1, column: 31, scope: !4)
+!18 = !DILocation(line: 1, column: 36, scope: !4)




More information about the llvm-commits mailing list