Change how globalopt handles aliases in llvm.used

Nick Lewycky nlewycky at google.com
Wed Jun 5 17:08:14 PDT 2013


Does anyone else have an opinion on verify.patch? Is it okay to require in
the verifier that every entry in @llvm.used must have a name? Is it ever
valid for an optimization to nuke the name of a global without first
checking whether it's used by @llvm.used?

I'm convinced that having an unnamed variable in @llvm.used can't possibly
have any use (it must be dead, we can ignore/remove all such entries), but
I'm not sure whether a well-behaved optimization ever produces them (just
as well-behaved optimizations may cause blocks to become unreachable).

Review of verify.patch:

Please also update LangRef.html with this patch to mention that all entries
in @llvm.used must have names.

Review of global-opt.patch:

The + and - don't line up for some of this patch, making it a pain to
review. Could you upload this to phab? http://llvm.org/docs/Phabricator.html

+/// \brief Given "llvm.used" or "llvm.compiler_used" as a global nome,
collect

typo, "nome".

Good news, I think I've reviewed this patch before? It looks like it's
probably ready to be submitted.

Nick

On 27 May 2013 16:25, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:

> Now that the simple fix is safely in the 3.3 branch, I would like to
> revisit the more complete one.
>
> The first patch (verify.patch) just checks that every entry in
> llvm.used has a name. As far as I can tell this is a reasonable
> restriction since the language reference defines llvm.used in terms of
> an invisible reference.
>
> The second patch (global-opt.patch) is the actual change. Instead of a
> custom implementation of replaceAllUsesWith, we just call
> replaceAllUsesWith and recreate llvm.used and llvm.compiler-used.
>
> This change is particularity interesting because it makes llvm see
> through what clang is doing with static used functions in extern "C"
> contexts. With this change, running clang -O2 in
>
> extern "C" {
>   __attribute__((used)) static void foo() {}
> }
>
> produces
>
> @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to
> i8*)], section "llvm.metadata"
> define internal void @foo() #0 {
> entry:
>   ret void
> }
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130605/e493a0db/attachment.html>


More information about the llvm-commits mailing list