[llvm] [Extractor][DebugInfo] Don't pick DebugLocs from dbg intrinsics (PR #80863)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 08:15:13 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Jeremy Morse (jmorse)

<details>
<summary>Changes</summary>

When picking the source location for a branch instruction in the CodeExtractor, we can end up picking the source location of a debugging intrinsic. This never makes sense because any variable assignment information (or labels) might originate from completely different lexical scopes that have been inlined, and also makes the line tables change between -g and -gmlt. Fix this by skipping debug intrinsics when looking for branch source locations.

Detected because of test differences with RemoveDIs, the non-intrinsinc form of debug-info -- fixing in intrinsic form to avoid there being spurious test differences when we turn it on.

---
Full diff: https://github.com/llvm/llvm-project/pull/80863.diff


3 Files Affected:

- (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+4) 
- (modified) llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll (+1-1) 
- (modified) llvm/test/Transforms/IROutliner/gvn-phi-debug.ll (+2-3) 


``````````diff
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 278111883459b..57d3926515993 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1769,6 +1769,10 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
       return any_of(*BB, [&BranchI](const Instruction &I) {
         if (!I.getDebugLoc())
           return false;
+        // Don't use source locations attached to debug-intrinsics: they could
+        // be from completely unrelated scopes.
+        if (isa<DbgInfoIntrinsic>(I))
+          return false;
         BranchI->setDebugLoc(I.getDebugLoc());
         return true;
       });
diff --git a/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll b/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
index 8209f93915e9c..97bb13d4bdcfb 100644
--- a/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
+++ b/llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
@@ -18,8 +18,8 @@ target triple = "x86_64-apple-macosx10.14.0"
 ; CHECK: [[FILE:![0-9]+]] = !DIFile
 ; CHECK: [[INLINE_ME_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "inline_me"
 ; CHECK: [[SCOPE:![0-9]+]] = distinct !DISubprogram(name: "foo.cold.1"
-; CHECK: [[LINE]] = !DILocation(line: 1, column: 1, scope: [[SCOPE]]
 ; CHECK: [[LABEL]] = !DILabel(scope: [[SCOPE]], name: "bye", file: [[FILE]], line: 28
+; CHECK: [[LINE]] = !DILocation(line: 1, column: 1, scope: [[SCOPE]]
 ; CHECK: [[LABEL_IN_INLINE_ME]] = !DILabel(scope: [[INLINE_ME_SCOPE]], name: "label_in_ at inline_me", file: [[FILE]], line: 29
 ; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[INLINE_ME_SCOPE]], inlinedAt: [[LINE]]
 ; CHECK: [[SCOPED_LABEL]] = !DILabel(scope: [[SCOPE_IN_FOO:![0-9]+]], name: "scoped_label_in_foo", file: [[FILE]], line: 30
diff --git a/llvm/test/Transforms/IROutliner/gvn-phi-debug.ll b/llvm/test/Transforms/IROutliner/gvn-phi-debug.ll
index 934bda1fc7c2e..217a8498ffbb3 100644
--- a/llvm/test/Transforms/IROutliner/gvn-phi-debug.ll
+++ b/llvm/test/Transforms/IROutliner/gvn-phi-debug.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
 ; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s | FileCheck %s
+; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s --try-experimental-debuginfo-iterators | FileCheck %s
 
 target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
 target triple = "thumbv7-none-linux-android19"
@@ -171,7 +172,5 @@ attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memo
 ; CHECK: [[DBG8]] = distinct !DISubprogram(name: "w", scope: [[META5]], file: [[META5]], line: 54, type: [[META9:![0-9]+]], scopeLine: 54, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META10:![0-9]+]])
 ; CHECK: [[META9]] = !DISubroutineType(types: [[META10]])
 ; CHECK: [[META10]] = !{}
-; CHECK: [[DBG11]] = !DILocation(line: 0, scope: [[META12:![0-9]+]])
-; CHECK: [[META12]] = distinct !DILexicalBlock(scope: [[META13:![0-9]+]], file: [[META5]], line: 56, column: 17)
-; CHECK: [[META13]] = distinct !DILexicalBlock(scope: [[DBG8]], file: [[META5]], line: 56, column: 11)
+; CHECK: [[DBG11]] = !DILocation(line: 0, scope: [[DBG8]])
 ;.

``````````

</details>


https://github.com/llvm/llvm-project/pull/80863


More information about the llvm-commits mailing list