[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 13:40:29 PST 2022
rampitec created this revision.
rampitec added a reviewer: arsenm.
Herald added subscribers: jeroen.dobbelaere, foad, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
Herald added a project: All.
rampitec requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
A global pointer cast to constant address space does not necessarily
mean the memory will not be modified, but may mean it will not be
modified prior to a specific use.
Fixes: SWDEV-326463
https://reviews.llvm.org/D121157
Files:
llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
llvm/lib/Target/AMDGPU/const-addrspace-alias.ll
llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll
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/const-addrspace-alias.ll
===================================================================
--- /dev/null
+++ llvm/lib/Target/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/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.413619.patch
Type: text/x-patch
Size: 3634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220307/c220ca66/attachment.bin>
More information about the llvm-commits
mailing list