Skip to content

[AMDGPU] Fix spurious NoAlias results #122309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
default:
// TODO: In the regular function, if that local variable in the
// location B is not captured, that argument pointer won't alias to it
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/AMDGPU/amdgpu-alias-analysis.ll
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,20 @@ define void @test_9_9(ptr addrspace(9) %p, ptr addrspace(9) %p1) {
load i8, ptr addrspace(9) %p1
ret void
}

; CHECK-LABEL: Function: test_kernel_arg_local_ptr
; CHECK: MayAlias: i32 addrspace(3)* %arg, i32 addrspace(3)* %arg1
; CHECK: MustAlias: i32 addrspace(3)* %arg, i32* %arg2
; CHECK: MustAlias: i32 addrspace(3)* %arg1, i32* %arg2
define amdgpu_kernel void @test_kernel_arg_local_ptr(ptr addrspace(3) %arg) {
entry:
%load1 = load i32, ptr addrspace(3) %arg, align 4
%arg.plus.1 = getelementptr inbounds nuw i8, ptr addrspace(3) %arg, i64 1
%arg1 = getelementptr inbounds nuw i8, ptr addrspace(3) %arg.plus.1, i64 -1
%load2 = load i32, ptr addrspace(3) %arg1, align 4
%arg.plus.4 = getelementptr inbounds nuw i8, ptr addrspace(3) %arg, i64 4
%acast = addrspacecast ptr addrspace(3) %arg.plus.4 to ptr
%arg2 = getelementptr inbounds i8, ptr %acast, i64 -4
%load3 = load i32, ptr %arg2, align 4
ret void
}
Loading