This is an archive of the discontinued LLVM Phabricator instance.

[TLII] Reduce copies of TLII for TLA
AcceptedPublic

Authored by wenlei on Apr 11 2020, 12:07 PM.

Details

Summary

Minor changes to reduce the copying needed for TargetLibraryInfoImpl when it's passed around by TargetLibraryAnalysis and TargetLibraryInfoWrapperPass, by using move whenever possible.

Diff Detail

Event Timeline

wenlei created this revision.Apr 11 2020, 12:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2020, 12:07 PM
hoyFB added a comment.Apr 11 2020, 1:37 PM

Thanks for the nice cleanup!

llvm/include/llvm/Analysis/TargetLibraryInfo.h
456

Can T just be used here? TargetLibraryInfoImpl comes with a such constructor: TargetLibraryInfoImpl(const Triple &T)

hoyFB accepted this revision.Apr 11 2020, 1:43 PM
hoyFB added inline comments.
llvm/include/llvm/Analysis/TargetLibraryInfo.h
456

Unlikely not. That is an explicit constructor and BaselineInfoImpl is an Optional object.

This revision is now accepted and ready to land.Apr 11 2020, 1:43 PM

Some parts of this are dependent on the patch that got reverted, but I have some other questions below about the changes in BackendUtil.cpp.

clang/lib/CodeGen/BackendUtil.cpp
691

These changes mean we now construct a new TLII multiple times (e.g. both when we add the TargetLibraryInfoWrapperPass to the MPM earlier and to the FPM here, rather that just copying. Is this actually faster? It seems like it would be slower overall.

llvm/lib/Analysis/TargetLibraryInfo.cpp
586–587

Woops, sorry, missed this one in the original review.

598

This is missing copying of the VecLibDescs (looks like I missed this as well originally).

610

Ditto.

wenlei marked an inline comment as done.Apr 11 2020, 3:31 PM

Some parts of this are dependent on the patch that got reverted, but I have some other questions below about the changes in BackendUtil.cpp.

Thanks for quick review.. I will remove the changes dependent on the reverted change before commit.

clang/lib/CodeGen/BackendUtil.cpp
691

Oops, this one isn't intentional... changed it back. Though for other instances where TLII isn't reused, similar change turns extra copy into move.

wenlei updated this revision to Diff 256806.Apr 11 2020, 3:31 PM

address feedback

tejohnson added inline comments.Apr 12 2020, 8:32 AM
clang/lib/CodeGen/BackendUtil.cpp
691

I suppose you could std::move the TLII here to avoid this second copy.

Do you know how much difference this patch makes on the compile time instruction count regressions seen with the original patch? It seems like it shouldn't be huge given that this is just during the pipeline setup for the module. But if it does explain the instruction count increases that's probably why it didn't regress the actual wall time measurements.

Also, just a nit, because TLI is sometimes used to refer to the TargetLibraryInfo and occasionally to the TargetLibraryInfoImpl, and the latter is frequently referred to as TLII, could you change the description to say TLII or TLI Impl? Since this doesn't affect TargetLibraryInfo/TLI object copies.

wenlei marked 2 inline comments as done.Apr 12 2020, 9:06 AM
wenlei added inline comments.
clang/lib/CodeGen/BackendUtil.cpp
691

Yeah, the 2nd use can be a move, though I'm inclined to not do that, as TLII isn't immediately out of scope yet.

I didn't setup measurement for this. I was basically playing with some tests for sanity check just to make sure we're not doing things unexpectedly, e.g. we don't do per-function copies unexpectedly in TargetLibraryAnalysis::run. But other than a few extra copies on setup path, I didn't see anything unusual. Since the original patch can make any copies more expensive, I thought it's good to reduce that as I see it.

llvm/lib/Analysis/TargetLibraryInfo.cpp
598

Now I remembered why this was missed from my side, before my patch, VecLibDescs isn't copied here either, which seems like a bug? Same for the move one below.

wenlei retitled this revision from [TLI] Reduce copies for TLI and TLA to [TLII] Reduce copies for TLI and TLA.Apr 12 2020, 9:07 AM
wenlei retitled this revision from [TLII] Reduce copies for TLI and TLA to [TLII] Reduce copies of TLII for TLA.Apr 12 2020, 9:10 AM
wenlei edited the summary of this revision. (Show Details)

Also, just a nit, because TLI is sometimes used to refer to the TargetLibraryInfo and occasionally to the TargetLibraryInfoImpl, and the latter is frequently referred to as TLII, could you change the description to say TLII or TLI Impl? Since this doesn't affect TargetLibraryInfo/TLI object copies.

Sure, done.. changed the title, and made the description more explicit.

lgtm with the VecLibDesc references removed.

llvm/lib/Analysis/TargetLibraryInfo.cpp
598

I assume you mean the VectorDescs/ScalarDescs vectors. You are right, even before your D77632 patch they were not being copied here or below. Looks like there is an existing bug there that no one noticed.

tejohnson accepted this revision.Apr 12 2020, 2:44 PM