[PATCH] D121157: [AMDGPU] always use underlying object in the pointsToConstantMemory

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 7 14:52:30 PST 2022


rampitec updated this revision to Diff 413639.
rampitec added a comment.

Moved test into right folder.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121157/new/

https://reviews.llvm.org/D121157

Files:
  llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
  llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll
  llvm/test/CodeGen/AMDGPU/const-addrspace-alias.ll


Index: llvm/test/CodeGen/AMDGPU/const-addrspace-alias.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/const-addrspace-alias.ll
@@ -0,0 +1,36 @@
+; 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
+}
+
+ at constant_ptr = addrspace(4) global i32 undef
+
+; GCN-LABEL: {{^}}const_does_not_alias_global:
+; GCN: global_load_dword
+; GCN: global_store_dword
+; GCN: flat_store_dword
+define amdgpu_kernel void @const_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
+}
+
+declare i32 @llvm.amdgcn.workitem.id.x()
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/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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121157.413639.patch
Type: text/x-patch
Size: 3638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220307/11d9b75f/attachment.bin>


More information about the llvm-commits mailing list