[PATCH] D98783: [CUDA][HIP] Remove unused addr space casts

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 15 10:48:28 PDT 2021


yaxunl added a comment.

In D98783#2657656 <https://reviews.llvm.org/D98783#2657656>, @rjmccall wrote:

> In D98783#2642269 <https://reviews.llvm.org/D98783#2642269>, @tra wrote:
>
>> We may want to add someone with more expertise with the IR as a reviewer. I'd like an educated opinion on whether the invisible dangling IR is something that needs fixing in general or if it's OK to just clean it up in this particular case. Or both.
>>
>> @rjmccall, @rsmith -- do you have any suggestions -- either on the subject of the invisible dangling IR or on who may be the right person to talk to?
>
> If Clang is creating constants unnecessarily, we should try to avoid that on general compile time / memory usage grounds unless doing so is a serious problem.  But I don't think it should be our responsibility to GC unused constant expressions in order to make DCE work.
>
> It's extremely common to create `bitcast` global constants.  So the fact that this happens with `addrspacecast`s but hasn't been a persistent problem with `bitcast`s makes more suspect that DCE actually tries to handle this, but something about what it's doing isn't aware of `addrspacecast`.  And indeed, LLVM's GlobalDCE seems to call a method called `removeDeadConstantUsers()` before concluding that a constant can't be thrown away.  So either you're using a different transform that needs to do the same thing, or something is stopping `removeDeadConstantUsers()` from eliminating this `addrspacecast`.

You are right. GlobalDCE is able to remove the dead addr space casts added by clang. The reason why the useless global variables are not internalized is that the internalization pass is done before GlobalDCE, whereas the internalization pass only internalizes useless global variables. To be able to internalize global variables with dead users, I need to add another GlobalDCE before internalization pass.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98783/new/

https://reviews.llvm.org/D98783



More information about the cfe-commits mailing list