[PATCH] D101512: [CodeGen] don't emit addrsig symbol if it's used only by metadata
Reid Kleckner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 29 14:34:38 PDT 2021
rnk added inline comments.
================
Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1854
+ for (auto U = GV.user_begin(), E = GV.user_end(); U != E; ++U)
+ if (U->isUsedByMetadata())
+ ++MetadataCount;
----------------
zequanwu wrote:
> rnk wrote:
> > I see, so, the GV is used by a constant, which is then used by metadata. Metadata uses do not appear in the use list.
> >
> > I think this condition is slightly incorrect, though, the bitcast constant expression could be used by metadata *and* a real Value. So, consider your test case, but then add in a real instruction that uses the same bitcast. In this case, we should still put GV into the addrsig table.
> >
> > One refinement would be to check that each user is a Constant with no uses, instead of checking if it is used by metadata. This could be:
> > if (isa<Constant>(U) && U->use_empty())
> >
> > However, this will not handle nested constant expressions. Consider a series of `getelementptr` and `bitcast` constant expressions. To be fully general, you need a worklist to check that all transitive users of GV are non-GlobalValue Constants that are only used by other constants.
> Yea, I see the problem.
> > `if (isa<Constant>(U) && U->use_empty())`
> I understand this, but confused by below.
> > check that all transitive users of GV are non-GlobalValue Constants that are only used by other constants.
> IIUC, if all transitive users of the GV are non-GlobalValue constants that are not transitively used by any non-GlobalValue constants, the GV is not address significant. For example, in the test case below, `@a1` and `@i1` are not address significant, right?
In the test below, I see two Instructions that use `@a1` and `@i1`, so I think they are address significant.
I mentioned GlobalValues because they are also subclasses of Constant, but if a GlobalVariable uses a Function, for example, that is a real use and we should consider the function address significant. Consider:
```
int someFunc(int x) { return x + 1; }
void *p = (void *)&someFunc;
```
The only user of `someFunc` will be a bitcast constant, and then the only use of that bitcast will be `p`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101512/new/
https://reviews.llvm.org/D101512
More information about the llvm-commits
mailing list