Skip to content

Fix crash from [CGData] Global Merge Functions (#112671) #116241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

kyulee-com
Copy link
Contributor

@kyulee-com kyulee-com commented Nov 14, 2024

Module summary index is optional for this pass, and we shouldn't run it, but import it as necessary.

@kyulee-com kyulee-com force-pushed the fixsummary branch 2 times, most recently from 6010da4 to c24e064 Compare November 14, 2024 15:21
@kyulee-com kyulee-com marked this pull request as ready for review November 14, 2024 15:23
@mikaelholmen
Copy link
Collaborator

This fixes the crash I reported in #112671 (comment)
I have no idea if this is the propoer fix for the problem though. I think it's better if someone who reviwed #112671 looks at this too.

I think it would be good to add a testcase though. There is a reproducer in #112671 (comment) so it's easy to make a testcase out of that.

@kyulee-com
Copy link
Contributor Author

cc. @nocchijiang

Copy link
Contributor

@nocchijiang nocchijiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it is kind of my fault letting it slip through. I had observed the same crash during my local testing but forgot to report the issue.

@@ -0,0 +1,6 @@
; This test checks if the global merge func pass should not build module summary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick: should we move the test file into llvm/test/CodeGen/AArch64/ or even llvm/test/CodeGen/Generic/ since this is not a ThinLTO/backend-specific test?

Copy link
Contributor

@thevinster thevinster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if this resolves the crash

@@ -666,7 +666,6 @@ bool GlobalMergeFuncPassWrapper::runOnModule(Module &M) {

PreservedAnalyses GlobalMergeFuncPass::run(Module &M,
AnalysisManager<Module> &AM) {
ModuleSummaryIndex *Index = &(AM.getResult<ModuleSummaryIndexAnalysis>(M));
bool Changed = GlobalMergeFunc(Index).run(M);
bool Changed = GlobalMergeFunc(ImportSummary).run(M);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If GlobalMergeFunc doesn't need ModuleSummaryIndex, why not just initialize without the parameter? Is there some weird side effect from some other thing that requires passing it in even though it's not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pass only uses this combined summary to determine if it's a LTO mode -- https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/GlobalMergeFunctions.cpp#L539-L542.

Currently, this pass is utilized in a pre-codegen pass that employs the legacy createGlobalMergeFuncPass(). As per the review comment, I have also incorporated an option for the new pass manager, GlobalMergeFuncPass(). If we intend to use this with the typical new PM, such as buildThinLTODefaultPipeline(), it is necessary to pass ImportSummary to the constructor.

@kyulee-com kyulee-com force-pushed the fixsummary branch 3 times, most recently from 35b8603 to ac281be Compare November 15, 2024 19:18
@kyulee-com kyulee-com merged commit 816c975 into llvm:main Nov 15, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants