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

Fraser Cormack via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 02:30:58 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:

Thanks, I've gone with your suggestion.

I have a question, though; is it possible that `ObjA` hits its max lookup during `getUnderlyingObject`, but does in fact alias with `ObjB`? For example, what if it's `ObjB` but with 7+ GEPs, for example? I don't know if this is something to worry about.

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


More information about the llvm-commits mailing list