[llvm] [AMDGPU] Fix spurious NoAlias results (PR #122309)

Fraser Cormack via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 09:29:27 PST 2025


================
@@ -80,10 +80,13 @@ AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
     } else if (const Argument *Arg = dyn_cast<Argument>(ObjA)) {
       const Function *F = Arg->getParent();
       switch (F->getCallingConv()) {
-      case CallingConv::AMDGPU_KERNEL:
+      case CallingConv::AMDGPU_KERNEL: {
         // In the kernel function, kernel arguments won't alias to (local)
         // variables in shared or private address space.
-        return AliasResult::NoAlias;
+        const auto *ObjB =
+            getUnderlyingObject(B.Ptr->stripPointerCastsForAliasAnalysis());
+        return (ObjA == ObjB) ? AliasResult::MustAlias : AliasResult::NoAlias;
----------------
frasercrmck wrote:

I didn't know that about MustAlias, thank you.

My understanding of the intent of the code is that a kernel argument can never alias with a "shared" or "private" address-space-qualified pointer that isn't based on a kernel argument (that's what `(local)` hints at in the comment). Perhaps this is always true for private pointers, as they can never derive from a kernel argument. But proving that a shared pointer is local to a function is going to be tricky; that's why I was trying to use underlying objects.

Another thing I don't understand is whether two distinct shared kernel parameters may alias. In that case there's even more work to be done.

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


More information about the llvm-commits mailing list