This is an archive of the discontinued LLVM Phabricator instance.

[LTO][WPD] Simplify mustBeUnreachableFunction and test after D115492
ClosedPublic

Authored by MaskRay on Dec 14 2021, 7:22 PM.

Details

Summary

An well-formed IR function definition must have an entry basic block and
a well-formed IR basic block must have one terminator so the emptiness
check can be simplified.
Also simplify the test a bit.

Diff Detail

Event Timeline

MaskRay created this revision.Dec 14 2021, 7:22 PM
MaskRay requested review of this revision.Dec 14 2021, 7:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 14 2021, 7:22 PM

Thanks for the simplifications. This lgtm but please wait for @luna to confirm that the simplified test case fails without the original fix.

thanks for the simplification!

The comment for IR (test case) is just a FYI, and for the cpp change, more of a double check since I wasn't sure myself if function declaration would make a difference.

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
242

An well-formed IR function definition must have an entry basic block and

a well-formed IR basic block must have one terminator so the emptiness
check can be simplified.

Thanks for pointing this out!

I think this is true for function definition but not true for function declarations. Yet I don't know if computeFunctionSummary [1] (caller of mustBeUnreachableFunction) guarantees it's a function definition (not a function declaration).

Is there a way to make this safe for function declarations (if necessary)?

[1] https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp#L257

llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
37–39

thanks for the simplification!

The change looks good to me, and I can verify that nodevirtualization happens on simplified IRs without the fix (by using -vv on llvm-lit to print out the commands, and re-run commands using {opt, llvm-lto2} without the change.

Just fyi I added -O3 (which is absent before) on the command to generate the IR, and got simpler IR for both IR [1]; so going to carry on the simplification in a pending patch (https://reviews.llvm.org/D115648)

[1] https://gist.github.com/minglotus-6/aea3355e6e9a63d5a047a301dca7c7d7 for devirt_hybrid_after_filtering_unreachable.ll, and https://gist.github.com/minglotus-6/546e2a6627a8cc6823022b4ff30a7d43 for Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll,

mingmingl accepted this revision.Dec 15 2021, 10:44 AM
mingmingl added inline comments.
llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
242

An well-formed IR function definition must have an entry basic block and

a well-formed IR basic block must have one terminator so the emptiness
check can be simplified.

Thanks for pointing this out!

I think this is true for function definition but not true for function declarations. Yet I don't know if computeFunctionSummary [1] (caller of mustBeUnreachableFunction) guarantees it's a function definition (not a function declaration).

Is there a way to make this safe for function declarations (if necessary)?

[1] https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp#L257

After another look, caller guarantees F is a function definition, so LGTM. Maybe add a comment for mustBeUnreachableFunction that caller guarantees F is a function definition (not a function declaration)?

This revision is now accepted and ready to land.Dec 15 2021, 10:44 AM
MaskRay updated this revision to Diff 394673.Dec 15 2021, 3:43 PM
MaskRay marked an inline comment as done.

add comment and assert

This revision was landed with ongoing or failed builds.Dec 15 2021, 3:43 PM
This revision was automatically updated to reflect the committed changes.