This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Fix cloning of llvm*.used when splitting module
ClosedPublic

Authored by tejohnson on Feb 18 2021, 5:26 PM.

Details

Summary

Refines the fix in 3c4c205060c9398da705eb71b63ddd8a04999de9 to only
put globals whose defs were cloned into the split regular LTO module
on the cloned llvm*.used globals. This avoids an issue where one of the
attached values was a local that was promoted in the original module
after the module was cloned. We only need to have the values defined in
the new module on those globals.

Fixes PR49251.

Diff Detail

Event Timeline

tejohnson created this revision.Feb 18 2021, 5:26 PM
tejohnson requested review of this revision.Feb 18 2021, 5:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 18 2021, 5:26 PM
tejohnson added inline comments.Feb 18 2021, 5:27 PM
llvm/lib/Transforms/Utils/ModuleUtils.cpp
79–85

I forgot to add in the description - this is needed because when we originally clone the module over, the llvm*.used globals will be declarations in the merged module. So when we go to add the new values to their used set, we need to handle deleting the old one which doesn't have an initializer.

MaskRay accepted this revision.Feb 19 2021, 9:37 PM

LGTM.

llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
204

llvm.used -> llvm[.compiler].used

"First" here made me think whether there should be another comment about "then" :)

llvm/test/Transforms/ThinLTOBitcodeWriter/split-used.ll
16

Perhaps add ; M1-NOT: @g

or change the following ; M1: @llvm.used to ; M1-NEXT: @llvm.used, to check that @g3 or @g4 is not copied.

26

The canonical form has , section("llvm.metadata").

With this new patch, , section("llvm.metadata") will be appended for M1. I assume that this different does not matter.

This revision is now accepted and ready to land.Feb 19 2021, 9:37 PM
tejohnson marked 2 inline comments as done.Feb 20 2021, 9:45 AM
tejohnson added inline comments.
llvm/test/Transforms/ThinLTOBitcodeWriter/split-used.ll
26

The compiler adds this when creating one of these special global values. I didn't bother putting it on the hand created globals here since it didn't matter for the test and keeps it more minimal.

tejohnson updated this revision to Diff 325212.Feb 20 2021, 9:46 AM

Address comments

This revision was landed with ongoing or failed builds.Feb 20 2021, 9:46 AM
This revision was automatically updated to reflect the committed changes.