[llvm] r324982 - [Utils] Salvage debug info from all no-op casts

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 19:34:23 PST 2018


Author: vedantk
Date: Mon Feb 12 19:34:23 2018
New Revision: 324982

URL: http://llvm.org/viewvc/llvm-project?rev=324982&view=rev
Log:
[Utils] Salvage debug info from all no-op casts

We already try to salvage debug values from no-op bitcasts and inttoptr
instructions: we should handle ptrtoint instructions as well.

This saves an additional 24,444 debug values in a stage2 build of clang,
and (according to llvm-dwarfdump --statistics) provides an additional
289 unique source variables.

Modified:
    llvm/trunk/lib/Transforms/Utils/Local.cpp
    llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll

Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=324982&r1=324981&r2=324982&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Feb 12 19:34:23 2018
@@ -1518,11 +1518,14 @@ void llvm::salvageDebugInfo(Instruction
     doSalvage(DII, Ops);
   };
 
-  if (isa<BitCastInst>(&I) || isa<IntToPtrInst>(&I)) {
-    // Bitcasts are entirely irrelevant for debug info. Rewrite dbg.value,
-    // dbg.addr, and dbg.declare to use the cast's source.
+  if (auto *CI = dyn_cast<CastInst>(&I)) {
+    if (!CI->isNoopCast(M.getDataLayout()))
+      return;
+
+    // No-op casts are irrelevant for debug info.
+    MetadataAsValue *CastSrc = wrapMD(I.getOperand(0));
     for (auto *DII : DbgUsers) {
-      DII->setOperand(0, wrapMD(I.getOperand(0)));
+      DII->setOperand(0, CastSrc);
       DEBUG(dbgs() << "SALVAGE: " << *DII << '\n');
     }
   } else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {

Modified: llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll?rev=324982&r1=324981&r2=324982&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/debuginfo-variables.ll Mon Feb 12 19:34:23 2018
@@ -80,6 +80,13 @@ define void @test_srem(i64 %A) {
   ret void
 }
 
+define void @test_ptrtoint(i64* %P) {
+; CHECK-LABEL: @test_ptrtoint
+; CHECK-NEXT:  call void @llvm.dbg.value(metadata i64* %P, metadata !67, metadata !DIExpression()), !dbg !68
+  %1 = ptrtoint i64* %P to i64
+  ret void
+}
+
 ; CHECK: !8 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !9)
 ; CHECK: !10 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 2, type: !11)
 ; CHECK: !12 = !DILocation(line: 2, column: 1, scope: !5)
@@ -114,3 +121,6 @@ define void @test_srem(i64 %A) {
 
 ; CHECK: !62 = !DILocalVariable(name: "12", scope: !60, file: !1, line: 22, type: !11)
 ; CHECK: !63 = !DILocation(line: 22, column: 1, scope: !60)
+
+; CHECK: !67 = !DILocalVariable(name: "13", scope: !65, file: !1, line: 24, type: !11)
+; CHECK: !68 = !DILocation(line: 24, column: 1, scope: !65)




More information about the llvm-commits mailing list