This is an archive of the discontinued LLVM Phabricator instance.

Fix the bug when -compile-twice is specified, the PSI will be invalidated.
ClosedPublic

Authored by danielcdh on Sep 27 2016, 5:21 PM.

Details

Summary

When using llc with -compile-twice, module is generated twice, but getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI will still get the old PSI with the original (invalidated) Module. This patch checks if the module has changed when calling getPSI, if yes, update the module and invalidate the Summary.
The bug does not show up in the current llc because PSI is not used in CodeGen yet. But with https://reviews.llvm.org/D24989, the bug will be exposed by test/CodeGen/PowerPC/pr26378.ll

Diff Detail

Event Timeline

danielcdh updated this revision to Diff 72739.Sep 27 2016, 5:21 PM
danielcdh retitled this revision from to Fix the bug when -compile-twice is specified, the PSI will be invalidated..
danielcdh updated this object.
danielcdh added reviewers: eraman, davidxl.
danielcdh added a subscriber: llvm-commits.
davidxl edited edge metadata.Sep 27 2016, 5:38 PM

How about a test case?

include/llvm/Analysis/ProfileSummaryInfo.h
63

resetModule

lib/Analysis/ProfileSummaryInfo.cpp
120

Summary.reset(nullptr);

danielcdh updated this revision to Diff 72744.Sep 27 2016, 5:41 PM
danielcdh edited edge metadata.

update

not sure how to test this: it requires -compile-twice, which is an llc flag, but llc does not use PSI for now. https://reviews.llvm.org/D24989 will be the first patch that makes llc uses PSI.

davidxl accepted this revision.Sep 28 2016, 11:33 AM
davidxl edited edge metadata.

lgtm

This revision is now accepted and ready to land.Sep 28 2016, 11:33 AM
danielcdh closed this revision.Sep 28 2016, 11:50 AM

This sounds like not very idiomatic. I believe the usual solution is to handle this inside doInitialization. Can you clarify why you didn't do it this way?

You are right, doInitialization indeed made the analysis impl more cleaner. A fix is sent out in https://reviews.llvm.org/D25041

Thanks