Skip to content

Commit e6aeb3f

Browse files
[MemProf] Fix when function has indirect call (#101170)
When function has indirect call in LTO mode, it causes `assert(Alias)` in `findProfiledCalleeThroughTailCalls`
1 parent bc6834f commit e6aeb3f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,7 @@ bool ModuleCallsiteContextGraph::calleeMatchesFunc(
21092109
Instruction *Call, const Function *Func, const Function *CallerFunc,
21102110
std::vector<std::pair<Instruction *, Function *>> &FoundCalleeChain) {
21112111
auto *CB = dyn_cast<CallBase>(Call);
2112-
if (!CB->getCalledOperand())
2112+
if (!CB->getCalledOperand() || CB->isIndirectCall())
21132113
return false;
21142114
auto *CalleeVal = CB->getCalledOperand()->stripPointerCasts();
21152115
auto *CalleeFunc = dyn_cast<Function>(CalleeVal);

llvm/test/Transforms/MemProfContextDisambiguation/tailcall.ll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ source_filename = "memprof-tailcall.cc"
1616
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"
1717
target triple = "x86_64-unknown-linux-gnu"
1818

19+
@a = dso_local global [2 x ptr] [ptr @_Z2a1v, ptr @_Z2a2v], align 16
20+
21+
declare void @_Z2a1v() #0
22+
23+
declare void @_Z2a2v() #0
24+
1925
; Function Attrs: noinline
2026
; IR-LABEL: @_Z3barv()
2127
define ptr @_Z3barv() local_unnamed_addr #0 {
@@ -58,6 +64,8 @@ define i32 @main() #0 {
5864
;; cloned functions.
5965
; IR: call ptr @_Z3foov.memprof.1()
6066
%call1 = tail call ptr @_Z3foov(), !callsite !7
67+
%2 = load ptr, ptr @a, align 16
68+
call void %2(), !callsite !10
6169
ret i32 0
6270
}
6371

@@ -79,11 +87,14 @@ attributes #0 = { noinline }
7987
attributes #1 = { nobuiltin allocsize(0) }
8088
attributes #2 = { builtin allocsize(0) }
8189

82-
!0 = !{!1, !3}
90+
!0 = !{!1, !3, !8}
8391
!1 = !{!2, !"notcold"}
8492
!2 = !{i64 3186456655321080972, i64 8632435727821051414}
8593
!3 = !{!4, !"cold"}
8694
!4 = !{i64 3186456655321080972, i64 -3421689549917153178}
8795
!5 = !{i64 3186456655321080972}
8896
!6 = !{i64 8632435727821051414}
8997
!7 = !{i64 -3421689549917153178}
98+
!8 = !{!9, !"notcold"}
99+
!9 = !{i64 3186456655321080972, i64 1}
100+
!10 = !{i64 1}

0 commit comments

Comments
 (0)