Index: llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp @@ -126,13 +126,8 @@ bool AMDGPUAAResult::pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal) { - unsigned AS = Loc.Ptr->getType()->getPointerAddressSpace(); - if (AS == AMDGPUAS::CONSTANT_ADDRESS || - AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) - return true; - const Value *Base = getUnderlyingObject(Loc.Ptr); - AS = Base->getType()->getPointerAddressSpace(); + unsigned AS = Base->getType()->getPointerAddressSpace(); if (AS == AMDGPUAS::CONSTANT_ADDRESS || AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) return true; Index: llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll =================================================================== --- llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll +++ llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll @@ -39,8 +39,11 @@ ret void } +; pointsToConstantMemory gets to the underlying generic pointer and returns false. define void @test_cast_generic_to_constant_addrspace(i8* %p) { ; CHECK-LABEL: @test_cast_generic_to_constant_addrspace( +; CHECK-NEXT: [[CAST:%.*]] = addrspacecast i8* [[P:%.*]] to i8 addrspace(4)* +; CHECK-NEXT: store i8 0, i8 addrspace(4)* [[CAST]], align 1 ; CHECK-NEXT: ret void ; %cast = addrspacecast i8* %p to i8 addrspace(4)* @@ -48,8 +51,11 @@ ret void } +; pointsToConstantMemory gets to the underlying generic pointer and returns false. define void @test_cast_generic_to_constant32bit_addrspace(i8* %p) { ; CHECK-LABEL: @test_cast_generic_to_constant32bit_addrspace( +; CHECK-NEXT: [[CAST:%.*]] = addrspacecast i8* [[P:%.*]] to i8 addrspace(6)* +; CHECK-NEXT: store i8 0, i8 addrspace(6)* [[CAST]], align 1 ; CHECK-NEXT: ret void ; %cast = addrspacecast i8* %p to i8 addrspace(6)* Index: llvm/test/CodeGen/AMDGPU/const-addrspace-alias.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AMDGPU/const-addrspace-alias.ll @@ -0,0 +1,51 @@ +; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck --check-prefix=GCN %s + +; GCN-LABEL: {{^}}const_aliases_global: +; GCN: global_store_dword +; GCN: global_load_dword +; GCN: flat_store_dword +define amdgpu_kernel void @const_aliases_global(i32 addrspace(1)* %arg, i32 addrspace(1)* %arg.2) { +entry: + %id = tail call i32 @llvm.amdgcn.workitem.id.x() + %ptr = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %id + %ptr.2 = getelementptr inbounds i32, i32 addrspace(1)* %arg.2, i32 %id + %ptr.const = addrspacecast i32 addrspace(1)* %ptr.2 to i32 addrspace(4)* + store i32 42, i32 addrspace(1)* %ptr + %v = load i32, i32 addrspace(4)* %ptr.const + store i32 %v, i32* undef + ret void +} + +@constant_ptr = addrspace(4) global i32 undef + +; GCN-LABEL: {{^}}const_gv_does_not_alias_global: +; GCN: global_load_dword +; GCN: global_store_dword +; GCN: flat_store_dword +define amdgpu_kernel void @const_gv_does_not_alias_global(i32 addrspace(1)* %arg) { +entry: + %id = tail call i32 @llvm.amdgcn.workitem.id.x() + %ptr = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %id + %ptr.const = getelementptr inbounds i32, i32 addrspace(4)* @constant_ptr, i32 %id + store i32 42, i32 addrspace(1)* %ptr + %v = load i32, i32 addrspace(4)* %ptr.const + store i32 %v, i32* undef + ret void +} + +; GCN-LABEL: {{^}}const_arg_does_not_alias_global: +; GCN: global_load_dword +; GCN: global_store_dword +; GCN: flat_store_dword +define amdgpu_kernel void @const_arg_does_not_alias_global(i32 addrspace(1)* %arg, i32 addrspace(4)* %arg.const) { +entry: + %id = tail call i32 @llvm.amdgcn.workitem.id.x() + %ptr = getelementptr inbounds i32, i32 addrspace(1)* %arg, i32 %id + %ptr.const = getelementptr inbounds i32, i32 addrspace(4)* %arg.const, i32 %id + store i32 42, i32 addrspace(1)* %ptr + %v = load i32, i32 addrspace(4)* %ptr.const + store i32 %v, i32* undef + ret void +} + +declare i32 @llvm.amdgcn.workitem.id.x()