[PATCH] D81939: [NOT FOR COMMIT] [deadargelim] Attach dbg info to the insert/extractvalue instructions

Djordje Todorovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 07:42:49 PDT 2020


djtodoro created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

The bug was found by the `LLVM DI Checker` and this will be used in the RFC for the utility.

Before this patch, the deadargelim pass does not attach any dbg location to `insertvalue/extractvalue` instructions. This fixes that.

TODO: Add another test case for the `extractvalue` case.


https://reviews.llvm.org/D81939

Files:
  llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
  llvm/test/Transforms/DeadArgElim/insertval-dbg-info.ll


Index: llvm/test/Transforms/DeadArgElim/insertval-dbg-info.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/DeadArgElim/insertval-dbg-info.ll
@@ -0,0 +1,41 @@
+; RUN: opt -deadargelim -S < %s | FileCheck %s
+
+; CHECK: %[[invoke:.*]] = invoke i32 @fn1()
+; CHECK: %[[oldret:.*]] = insertvalue { i32 } undef, i32 %[[invoke]], 0, !dbg
+
+define internal { i32 } @fn1() !dbg !4 {
+entry:
+  unreachable
+}
+
+define void @fn2() personality i32 (i32)* undef !dbg !8 {
+entry:
+  %tmp2 = invoke { i32 } @fn1()
+          to label %bb3 unwind label %bb4, !dbg !15
+bb3:
+  %tmp3 = phi { i32 } [ %tmp2, %entry ], !dbg !15
+  unreachable
+bb4:
+  %tmp4 = landingpad { i8*, i32 }
+          cleanup, !dbg !15
+  unreachable
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!12, !13}
+!llvm.ident = !{!14}
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 11", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2)
+!1 = !DIFile(filename: "test.cpp", directory: "/dir")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "fn1", line: 4, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 4, file: !1, scope: !5, type: !6, retainedNodes: !2)
+!5 = !DIFile(filename: "test.cpp", directory: "/dir")
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = distinct !DISubprogram(name: "fn2", line: 1, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !9, retainedNodes: !2)
+!9 = !DISubroutineType(types: !10)
+!10 = !{null, !11, null}
+!11 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!12 = !{i32 2, !"Dwarf Version", i32 4}
+!13 = !{i32 2, !"Debug Info Version", i32 3}
+!14 = !{!"clang version 11"}
+!15 = !DILocation(line: 1, column: 19, scope: !8)
Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
===================================================================
--- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -977,6 +977,7 @@
               V = NewCB;
             // Insert the value at the old position
             RetVal = InsertValueInst::Create(RetVal, V, Ri, "oldret", InsertPt);
+            cast<Instruction>(RetVal)->setDebugLoc(CB.getDebugLoc());
           }
         // Now, replace all uses of the old call instruction with the return
         // struct we built
@@ -1046,6 +1047,7 @@
                 // extracted value.
                 RetVal = EV;
               }
+              cast<Instruction>(RetVal)->setDebugLoc(RI->getDebugLoc());
             }
         }
         // Replace the return instruction with one returning the new return


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81939.271087.patch
Type: text/x-patch
Size: 2840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200616/2b52861b/attachment-0001.bin>


More information about the llvm-commits mailing list