[llvm] [PseudoProbe] Preserve probe identity for inlined nodebug calls (PR #219079)

Kunal Pathak via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 17:56:30 PDT 2026


https://github.com/kunalspathak updated https://github.com/llvm/llvm-project/pull/219079

>From 94c99f5080bb6a7b54beef6693374d7b3f16fe7d Mon Sep 17 00:00:00 2001
From: Kunal Pathak <kupathak at fb.com>
Date: Wed, 12 Aug 2026 17:34:32 -0700
Subject: [PATCH 1/2] [PseudoProbe] Preserve probe identity for inlined nodebug
 calls

Summary:
Prevent debugless calls in inlined nodebug functions from inheriting the caller's packed pseudo-probe discriminator. Such inheritance aliases distinct calls onto one probe index and makes the resulting callsite profile stale. Add a regression test covering the emitted callsite probe.

Test Plan:
/home/kupathak/llvm21-build/bin/llvm-lit -v llvm/test/Transforms/SampleProfile/pseudo-probe-no-debug-info.ll

Reviewers:

Subscribers:

Tasks:

Tags:
---
 llvm/lib/Transforms/Utils/InlineFunction.cpp      |  8 +++++++-
 .../SampleProfile/pseudo-probe-no-debug-info.ll   | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 45454002a78e2..366771927061e 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2013,7 +2013,13 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
     if (isa<PseudoProbeInst>(I))
       return;
 
-    I.setDebugLoc(TheCallDL);
+    DebugLoc DL = TheCallDL;
+    // An inlined call without a debug location has no callsite probe of its
+    // own. Do not let it inherit the caller's probe discriminator.
+    if (isa<CallBase>(I) && DL &&
+        DILocation::isPseudoProbeDiscriminator(DL->getDiscriminator()))
+      DL = DL->cloneWithDiscriminator(0);
+    I.setDebugLoc(DL);
   };
 
   // Helper-util for updating debug-info records attached to instructions.
diff --git a/llvm/test/Transforms/SampleProfile/pseudo-probe-no-debug-info.ll b/llvm/test/Transforms/SampleProfile/pseudo-probe-no-debug-info.ll
index 08b7e4cb162af..b5a41656c0d1f 100644
--- a/llvm/test/Transforms/SampleProfile/pseudo-probe-no-debug-info.ll
+++ b/llvm/test/Transforms/SampleProfile/pseudo-probe-no-debug-info.ll
@@ -1,7 +1,13 @@
-; RUN: opt < %s -passes='pseudo-probe,cgscc(inline)' -S | FileCheck %s
+; RUN: opt < %s -passes='pseudo-probe,cgscc(inline)' -S -o %t
+; RUN: FileCheck %s < %t
+; RUN: llc %t -mtriple=x86_64 -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=MIR
 
 ; CHECK-LABEL: @caller(
 
+; This call came from the callee without debug metadata. It keeps the caller's
+; source location but must not inherit the caller's callsite probe.
+; CHECK: call void @inner(){{.*}}!dbg ![[INNER_CALL_LOC:[0-9]+]]
+
 ; This instruction did not have a !dbg metadata in the callee but get a !dbg after inlined.
 ; CHECK: store i32 1, {{.*}}, !dbg ![[#]]
 
@@ -9,12 +15,19 @@
 ; CHECK-NOT:  call void @llvm.pseudoprobe({{.*}}), !dbg ![[#]]
 ; CHECK:  call void @llvm.pseudoprobe({{.*}})
 
+; MIR-LABEL: name: caller
+; MIR-NOT: PSEUDO_PROBE {{.*}}, 2, 2
+; MIR: CALL64pcrel32 {{.*}}@inner
+
 @a = common global i32 0, align 4
 @b = common global i32 0, align 4
 
+declare void @inner()
+
 ; Function Attrs: nounwind uwtable
 define void @callee() {
 entry:
+  call void @inner()
   store i32 1, ptr @a, align 4
   ret void
 }

>From 239488a4bd34bd0363f571b25a1406019883ca62 Mon Sep 17 00:00:00 2001
From: Kunal Pathak <kupathak at meta.com>
Date: Wed, 26 Aug 2026 17:56:12 -0700
Subject: [PATCH 2/2] update the comment to make it clear

---
 llvm/lib/Transforms/Utils/InlineFunction.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 366771927061e..a0a04295b24bf 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2014,8 +2014,9 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
       return;
 
     DebugLoc DL = TheCallDL;
-    // An inlined call without a debug location has no callsite probe of its
-    // own. Do not let it inherit the caller's probe discriminator.
+    // A call receiving the outer callsite's fallback location has no usable
+    // callsite probe of its own. Do not let it inherit the outer call's probe
+    // discriminator.
     if (isa<CallBase>(I) && DL &&
         DILocation::isPseudoProbeDiscriminator(DL->getDiscriminator()))
       DL = DL->cloneWithDiscriminator(0);



More information about the llvm-commits mailing list