[llvm] [NVPTX] Infer global AS for loads through readonly multi-level kernel pointer args (PR #193701)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 19:52:39 PDT 2026


Kalomidin wrote:

> I don't think it makes sense to recursively walk the call-graph and look for stores of pointers. It seems like this is only going to succeed for trivially simple programs and it feels like we're hand-rolling a bespoke alias-analysis. I think you could take the PR in 2 directions:
> 
> 1. narrow: A kernel pointer argument with the CUDA driver that has both `readonly` and `noalias` points to a region of memory that we can guarantee won't be written to during the kernel execution so all pointers loaded directly form that argument are global.
> 2. broad: I think InferAddressSpaces could be generally improved to use alias analysis to track pointer AS through memory. This is a bigger change though and I'm not sure exactly how it should look.

@AlexMaclean thank you for the feedback.
For broad option, it is very challenging task and I do not see any way to do such alias analysis.
For narrow option, when you are referring to `noalias`, do you mean user provides attribute `__restrict ` in the kernel argument? And my understanding is that `__restrict ` attribute only guarantees first level of pointer results to noalias with kernel and global arguments but sub-pointers may still have alias.
And finally, let me know if you think this optimization might be helpful as I see in the end it might cover very small amount of scenarios. If not useful, I can try to concentrate in some other optimization opportunities and close the pull request.

https://github.com/llvm/llvm-project/pull/193701


More information about the llvm-commits mailing list