This pass transforms
gep (addrspacecast p)
into
addrspacecast (gep p)
Doing the addrspacecast instruction first (which is valid in NVPTX but
not on all targets) lets LLVM optimize better, because LLVM treats
addrspacecast as a black-box function.
This is particularly important for the idiom clang will use for lowering
the __ldg builtin.
Hmm, this looks a little suspicious to me.
What if you have:
Just because the addrspacecast postdominates the GEP does not ensure that it will be executed.
Along slightly similar but slightly different lines, consider:
In this case the addrspacecast postdominates the GEP and all its uses are control dependent on %cond. If %cond is true, then the addrspacecast is never used and all access to memory go through %gep instead of %asc.