[PATCH] D29781: Add alias canonicalization pass when preparing for ThinLTO

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 17:04:31 PST 2017


> +/// Check if the given user is an alias (looking through bit casts).
> +static bool userIsAlias(Value *V) {
> +  if (isa<GlobalAlias>(V))
> +    return true;
> +  if (BitCastOperator *BC = dyn_cast<BitCastOperator>(V)) {
> +    for (Use &U : BC->materialized_uses()) {
> +      return userIsAlias(U.getUser());

Using a for that always returns in the first iteration looks a bit odd
IMHO.

> +/// Like replaceAllUsesWith but doesn't replace any uses that are
> +/// aliases, so that we can just replace uses of the original value
> +/// with the new private aliasee, but keep the original value name
> +/// as an alias to it.
> +static void replaceAllUsesWithExceptAliases(Value *Old, Value *New) {

When first reading the code I got the impression that this would convert

@foo = weak alias @bar

....
call @foo
...

into calling @bar directly. Please add that to the test to show that it
is not the case. In fact, I think a good test would be

@bar = global...
@foo = alias @bar

...
use @bar
...
use @foo

and check that we still have a use of @bar and a use of @foo, but now
@bar and @foo are an alias to a private global.


> +
> +    // Don't make malformed IR (will be caught by verifier) worse.
> +    if (GO->isDeclarationForLinker())
> +      continue;

When is a pass expected to be run on malformed IR?

Cheers,
Rafael


More information about the llvm-commits mailing list