This is an archive of the discontinued LLVM Phabricator instance.

llvm-reduce: Fix invalid reductions with llvm.used
ClosedPublic

Authored by arsenm on Dec 9 2022, 10:16 AM.

Details

Summary

Fixes issue 59413.

Diff Detail

Event Timeline

arsenm created this revision.Dec 9 2022, 10:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2022, 10:16 AM
arsenm requested review of this revision.Dec 9 2022, 10:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2022, 10:16 AM
Herald added a subscriber: wdng. · View Herald Transcript
jdoerfert accepted this revision.Dec 9 2022, 10:25 AM

LG, with some nits though.

llvm/include/llvm/Transforms/Utils/ModuleUtils.h
88

Nit: I don't think we need it to be a std::function, llvm::function_ref should do.

llvm/lib/Transforms/Utils/ModuleUtils.cpp
147

Nits:
Early exit in the end.
Surprised we need .getArrayRef()
Here and elsewhere, we should keep GV around until we insert the new GlobalVariable before it to avoid reorderings in the IR.
Remove llvm::

This revision is now accepted and ready to land.Dec 9 2022, 10:25 AM
arsenm added inline comments.Dec 9 2022, 10:31 AM
llvm/lib/Transforms/Utils/ModuleUtils.cpp
147

If you create the new one when the old one still exists, you get "@llvm.used0" which is wrong. Avoiding reordering would require finding the neighbor global

arsenm closed this revision.Dec 14 2022, 12:06 PM
arsenm marked an inline comment as done.
llvm/lib/Transforms/Utils/ModuleUtils.cpp
147

I remembered takeName exists, so managed to fix this