https://github.com/clemenswasser updated 
https://github.com/llvm/llvm-project/pull/204817

>From 879a487e1eef0d4c2d9bbe2986307b15d1ee7088 Mon Sep 17 00:00:00 2001
From: Clemens Wasser <[email protected]>
Date: Thu, 18 Jun 2026 13:33:45 +0200
Subject: [PATCH 1/4] [Inliner] Use distinct DILocations for inlined
 instruction debug locs

---
 .../DebugInfo/Generic/debug-label-inline.c    |  2 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  | 35 +++++++++++--------
 .../Generic/assignment-tracking/inline/id.ll  |  4 +--
 .../DebugInfo/Generic/inline-dbg-values.ll    |  4 +--
 .../Generic/inline-debug-info-multiret.ll     |  2 +-
 .../DebugInfo/Generic/inline-debug-info.ll    |  2 +-
 .../DebugInfo/Generic/inline-no-debug-info.ll |  2 +-
 .../KeyInstructions/Generic/inline.ll         |  4 +--
 .../CodeExtractor/PartialInlineDebug.ll       |  4 +--
 .../PartialInlineVarArgsDebug.ll              |  2 +-
 .../Inline/X86/inline-landing-pad.ll          |  2 +-
 llvm/test/Transforms/Inline/debug-invoke.ll   |  2 +-
 .../Inline/dilocation-loop-metadata-update.ll |  4 +--
 .../Transforms/Inline/inline_dbg_declare.ll   |  2 +-
 .../SampleProfile/pseudo-probe-emit-inline.ll |  6 ++--
 15 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/clang/test/DebugInfo/Generic/debug-label-inline.c 
b/clang/test/DebugInfo/Generic/debug-label-inline.c
index 9d92ffb5ef61f..1dfb41a228ca7 100644
--- a/clang/test/DebugInfo/Generic/debug-label-inline.c
+++ b/clang/test/DebugInfo/Generic/debug-label-inline.c
@@ -25,4 +25,4 @@ int f2(void) {
 // CHECK: [[ELEMENTS]] = !{{{.*}}, [[LABEL_METADATA]]}
 // CHECK: [[LABEL_METADATA]] = !DILabel({{.*}}, name: "top", {{.*}}, line: 8, 
column: 1)
 // CHECK: [[INLINEDAT:!.*]] = distinct !DILocation(line: 18,
-// CHECK: [[LABEL_LOCATION]] = !DILocation(line: 8, {{.*}}, inlinedAt: 
[[INLINEDAT]])
+// CHECK: [[LABEL_LOCATION]] = distinct !DILocation(line: 8, {{.*}}, 
inlinedAt: [[INLINEDAT]])
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp 
b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index be186ffbf7e42..6c77b8849b3e1 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1933,13 +1933,18 @@ static bool allocaWouldBeStaticInEntry(const AllocaInst 
*AI ) {
 
 /// Returns a DebugLoc for a new DILocation which is a clone of \p OrigDL
 /// inlined at \p InlinedAt. \p IANodes is an inlined-at cache.
-static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
-                               LLVMContext &Ctx,
-                               DenseMap<const MDNode *, MDNode *> &IANodes) {
+static DebugLoc
+inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt, LLVMContext &Ctx,
+               DenseMap<const MDNode *, MDNode *> &IANodes,
+               DenseMap<const MDNode *, MDNode *> &InlineLocCache) {
+  if (MDNode *Cached = InlineLocCache.lookup(OrigDL.get()))
+    return DebugLoc(cast<DILocation>(Cached));
   auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
-  return DILocation::get(Ctx, OrigDL.getLine(), OrigDL.getCol(),
-                         OrigDL.getScope(), IA, OrigDL.isImplicitCode(),
-                         OrigDL->getAtomGroup(), OrigDL->getAtomRank());
+  DILocation *Result = DILocation::getDistinct(
+      Ctx, OrigDL.getLine(), OrigDL.getCol(), OrigDL.getScope(), IA,
+      OrigDL.isImplicitCode(), OrigDL->getAtomGroup(), OrigDL->getAtomRank());
+  InlineLocCache[OrigDL.get()] = Result;
+  return DebugLoc(Result);
 }
 
 /// Update inlined instructions' line numbers to
@@ -1969,6 +1974,7 @@ static void fixupLineNumbers(Function *Fn, 
Function::iterator FI,
   // this every instruction's inlined-at chain would become distinct from each
   // other.
   DenseMap<const MDNode *, MDNode *> IANodes;
+  DenseMap<const MDNode *, MDNode *> InlineLocCache;
 
   // Check if we are not generating inline line tables and want to use
   // the call site location instead.
@@ -1978,18 +1984,19 @@ static void fixupLineNumbers(Function *Fn, 
Function::iterator FI,
   auto UpdateInst = [&](Instruction &I) {
     // Loop metadata needs to be updated so that the start and end locs
     // reference inlined-at locations.
-    auto updateLoopInfoLoc = [&Ctx, &InlinedAtNode,
-                              &IANodes](Metadata *MD) -> Metadata * {
+    auto updateLoopInfoLoc = [&Ctx, &InlinedAtNode, &IANodes,
+                              &InlineLocCache](Metadata *MD) -> Metadata * {
       if (auto *Loc = dyn_cast_or_null<DILocation>(MD))
-        return inlineDebugLoc(Loc, InlinedAtNode, Ctx, IANodes).get();
+        return inlineDebugLoc(Loc, InlinedAtNode, Ctx, IANodes, InlineLocCache)
+            .get();
       return MD;
     };
     updateLoopMetadataDebugLocations(I, updateLoopInfoLoc);
 
     if (!NoInlineLineTables)
       if (DebugLoc DL = I.getDebugLoc()) {
-        DebugLoc IDL =
-            inlineDebugLoc(DL, InlinedAtNode, I.getContext(), IANodes);
+        DebugLoc IDL = inlineDebugLoc(DL, InlinedAtNode, I.getContext(),
+                                      IANodes, InlineLocCache);
         I.setDebugLoc(IDL);
         return;
       }
@@ -2025,9 +2032,9 @@ static void fixupLineNumbers(Function *Fn, 
Function::iterator FI,
       return;
     }
     DebugLoc DL = DVR->getDebugLoc();
-    DebugLoc IDL =
-        inlineDebugLoc(DL, InlinedAtNode,
-                       DVR->getMarker()->getParent()->getContext(), IANodes);
+    DebugLoc IDL = inlineDebugLoc(DL, InlinedAtNode,
+                                  DVR->getMarker()->getParent()->getContext(),
+                                  IANodes, InlineLocCache);
     DVR->setDebugLoc(IDL);
   };
 
diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/inline/id.ll 
b/llvm/test/DebugInfo/Generic/assignment-tracking/inline/id.ll
index e01b44ff75fdb..8b70a12e6b06e 100644
--- a/llvm/test/DebugInfo/Generic/assignment-tracking/inline/id.ll
+++ b/llvm/test/DebugInfo/Generic/assignment-tracking/inline/id.ll
@@ -21,8 +21,8 @@
 ; CHECK-NEXT: #dbg_assign(i32 5, [[val]], !DIExpression(), [[ID_1]], ptr 
%val.i1, !DIExpression(), [[dl_inline_1:![0-9]+]]
 ;
 ; CHECK-DAG: [[val]] = !DILocalVariable(name: "val",
-; CHECK-DAG: [[dl_inline_0]] = !DILocation({{.*}}inlinedAt
-; CHECK-DAG: [[dl_inline_1]] = !DILocation({{.*}}inlinedAt
+; CHECK-DAG: [[dl_inline_0]] = distinct !DILocation({{.*}}inlinedAt
+; CHECK-DAG: [[dl_inline_1]] = distinct !DILocation({{.*}}inlinedAt
 ; CHECK-DAG: [[ID_0]] = distinct !DIAssignID()
 ; CHECK-DAG: [[ID_1]] = distinct !DIAssignID()
 
diff --git a/llvm/test/DebugInfo/Generic/inline-dbg-values.ll 
b/llvm/test/DebugInfo/Generic/inline-dbg-values.ll
index 304e5810b88cb..4ace278df8612 100644
--- a/llvm/test/DebugInfo/Generic/inline-dbg-values.ll
+++ b/llvm/test/DebugInfo/Generic/inline-dbg-values.ll
@@ -53,9 +53,9 @@
 ; CHECK-DAG: ![[TESTSP:[0-9]+]] = distinct !DISubprogram(name: "test",
 ; CHECK-DAG: ![[KVAR]] = !DILocalVariable(name: "k",
 ; CHECK-DAG: ![[K2VAR]] = !DILocalVariable(name: "k2",
-; CHECK-DAG: ![[KLINE]] = !DILocation(line: 4, scope: ![[TESTSP]], inlinedAt: 
![[INLINESITE:[0-9]+]])
+; CHECK-DAG: ![[KLINE]] = distinct !DILocation(line: 4, scope: ![[TESTSP]], 
inlinedAt: ![[INLINESITE:[0-9]+]])
 ; CHECK-DAG: ![[INLINESITE]] = distinct !DILocation(line: 14, scope: 
![[INLINESITEBLOCK]])
-; CHECK-DAG: ![[GLINE]] = !DILocation(line: 5, scope: ![[TESTSP]], inlinedAt: 
![[INLINESITE:[0-9]+]])
+; CHECK-DAG: ![[GLINE]] = distinct !DILocation(line: 5, scope: ![[TESTSP]], 
inlinedAt: ![[INLINESITE:[0-9]+]])
 
 target triple = "x86_64--"
 
diff --git a/llvm/test/DebugInfo/Generic/inline-debug-info-multiret.ll 
b/llvm/test/DebugInfo/Generic/inline-debug-info-multiret.ll
index 07f28ed85bc12..b4fd07888ed5c 100644
--- a/llvm/test/DebugInfo/Generic/inline-debug-info-multiret.ll
+++ b/llvm/test/DebugInfo/Generic/inline-debug-info-multiret.ll
@@ -11,7 +11,7 @@
 ; The branch instruction has the source location of line 9 and its inlined 
location
 ; has the source location of line 14.
 ; CHECK: ![[INL:[0-9]+]] = distinct !DILocation(line: 14, scope: {{.*}})
-; CHECK: ![[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: ![[INL]])
+; CHECK: ![[MD]] = distinct !DILocation(line: 9, scope: {{.*}}, inlinedAt: 
![[INL]])
 
 ; ModuleID = 'test.cpp'
 target datalayout = 
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
diff --git a/llvm/test/DebugInfo/Generic/inline-debug-info.ll 
b/llvm/test/DebugInfo/Generic/inline-debug-info.ll
index 306243cf27bb6..5cf0fa54669a1 100644
--- a/llvm/test/DebugInfo/Generic/inline-debug-info.ll
+++ b/llvm/test/DebugInfo/Generic/inline-debug-info.ll
@@ -32,7 +32,7 @@
 ; The branch instruction has the source location of line 9 and its inlined 
location
 ; has the source location of line 14.
 ; CHECK: [[INL:![0-9]*]] = distinct !DILocation(line: 14, scope: {{.*}})
-; CHECK: [[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: [[INL]])
+; CHECK: [[MD]] = distinct !DILocation(line: 9, scope: {{.*}}, inlinedAt: 
[[INL]])
 
 ; ModuleID = 'test.cpp'
 target datalayout = 
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
diff --git a/llvm/test/DebugInfo/Generic/inline-no-debug-info.ll 
b/llvm/test/DebugInfo/Generic/inline-no-debug-info.ll
index f1db6c09f5fdd..54ca4bce1608d 100644
--- a/llvm/test/DebugInfo/Generic/inline-no-debug-info.ll
+++ b/llvm/test/DebugInfo/Generic/inline-no-debug-info.ll
@@ -24,7 +24,7 @@
 ; CHECK-DAG: [[A]] = !DILocation(line: 4, scope: !{{[0-9]+}})
 
 ; Debug location of the inlined code.
-; CHECK-DAG: [[B]] = !DILocation(line: 2, scope: !{{[0-9]+}}, inlinedAt: 
[[A_INL:![0-9]*]])
+; CHECK-DAG: [[B]] = distinct !DILocation(line: 2, scope: !{{[0-9]+}}, 
inlinedAt: [[A_INL:![0-9]*]])
 ; CHECK-DAG: [[A_INL]] = distinct !DILocation(line: 4, scope: !{{[0-9]+}})
 
 
diff --git a/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll 
b/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll
index 0d5cc6d4a44de..5e594615469d2 100644
--- a/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll
+++ b/llvm/test/DebugInfo/KeyInstructions/Generic/inline.ll
@@ -9,8 +9,8 @@
 ; CHECK-NEXT: store i32 %add.i, ptr %x.i, align 4, !dbg [[G1R1:!.*]]
 
 ; CHECK: distinct !DISubprogram(name: "g", {{.*}}keyInstructions: true)
-; CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
-; CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+; CHECK: [[G1R2]] = distinct !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+; CHECK: [[G1R1]] = distinct !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
 
 define hidden void @_Z1fi(i32 noundef %a) !dbg !11 {
 entry:
diff --git a/llvm/test/Transforms/CodeExtractor/PartialInlineDebug.ll 
b/llvm/test/Transforms/CodeExtractor/PartialInlineDebug.ll
index af01ea1421cf5..1bda5b84f3919 100644
--- a/llvm/test/Transforms/CodeExtractor/PartialInlineDebug.ll
+++ b/llvm/test/Transforms/CodeExtractor/PartialInlineDebug.ll
@@ -69,9 +69,9 @@ entry:
 ; CHECK: br label %if.then, !dbg ![[DBG6:[0-9]+]]
 
 ; CHECK: ![[DBG1]] = !DILocation(line: 10, column: 7,
-; CHECK: ![[DBG2]] = !DILocation(line: 10, column: 7,
+; CHECK: ![[DBG2]] = distinct !DILocation(line: 10, column: 7,
 ; CHECK: ![[DBG3]] = !DILocation(line: 110, column: 17,
-; CHECK: ![[DBG4]] = !DILocation(line: 110, column: 17,
+; CHECK: ![[DBG4]] = distinct !DILocation(line: 110, column: 17,
 ; CHECK: ![[DBG5]] = !DILocation(line: 110, column: 17,
 ; CHECK: ![[DBG6]] = !DILocation(line: 10, column: 7,
 
diff --git a/llvm/test/Transforms/CodeExtractor/PartialInlineVarArgsDebug.ll 
b/llvm/test/Transforms/CodeExtractor/PartialInlineVarArgsDebug.ll
index c68729ea231b9..a65a30595b1a1 100644
--- a/llvm/test/Transforms/CodeExtractor/PartialInlineVarArgsDebug.ll
+++ b/llvm/test/Transforms/CodeExtractor/PartialInlineVarArgsDebug.ll
@@ -31,7 +31,7 @@ entry:
 ; CHECK: br label %if.then, !dbg ![[DBG3:[0-9]+]]
 
 ; CHECK: ![[DBG1]] = !DILocation(line: 10, column: 7,
-; CHECK: ![[DBG2]] = !DILocation(line: 10, column: 7,
+; CHECK: ![[DBG2]] = distinct !DILocation(line: 10, column: 7,
 ; CHECK: ![[DBG3]] = !DILocation(line: 10, column: 7,
 
 
diff --git a/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll 
b/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll
index 8422a4c1082a9..9863d76387355 100644
--- a/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll
+++ b/llvm/test/Transforms/Inline/X86/inline-landing-pad.ll
@@ -66,7 +66,7 @@ bb:
 ; CHECK: [[DBG4]] = distinct !DISubprogram(name: "widget", linkageName: 
"widget", scope: [[META1]], file: [[META1]], line: 87, type: [[META5:![0-9]+]], 
scopeLine: 88, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: 
DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: 
[[META2]])
 ; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6:![0-9]+]])
 ; CHECK: [[META6]] = !{null}
-; CHECK: [[DBG7]] = !DILocation(line: 9, column: 7, scope: [[DBG8]], 
inlinedAt: [[META9:![0-9]+]])
+; CHECK: [[DBG7]] = distinct !DILocation(line: 9, column: 7, scope: [[DBG8]], 
inlinedAt: [[META9:![0-9]+]])
 ; CHECK: [[DBG8]] = distinct !DISubprogram(name: "baz", linkageName: "baz", 
scope: [[META1]], file: [[META1]], line: 7, type: [[META5]], scopeLine: 8, 
flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition 
| DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
 ; CHECK: [[META9]] = distinct !DILocation(line: 99, column: 17, scope: 
[[DBG4]])
 ; CHECK: [[DBG10]] = !DILocation(line: 9, column: 7, scope: [[DBG8]])
diff --git a/llvm/test/Transforms/Inline/debug-invoke.ll 
b/llvm/test/Transforms/Inline/debug-invoke.ll
index 45897fcaa70b8..403f072c685ec 100644
--- a/llvm/test/Transforms/Inline/debug-invoke.ll
+++ b/llvm/test/Transforms/Inline/debug-invoke.ll
@@ -5,7 +5,7 @@
 ; CHECK: invoke void @test()
 ; CHECK-NEXT: to label {{.*}} unwind label {{.*}}, !dbg [[INL_LOC:![0-9]+]]
 ; CHECK: [[SP:.*]] = distinct !DISubprogram(
-; CHECK: [[INL_LOC]] = !DILocation(line: 1, scope: [[SP]], inlinedAt: 
[[INL_AT:.*]])
+; CHECK: [[INL_LOC]] = distinct !DILocation(line: 1, scope: [[SP]], inlinedAt: 
[[INL_AT:.*]])
 ; CHECK: [[INL_AT]] = distinct !DILocation(line: 2, scope: [[SP]])
 
 declare void @test()
diff --git a/llvm/test/Transforms/Inline/dilocation-loop-metadata-update.ll 
b/llvm/test/Transforms/Inline/dilocation-loop-metadata-update.ll
index 1bc132663331b..1bee6fcbd982b 100644
--- a/llvm/test/Transforms/Inline/dilocation-loop-metadata-update.ll
+++ b/llvm/test/Transforms/Inline/dilocation-loop-metadata-update.ll
@@ -75,9 +75,9 @@ entry:
 ; CHECK: [[META16]] = !{!"llvm.loop.unroll.count", i32 1}
 ; CHECK: [[DBG17]] = distinct !DISubprogram(name: "f", scope: [[META1]], file: 
[[META1]], line: 9, type: [[META4]], scopeLine: 9, spFlags: DISPFlagDefinition 
| DISPFlagOptimized, unit: [[META0]])
 ; CHECK: [[LOOP18]] = distinct !{[[LOOP18]], [[META19:![0-9]+]], 
[[META21:![0-9]+]], [[META9]], [[META10]], [[META22:![0-9]+]]}
-; CHECK: [[META19]] = !DILocation(line: 6, column: 3, scope: [[DBG3]], 
inlinedAt: [[META20:![0-9]+]])
+; CHECK: [[META19]] = distinct !DILocation(line: 6, column: 3, scope: 
[[DBG3]], inlinedAt: [[META20:![0-9]+]])
 ; CHECK: [[META20]] = distinct !DILocation(line: 9, column: 12, scope: 
[[DBG17]])
-; CHECK: [[META21]] = !DILocation(line: 7, column: 22, scope: [[DBG3]], 
inlinedAt: [[META20]])
+; CHECK: [[META21]] = distinct !DILocation(line: 7, column: 22, scope: 
[[DBG3]], inlinedAt: [[META20]])
 ; CHECK: [[META22]] = !{!"llvm.loop.distribute.followup_all", [[META19]], 
[[META21]], [[META9]], [[META12]], [[META13]], [[META23:![0-9]+]]}
 ; CHECK: [[META23]] = !{!"llvm.loop.vectorize.followup_all", [[META19]], 
[[META21]], [[META9]], [[META15]], [[META16]]}
 ;.
diff --git a/llvm/test/Transforms/Inline/inline_dbg_declare.ll 
b/llvm/test/Transforms/Inline/inline_dbg_declare.ll
index 60f1c2e733b93..8734a618f6eb0 100644
--- a/llvm/test/Transforms/Inline/inline_dbg_declare.ll
+++ b/llvm/test/Transforms/Inline/inline_dbg_declare.ll
@@ -93,5 +93,5 @@ attributes #1 = { nounwind readnone }
 ; CHECK: [[FOO:![0-9]+]] = distinct !DISubprogram(name: "foo",
 ; CHECK: [[m23]] = !DILocalVariable(name: "x", arg: 1, scope: [[FOO]]
 ; CHECK: [[BAR:![0-9]+]] = distinct !DISubprogram(name: "bar",
-; CHECK: [[m24]] = !DILocation(line: 1, column: 17, scope: [[FOO]], inlinedAt: 
[[CALL_SITE:![0-9]+]])
+; CHECK: [[m24]] = distinct !DILocation(line: 1, column: 17, scope: [[FOO]], 
inlinedAt: [[CALL_SITE:![0-9]+]])
 ; CHECK: [[CALL_SITE]] = distinct !DILocation(line: 8, column: 14, scope: 
[[BAR]])
diff --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll 
b/llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
index 6403fe92bddc1..0ee836e89da00 100644
--- a/llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
+++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
@@ -50,16 +50,16 @@ define dso_local i32 @entry() !dbg !14 {
 
 ; CHECK-IL: ![[#SCOPE1:]] = distinct !DISubprogram(name: "foo2"
 ; CHECK-IL: ![[#SCOPE2:]] = distinct !DISubprogram(name: "foo"
-; CHECK-IL: ![[#DL1]] = !DILocation(line: 3, column: 1,  scope: ![[#SCOPE1]], 
inlinedAt: ![[#INL1:]])
+; CHECK-IL: ![[#DL1]] = distinct !DILocation(line: 3, column: 1,  scope: 
![[#SCOPE1]], inlinedAt: ![[#INL1:]])
 ; CHECK-IL: ![[#INL1]] = distinct !DILocation(line: 7, column: 3, scope: 
![[#BL1:]])
 ;; A discriminator of 455082007 which is 0x1b200017 in hexdecimal, stands for 
a direct call probe
 ;; with an index of 2 and a scale of 100%.
 ; CHECK-IL: ![[#BL1]] = !DILexicalBlockFile(scope: ![[#SCOPE2]], file: !1, 
discriminator: 455082007)
 ; CHECK-IL: ![[#SCOPE3:]] = distinct !DISubprogram(name: "entry"
-; CHECK-IL: ![[#DL2]] = !DILocation(line: 7, column: 3,  scope: ![[#SCOPE2]], 
inlinedAt: ![[#INL2:]])
+; CHECK-IL: ![[#DL2]] = distinct !DILocation(line: 7, column: 3,  scope: 
![[#SCOPE2]], inlinedAt: ![[#INL2:]])
 ; CHECK-IL: ![[#INL2]] = distinct !DILocation(line: 11, column: 3, scope: 
![[#BL2:]])
 ; CHECK-IL: ![[#BL2]] = !DILexicalBlockFile(scope: ![[#SCOPE3]], file: !1, 
discriminator: 455082007)
-; CHECK-IL: ![[#DL3]] = !DILocation(line: 3, column: 1,  scope: ![[#SCOPE1]], 
inlinedAt: ![[#INL3:]])
+; CHECK-IL: ![[#DL3]] = distinct !DILocation(line: 3, column: 1,  scope: 
![[#SCOPE1]], inlinedAt: ![[#INL3:]])
 ; CHECK-IL: ![[#INL3]] = distinct !DILocation(line: 7, column: 3,  scope: 
![[#BL1]], inlinedAt: ![[#INL2]])
 
 

>From e9eca6e07cbd2ba2f4056c4f4a57101a5d2e0d70 Mon Sep 17 00:00:00 2001
From: Clemens Wasser <[email protected]>
Date: Thu, 18 Jun 2026 13:37:13 +0200
Subject: [PATCH 2/4] [Inliner] Use find() instead of operator[] in
 appendInlinedAt cache

---
 llvm/lib/IR/DebugLoc.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index c5eda4e81b1ce..72f515b0aa14a 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -133,8 +133,9 @@ DebugLoc DebugLoc::appendInlinedAt(const DebugLoc &DL, 
DILocation *InlinedAt,
   // Gather all the inlined-at nodes.
   while (DILocation *IA = CurInlinedAt->getInlinedAt()) {
     // Skip any we've already built nodes for.
-    if (auto *Found = Cache[IA]) {
-      Last = cast<DILocation>(Found);
+    auto It = Cache.find(IA);
+    if (It != Cache.end() && It->second) {
+      Last = cast<DILocation>(It->second);
       break;
     }
 

>From 4206e4d89ae7424cc3e8f61911ebc29a03bd4bea Mon Sep 17 00:00:00 2001
From: Clemens Wasser <[email protected]>
Date: Thu, 18 Jun 2026 13:37:35 +0200
Subject: [PATCH 3/4] [Inliner] Fast-path appendInlinedAt for leaf DebugLocs

---
 llvm/lib/Transforms/Utils/InlineFunction.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp 
b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 6c77b8849b3e1..2792817fc5157 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1939,7 +1939,10 @@ inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt, 
LLVMContext &Ctx,
                DenseMap<const MDNode *, MDNode *> &InlineLocCache) {
   if (MDNode *Cached = InlineLocCache.lookup(OrigDL.get()))
     return DebugLoc(cast<DILocation>(Cached));
-  auto IA = DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes);
+  DILocation *IA =
+      OrigDL->getInlinedAt()
+          ? DebugLoc::appendInlinedAt(OrigDL, InlinedAt, Ctx, IANodes).get()
+          : InlinedAt;
   DILocation *Result = DILocation::getDistinct(
       Ctx, OrigDL.getLine(), OrigDL.getCol(), OrigDL.getScope(), IA,
       OrigDL.isImplicitCode(), OrigDL->getAtomGroup(), OrigDL->getAtomRank());

>From 504a8eb7bd3613a003011ee2f6e980074f05cf62 Mon Sep 17 00:00:00 2001
From: Clemens Wasser <[email protected]>
Date: Fri, 19 Jun 2026 15:17:56 +0200
Subject: [PATCH 4/4] [Inliner] Fix Transforms/SafeStack/ARM/debug.ll test

---
 llvm/test/Transforms/SafeStack/ARM/debug.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/Transforms/SafeStack/ARM/debug.ll 
b/llvm/test/Transforms/SafeStack/ARM/debug.ll
index 89c70b7ffd2a7..ea698406094e6 100644
--- a/llvm/test/Transforms/SafeStack/ARM/debug.ll
+++ b/llvm/test/Transforms/SafeStack/ARM/debug.ll
@@ -12,7 +12,7 @@ target triple = "armv7-pc-linux-android"
 ; void Capture(char*x);
 ; void f() { char c[16]; Capture(c); }
 
-; CHECK: !36 = !DILocation(line: 3, column: 11, scope: !17, inlinedAt: !37)
+; CHECK: !36 = distinct !DILocation(line: 3, column: 11, scope: !17, 
inlinedAt: !37)
 ; CHECK: !37 = distinct !DILocation(line: 6, scope: !27)
 
 @addr = common local_unnamed_addr global ptr null, align 4, !dbg !0

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to