[llvm] beda9d0 - AMDGPU: Skip GetUnderlyingObject check in pointsToConstantMemory

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sat May 9 13:12:43 PDT 2020


Author: Matt Arsenault
Date: 2020-05-09T16:00:08-04:00
New Revision: beda9d04c284ab68073c6b7d5a858ee609b5311c

URL: https://github.com/llvm/llvm-project/commit/beda9d04c284ab68073c6b7d5a858ee609b5311c
DIFF: https://github.com/llvm/llvm-project/commit/beda9d04c284ab68073c6b7d5a858ee609b5311c.diff

LOG: AMDGPU: Skip GetUnderlyingObject check in pointsToConstantMemory

Check the address space first before searching for the object
definition to save compile time. As an added bonus, this will now
treat casts to constant addrspace as constant.

We also seemed to be missing targeted tests for this, so add a few
missing other cases too.

Added: 
    llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
index bba132c3bc46..bb2aba044974 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.cpp
@@ -91,12 +91,16 @@ AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
 
 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, DL);
-  unsigned AS = Base->getType()->getPointerAddressSpace();
+  AS = Base->getType()->getPointerAddressSpace();
   if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
-      AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) {
+      AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT)
     return true;
-  }
 
   if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
     if (GV->isConstant())

diff  --git a/llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll b/llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll
new file mode 100644
index 000000000000..d240b0819e8b
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/aa-points-to-constant-memory.ll
@@ -0,0 +1,112 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -mtriple=amdgcn-amd-amdhsa -S -amdgpu-aa-wrapper -amdgpu-aa -instcombine -o - %s | FileCheck %s
+;
+; Test AA::pointsToConstantMemory implementation. These should mostly
+; turn out to be stores to constant memory, and will therefore be
+; deleted as UB.
+
+define void @test_constant_addrspace(i8 addrspace(4)* %p) {
+; CHECK-LABEL: @test_constant_addrspace(
+; CHECK-NEXT:    ret void
+;
+  store i8 0, i8 addrspace(4)* %p
+  ret void
+}
+
+define void @test_constant32bit_addrspace(i8 addrspace(6)* %p) {
+; CHECK-LABEL: @test_constant32bit_addrspace(
+; CHECK-NEXT:    ret void
+;
+  store i8 0, i8 addrspace(6)* %p
+  ret void
+}
+
+define void @test_cast_generic_from_constant_addrspace(i8 addrspace(4)* %p) {
+; CHECK-LABEL: @test_cast_generic_from_constant_addrspace(
+; CHECK-NEXT:    ret void
+;
+  %cast = addrspacecast i8 addrspace(4)* %p to i8*
+  store i8 0, i8* %cast
+  ret void
+}
+
+define void @test_cast_generic_from_constant32bit_addrspace(i8 addrspace(6)* %p) {
+; CHECK-LABEL: @test_cast_generic_from_constant32bit_addrspace(
+; CHECK-NEXT:    ret void
+;
+  %cast = addrspacecast i8 addrspace(6)* %p to i8*
+  store i8 0, i8* %cast
+  ret void
+}
+
+define void @test_cast_generic_to_constant_addrspace(i8* %p) {
+; CHECK-LABEL: @test_cast_generic_to_constant_addrspace(
+; CHECK-NEXT:    ret void
+;
+  %cast = addrspacecast i8* %p to i8 addrspace(4)*
+  store i8 0, i8 addrspace(4)* %cast
+  ret void
+}
+
+define void @test_cast_generic_to_constant32bit_addrspace(i8* %p) {
+; CHECK-LABEL: @test_cast_generic_to_constant32bit_addrspace(
+; CHECK-NEXT:    ret void
+;
+  %cast = addrspacecast i8* %p to i8 addrspace(6)*
+  store i8 0, i8 addrspace(6)* %cast
+  ret void
+}
+
+define amdgpu_kernel void @noalias_readnone_global_kernarg(i32 addrspace(1)* noalias readnone %arg) {
+; CHECK-LABEL: @noalias_readnone_global_kernarg(
+; CHECK-NEXT:    ret void
+;
+  store i32 0, i32 addrspace(1)* %arg
+  ret void
+}
+
+define amdgpu_kernel void @noalias_readonly_global_kernarg(i32 addrspace(1)* noalias readonly %arg) {
+; CHECK-LABEL: @noalias_readonly_global_kernarg(
+; CHECK-NEXT:    ret void
+;
+  store i32 0, i32 addrspace(1)* %arg
+  ret void
+}
+
+define amdgpu_kernel void @readnone_global_kernarg(i32 addrspace(1)* readnone %arg) {
+; CHECK-LABEL: @readnone_global_kernarg(
+; CHECK-NEXT:    store i32 0, i32 addrspace(1)* [[ARG:%.*]], align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 0, i32 addrspace(1)* %arg
+  ret void
+}
+
+define amdgpu_kernel void @readonly_global_kernarg(i32 addrspace(1)* readonly %arg) {
+; CHECK-LABEL: @readonly_global_kernarg(
+; CHECK-NEXT:    store i32 0, i32 addrspace(1)* [[ARG:%.*]], align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 0, i32 addrspace(1)* %arg
+  ret void
+}
+
+ at global_as_constant = external addrspace(1) constant i32, align 4
+
+define amdgpu_kernel void @constant_gv_global_as() {
+; CHECK-LABEL: @constant_gv_global_as(
+; CHECK-NEXT:    ret void
+;
+  store i32 0, i32 addrspace(1)* @global_as_constant
+  ret void
+}
+
+ at global_nonconstant_constant_as = external addrspace(4) global i32, align 4
+
+define amdgpu_kernel void @nonconst_gv_constant_as() {
+; CHECK-LABEL: @nonconst_gv_constant_as(
+; CHECK-NEXT:    ret void
+;
+  store i32 0, i32 addrspace(4)* @global_nonconstant_constant_as
+  ret void
+}


        


More information about the llvm-commits mailing list