This is an archive of the discontinued LLVM Phabricator instance.

ThinLTOBitcodeWriter: Try harder to discard unused references to the merged module.
ClosedPublic

Authored by pcc on Nov 28 2017, 5:52 PM.

Details

Summary

If the thin module has no references to an internal global in the
merged module, we need to make sure to preserve that property if the
global is a member of a comdat group, as otherwise promotion can end
up adding global symbols to the comdat, which is not allowed.

This situation can arise if the external global in the thin module
has dead constant users, which would cause use_empty() to return
false and would cause us to try to promote it. To prevent this from
happening, discard the dead constant users before asking whether a
global is empty.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Nov 28 2017, 5:52 PM
tejohnson accepted this revision.Nov 30 2017, 2:24 PM

LGTM - I assume the modified test fails without the patch? I can't tell from looking at it whether it anon would have dead constant users.

This revision is now accepted and ready to land.Nov 30 2017, 2:24 PM
pcc added a comment.Nov 30 2017, 3:04 PM

LGTM - I assume the modified test fails without the patch?

It in fact passes because I made a mistake in the test. The declaration that appears in the thin module looks like this:

@"anon$ae77054242d4de6843fe9803b6a8ac9f" = external hidden unnamed_addr constant { [1 x i8*] }

I will adjust the test so that it would match this.

I can't tell from looking at it whether it anon would have dead constant users.

It would indeed, specifically the constant getelementptr inbounds ({ [1 x i8*] }, { [1 x i8*] }* @anon, i32 0, i32 0, i32 1 in @al's definition, which is left unreferenced when we drop @al from the thin module in filterModule.

This revision was automatically updated to reflect the committed changes.