This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Ignore unreachable virtual functions in WPD in thin LTO
ClosedPublic

Authored by mingmingl on Dec 13 2021, 9:41 AM.

Details

Summary

For thin LTO, ignore unreachable functions (by reading from index) when finding virtual functions.

  • This helps to de-virtualize. Unit test are added in test case in llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  • Rename devirt_hybrid_after_filtering_unreachable.ll to devirt_after_filtering_unreachable.ll, and Inputs/devirt_hybrid... to Inputs/devirt...

Diff Detail

Event Timeline

mingmingl created this revision.Dec 13 2021, 9:41 AM
mingmingl requested review of this revision.Dec 13 2021, 9:41 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 13 2021, 9:41 AM

Add unit test for thinlto.

mingmingl retitled this revision from [LTO] Ignore unreachable virtual functions in WPD in hybrid LTO to [LTO] Ignore unreachable virtual functions in WPD in thin LTO.Dec 13 2021, 12:20 PM
mingmingl updated this revision to Diff 394389.Dec 14 2021, 2:37 PM

Rebase to main

mingmingl edited the summary of this revision. (Show Details)Dec 14 2021, 2:39 PM
mingmingl added a reviewer: tejohnson.
tejohnson added inline comments.Dec 14 2021, 4:26 PM
llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
64

This stuff is checked in other tests. Unless you are checking something specific to this test, you can remove all of this. Actually, it would be good to test here and in the earlier hybrid case that the summary for _ZN4BaseD0Ev says it is unreachable. But that's probably all you need to test.

Ditto for %t4.o

127

Unless you need to share only some of the check results with another invocation, just use a single check prefix.

mingmingl updated this revision to Diff 394429.Dec 14 2021, 5:54 PM
mingmingl marked 2 inline comments as done.

Change test IR by removing irrelevant lines and using one prefix per FileCheck.

thanks for review!

llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
64

Done by

  1. checking the bit mustBeUnreachable for thin LTO and hybrid LTO, and remove irrelevant lines
  2. Use one prefix per FileCheck.

I spent some time trying to figure out why the regular LTO split modules (files with ".1" suffix in mod-extract output) don't have function summaries.

Didn't figure out from code perspective (starting from Index->enableSplitLTOUnit() in https://github.com/llvm/llvm-project/blob/main/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L3926), but it's probably intended in the sense that regular LTO module won't need index (which is generated for thin).

tejohnson accepted this revision.Dec 14 2021, 6:05 PM

lgtm with one more test simplification below.

llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
11

Since we don't ever use variable BaseD0, there isn't a need to capture a value there. In fact, you can ignore it completely and then change all 4 llvm-dis instances in this test to check the same pattern like:

; FLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1

(and no need for the -DAG handling since there is only one pattern being checked per llvm-dis invocation).

This revision is now accepted and ready to land.Dec 14 2021, 6:05 PM
mingmingl updated this revision to Diff 394435.Dec 14 2021, 6:13 PM

Simplify test by using non-DAG prefix (for one pattern), and avoid capturing values since they are not used.

tejohnson added inline comments.Dec 14 2021, 6:14 PM
llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
11

You can combine all of these (ENABLESPLITFLAG, LIBENABLESPLITFLAG, etc) now into a single filecheck pattern.

mingmingl marked an inline comment as done.Dec 14 2021, 6:17 PM

thanks for review!

Also in the previous reply, I forgot to mention I removed the the line assert ((VTP.FuncVI) && "VTP.FuncVI must be nullptr after finding existing references doesn't guarantee that [1], and mustBeUnreachableFunction will return false if an empty VI is passed in anyway.

I'll run a ninja check (may take a while) and then push this.

[1] For field VirtFuncOffset::FuncVI, there are if and assertions about empty value (e.g., https://github.com/llvm/llvm-project/blob/main/llvm/lib/AsmParser/LLParser.cpp#L7834)

mingmingl updated this revision to Diff 394443.Dec 14 2021, 6:23 PM
mingmingl marked an inline comment as done.

Simplify test by sharing one pattern across two filecheck lines.

llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
11

(Saw this after previous reply) Done by sharing the pattern between two filecheck lines.

tejohnson added inline comments.Dec 14 2021, 7:22 PM
llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
16

I think it can be shared with the equivalent checks in the unsplit case as well. And probably with a check-prefix name that reflects what is being checked (e.g. UNREACHABLEFLAG), or maybe something simpler (e.g. FLAG).

mingmingl updated this revision to Diff 394461.Dec 14 2021, 8:01 PM

Simplify filecheck by re-using one prefix to test the unreachable bit.

mingmingl marked an inline comment as done.Dec 14 2021, 8:02 PM

thanks for the inputs!

llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
16

Use UNREACHABLEFLAG and share it across split and unsplit case.

mingmingl updated this revision to Diff 394689.Dec 15 2021, 4:55 PM
mingmingl marked an inline comment as done.

Simplify test case by using -O3 to generate IR.

In D115648#3196142, @luna wrote:

Simplify test case by using -O3 to generate IR.

Probably because of the diff from ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll to ThinLTO/X86/devirt_after_filtering_unreachable.ll is big, git regard a git mv as git add and git mv here (this stack overflow) question echoes.

So I'm going to keep it (without trying to make it look like a mv), wait for the pre-merge test and the local ninja check-llvm-lto, and then land this.

This revision was landed with ongoing or failed builds.Dec 15 2021, 6:27 PM
This revision was automatically updated to reflect the committed changes.
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp