[llvm] [SampleProfileMatcher] Fix direct basename matching for suffixed function names (PR #227184)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 20:47:19 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Farid Zakaria (fzakaria)

<details>
<summary>Changes</summary>

Direct basename matching silently skips any function whose name carries a suffix, for two reasons:

1. `getDemangledBaseName` demangles the raw name. For names such as `_ZL3fool.__uniq.123`, `_Z3fool.llvm.7`, `.part.N` or `.cfi` the Itanium demangler's root node is a DotSuffix, for which `getFunctionBaseName()` returns null, so the function is never a candidate on either the IR or the profile side.
2. `UpdateWithSalvagedProfiles` keys `FuncNameToProfNameMap` by the raw IR name, but `SampleProfileReader::getSamplesFor(const Function &)` looks it up by `getCanonicalFnName`. A salvaged `.llvm.N` (ThinLTO-promoted), `.part.N` or `.cfi` function therefore still gets no profile.

### __uniq.N

Canonicalize the name before demangling (additionally dropping `.__uniq.N`, which `getCanonicalFnName` keeps when the profile has uniq names), and key the map by the canonical name. Other suffixes such as coroutine `.resume` are kept so those clones do not make a basename ambiguous.

The `.__uniq.N` case matters most in practice. The suffix hashes the source path (`-funique-internal-linkage-names`), so moving or renaming a file renames every internal-linkage function in it, and these are exactly the functions basename matching is meant to recover. 

### Performance Analysis

In CSSPGO profiles from two large production services at Meta,  `.__uniq.` functions are 17.4% and 8.6% of top-level profiles but carry 39.9% and 29.2% of the samples (i.e. internal functions are few, but they are small hot helpers), so their sample density is 2.3x-3.4x that of the average function. Today all of them are excluded from basename matching which this PR fixes.

Assisted-by: Claude

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


5 Files Affected:

- (modified) llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp (+12-2) 
- (added) llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-direct-basename-suffix.prof (+12) 
- (added) llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-stale-profile-direct-basename-uniq.prof (+6) 
- (added) llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-direct-basename-suffix.ll (+101) 
- (added) llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-direct-basename-uniq.ll (+68) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


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


More information about the llvm-commits mailing list