This is an archive of the discontinued LLVM Phabricator instance.

Preserve the address space for llvm.used and llvm.compiler.used global variables in GlobalOpt pass.
ClosedPublic

Authored by nawalcopty on Feb 21 2023, 1:33 PM.

Details

Summary

The llvm.used (or llvm.compiler.used) global variable is an array that contains a list of pointers to global variables and functions.

The GlobalOpt (Global Variable Optimizer) pass is not preserving the address space for llvm.used and llvm.compiler.used global variables.This patch updates the setUsedInitializer() function in GlobalOpt.cpp, so the address space is preserved.

Diff Detail

Event Timeline

nawalcopty created this revision.Feb 21 2023, 1:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 1:33 PM
nawalcopty requested review of this revision.Feb 21 2023, 1:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 1:33 PM

Thanks for fixing a hardcoded AS 0! Code change looks correct to me but the test case can be reduced further.

llvm/lib/Transforms/IPO/GlobalOpt.cpp
2123

Would the IR have passed the verifier if these checks don't hold? If not we could use cast instead.

llvm/test/Transforms/GlobalOpt/global-opt-addrspace.ll
5

Not needed

18

This looks exactly the same as before so the test would also pass without globalopt. Could you add another entry so that the sorting logic in the modified function changes the output?

43

(almost?) all of these lines should not be required for the test.

arsenm added a subscriber: arsenm.Feb 21 2023, 4:32 PM
arsenm added inline comments.
llvm/test/Transforms/GlobalOpt/global-opt-addrspace.ll
8

Don't need triple

21

Don't need all the metadata or comdat or linkage

23

use named values

Made changes as indicated by reviewers.

Fixed up the diff to include all changes (including the ones in the previous diff). Thanks.

arsenm added inline comments.Mar 31 2023, 12:07 PM
llvm/lib/Transforms/IPO/GlobalOpt.cpp
2122–2123

Don't need the if to check a cast<>

nawalcopty updated this revision to Diff 510519.EditedApr 3 2023, 8:52 AM

Removed the if when using cast<>. Thanks.

Could someone please review this patch? I think this patch is ready for approval. Thanks!

aeubanks accepted this revision.Apr 24 2023, 11:14 AM

lg with nit

llvm/lib/Transforms/IPO/GlobalOpt.cpp
2124

just inline this below instead of having a ElemAddrSpace variable

This revision is now accepted and ready to land.Apr 24 2023, 11:14 AM

Removed unnecessary ElemAddrSpace variable, as @aeubanks suggested.

do you need me to land this for you? what name/email should I use?

Hi @aeubanks. Yes, it would be great if you would land this for me. Please use the following name/email: "Nawal Copty <nawal.copty@intel.com>"

Thank you!

This revision was landed with ongoing or failed builds.Apr 25 2023, 1:07 PM
This revision was automatically updated to reflect the committed changes.