[llvm] [SampleProf] test that calls to function aliases get profile info (PR #169355)
Rose Hudson via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 08:23:31 PST 2025
https://github.com/rosefromthedead created https://github.com/llvm/llvm-project/pull/169355
When a call is made to a function alias, in SampleProfileLoader::generateMDProfMetadata we look up the actual call target name in the profile to resolve the alias, in the same way as we do for indirect calls. Add a test for this so we don't lose profile info on these calls some day.
>From 4992d63a5f476246afcc6ad19004704abf7343e8 Mon Sep 17 00:00:00 2001
From: Rose Hudson <rose.hudson at sony.com>
Date: Tue, 4 Nov 2025 10:18:04 +0000
Subject: [PATCH] [SampleProf] test that calls to function aliases get profile
info
When a call is made to a function alias, in
SampleProfileLoader::generateMDProfMetadata we look up the actual call
target name in the profile to resolve the alias, in the same way as we do
for indirect calls. Add a test for this so we don't lose profile info on
these calls some day.
---
.../SampleProfile/Inputs/fn-alias.prof | 3 ++
.../test/Transforms/SampleProfile/fn-alias.ll | 37 +++++++++++++++++++
2 files changed, 40 insertions(+)
create mode 100644 llvm/test/Transforms/SampleProfile/Inputs/fn-alias.prof
create mode 100644 llvm/test/Transforms/SampleProfile/fn-alias.ll
diff --git a/llvm/test/Transforms/SampleProfile/Inputs/fn-alias.prof b/llvm/test/Transforms/SampleProfile/Inputs/fn-alias.prof
new file mode 100644
index 0000000000000..7e99d129e10b3
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/Inputs/fn-alias.prof
@@ -0,0 +1,3 @@
+_ZN1AC2Ei:23127253:212088
+main:9489628:0
+ 2: 212088 _ZN1AC2Ei:212088
diff --git a/llvm/test/Transforms/SampleProfile/fn-alias.ll b/llvm/test/Transforms/SampleProfile/fn-alias.ll
new file mode 100644
index 0000000000000..b5c8c89d4af3a
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/fn-alias.ll
@@ -0,0 +1,37 @@
+; RUN: opt -S %s -passes=sample-profile -sample-profile-file=%S/Inputs/fn-alias.prof | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at _ZN1AC1Ei = alias void (ptr, i32), ptr @_ZN1AC2Ei
+
+define void @_ZN1AC2Ei() {
+ ret void
+}
+
+; CHECK-LABEL: define i32 @main
+define i32 @main() #0 !dbg !4 {
+; CHECK: call void @_ZN1AC1Ei
+; CHECK-SAME: !prof ![[PROF:[0-9]+]]
+ call void @_ZN1AC1Ei(ptr null, i32 0), !dbg !7
+ ret i32 0
+}
+
+attributes #0 = { "use-sample-profile" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 22.0.0git (https://github.com/llvm/llvm-project 2a02d57efb22956665d91b68de6b3f8d58db9cda)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "main.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "0f77ac0d94ea63dd55c86ed20b80e841")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 20, type: !6, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!5 = !DIFile(filename: "./main.cpp", directory: "/", checksumkind: CSK_MD5, checksum: "0f77ac0d94ea63dd55c86ed20b80e841")
+!6 = distinct !DISubroutineType(types: !2)
+!7 = !DILocation(line: 22, column: 7, scope: !8)
+!8 = distinct !DILexicalBlock(scope: !9, file: !5, line: 21, column: 47)
+!9 = distinct !DILexicalBlock(scope: !10, file: !5, line: 21, column: 3)
+!10 = distinct !DILexicalBlock(scope: !4, file: !5, line: 21, column: 3)
+
+; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 212088, i64 6296505300821684249, i64 212088}
More information about the llvm-commits
mailing list