aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2023-02-16 11:19:27 -0800
committerTeresa Johnson <tejohnson@google.com>2023-02-16 18:20:12 -0800
commit8045ba89488c9f7cc1c291e6c939e02e04fbcd2e (patch)
treefc7a36d8f02a2b9dcf471269877b5fcff23c2dd8 /llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
parent54186d33c3a0d4834d2e5f95640b63677f5b5142 (diff)
downloadllvm-8045ba89488c9f7cc1c291e6c939e02e04fbcd2e.zip
llvm-8045ba89488c9f7cc1c291e6c939e02e04fbcd2e.tar.gz
llvm-8045ba89488c9f7cc1c291e6c939e02e04fbcd2e.tar.bz2
[ThinLTO/WPD] Handle function alias in vtable correctly
We were not summarizing a function alias in the vtable, leading to incorrect WPD in some cases, and missing WPD in others. Specifically, we would end up ignoring function aliases as they aren't summarized, so we could incorrectly devirtualize if there was a single other non-alias function in a compatible vtable. And if there was only one implementation, but it was an alias, we would not be able to identify and perform the single implementation devirtualization. Handling the alias summary correctly also required fixing the handling in mustBeUnreachableFunction, so that it is not incorrectly ignored. Regular LTO is conservatively correct because it will skip devirtualizing when any pointer within a vtable is not a function. However, it needs additional work to be able to take advantage of function alias within the vtable that is in fact the only implementation. For that reason, the Regular LTO testing in the second test case is currently disabled, and will be enabled along with a follow on enhancement fix for Regular LTO WPD. Differential Revision: https://reviews.llvm.org/D144209
Diffstat (limited to 'llvm/lib/Analysis/ModuleSummaryAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/ModuleSummaryAnalysis.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 3dfa2d8..26ff84f 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -583,12 +583,17 @@ static void findFuncPointers(const Constant *I, uint64_t StartingOffset,
VTableFuncList &VTableFuncs) {
// First check if this is a function pointer.
if (I->getType()->isPointerTy()) {
- auto Fn = dyn_cast<Function>(I->stripPointerCasts());
- // We can disregard __cxa_pure_virtual as a possible call target, as
- // calls to pure virtuals are UB.
- if (Fn && Fn->getName() != "__cxa_pure_virtual")
- VTableFuncs.push_back({Index.getOrInsertValueInfo(Fn), StartingOffset});
- return;
+ auto C = I->stripPointerCasts();
+ auto A = dyn_cast<GlobalAlias>(C);
+ if (isa<Function>(C) || (A && isa<Function>(A->getAliasee()))) {
+ auto GV = dyn_cast<GlobalValue>(C);
+ assert(GV);
+ // We can disregard __cxa_pure_virtual as a possible call target, as
+ // calls to pure virtuals are UB.
+ if (GV && GV->getName() != "__cxa_pure_virtual")
+ VTableFuncs.push_back({Index.getOrInsertValueInfo(GV), StartingOffset});
+ return;
+ }
}
// Walk through the elements in the constant struct or array and recursively