Skip to content

Commit 14ee5ff

Browse files
committed
Postpone check in tryICallBranchFunnel and tighten condition to any AE.
1 parent fd5e7a1 commit 14ee5ff

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,6 @@ bool DevirtModule::tryFindVirtualCallTargets(
10931093
std::vector<VirtualCallTarget> &TargetsForSlot,
10941094
const std::set<TypeMemberInfo> &TypeMemberInfos, uint64_t ByteOffset,
10951095
ModuleSummaryIndex *ExportSummary) {
1096-
bool HasAvailableExternally = false;
10971096
for (const TypeMemberInfo &TM : TypeMemberInfos) {
10981097
if (!TM.Bits->GV->isConstant())
10991098
return false;
@@ -1104,16 +1103,6 @@ bool DevirtModule::tryFindVirtualCallTargets(
11041103
GlobalObject::VCallVisibilityPublic)
11051104
return false;
11061105

1107-
// Record if the first GV is AvailableExternally
1108-
if (TargetsForSlot.empty())
1109-
HasAvailableExternally = TM.Bits->GV->hasAvailableExternallyLinkage();
1110-
1111-
// When the first GV is AvailableExternally, check if all other GVs are
1112-
// also AvailableExternally. If they are not the same, return false.
1113-
if (!TargetsForSlot.empty() && HasAvailableExternally &&
1114-
!TM.Bits->GV->hasAvailableExternallyLinkage())
1115-
return false;
1116-
11171106
Function *Fn = nullptr;
11181107
Constant *C = nullptr;
11191108
std::tie(Fn, C) =
@@ -1467,6 +1456,12 @@ void DevirtModule::tryICallBranchFunnel(
14671456
if (!HasNonDevirt)
14681457
return;
14691458

1459+
// If any GV is AvailableExternally, drop to generate branch.funnel
1460+
for (auto &T : TargetsForSlot) {
1461+
if (T.TM->Bits->GV->hasAvailableExternallyLinkage())
1462+
return;
1463+
}
1464+
14701465
FunctionType *FT =
14711466
FunctionType::get(Type::getVoidTy(M.getContext()), {Int8PtrTy}, true);
14721467
Function *JT;

llvm/test/Transforms/WholeProgramDevirt/availableexternal-check.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
; ...;
1212
; }
1313
;
14-
; Build command is "clang++ -O2 -target x86_64-unknown-linux -flto=thin \
14+
; Build command is "clang++ -O2 -target x86_64-unknown-linux -flto=full \
1515
; -fwhole-program-vtables -static-libstdc++ -Wl,-plugin-opt=-whole-program-visibility"
1616
;
1717
; _ZTVSt9exception's visibility is 1 (Linkage Unit), and available_externally.
18-
; But another vtable _ZTV1A.0 is not available_externally.
19-
; They should not do devirtualization because they are in different linkage type.
18+
; If any GV is available_externally, icall.branch.funnel should not be generated.
2019

2120
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"
2221
target triple = "x86_64-unknown-linux"

0 commit comments

Comments
 (0)