diff options
author | Teresa Johnson <tejohnson@google.com> | 2023-02-16 11:19:27 -0800 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2023-02-16 18:20:12 -0800 |
commit | 8045ba89488c9f7cc1c291e6c939e02e04fbcd2e (patch) | |
tree | fc7a36d8f02a2b9dcf471269877b5fcff23c2dd8 /llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | |
parent | 54186d33c3a0d4834d2e5f95640b63677f5b5142 (diff) | |
download | llvm-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/Transforms/IPO/WholeProgramDevirt.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp index 7410b37..274bb7e 100644 --- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -379,6 +379,7 @@ namespace { // conditions // 1) All summaries are live. // 2) All function summaries indicate it's unreachable +// 3) There is no non-function with the same GUID (which is rare) bool mustBeUnreachableFunction(ValueInfo TheFnVI) { if ((!TheFnVI) || TheFnVI.getSummaryList().empty()) { // Returns false if ValueInfo is absent, or the summary list is empty @@ -391,12 +392,13 @@ bool mustBeUnreachableFunction(ValueInfo TheFnVI) { // In general either all summaries should be live or all should be dead. if (!Summary->isLive()) return false; - if (auto *FS = dyn_cast<FunctionSummary>(Summary.get())) { + if (auto *FS = dyn_cast<FunctionSummary>(Summary->getBaseObject())) { if (!FS->fflags().MustBeUnreachable) return false; } - // Do nothing if a non-function has the same GUID (which is rare). - // This is correct since non-function summaries are not relevant. + // Be conservative if a non-function has the same GUID (which is rare). + else + return false; } // All function summaries are live and all of them agree that the function is // unreachble. |