[llvm] [AMDGPU] Fix spurious NoAlias results (PR #122309)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 10 00:16:37 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;
----------------
nikic wrote:
> 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.
If that's the goal, I think the check here should be `isIdentifiedObject(ObjB) && ObjA != ObjB ? NoAlias : MayAlias`.
If it's not an identified object, you do not know whether it may be based on the kernel argument in some indirect way (e.g. via being stored and then loaded).
https://github.com/llvm/llvm-project/pull/122309
More information about the llvm-commits
mailing list