[llvm] 98f2549 - [globalopt] Teach to look through `addrspacecast`.
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 05:43:44 PDT 2020
Author: Michael Liao
Date: 2020-10-16T08:43:09-04:00
New Revision: 98f254960f0c7bfa96caffca05e14b3431b916d1
URL: https://github.com/llvm/llvm-project/commit/98f254960f0c7bfa96caffca05e14b3431b916d1
DIFF: https://github.com/llvm/llvm-project/commit/98f254960f0c7bfa96caffca05e14b3431b916d1.diff
LOG: [globalopt] Teach to look through `addrspacecast`.
- so that global variables in numbered address spaces could be properly
analyzed.
Differential Revision: https://reviews.llvm.org/D89140
Added:
Modified:
llvm/lib/Transforms/Utils/GlobalStatus.cpp
llvm/test/Transforms/GlobalOpt/unnamed-addr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/GlobalStatus.cpp b/llvm/lib/Transforms/Utils/GlobalStatus.cpp
index fe58f0e0fe40..f782396be7b6 100644
--- a/llvm/lib/Transforms/Utils/GlobalStatus.cpp
+++ b/llvm/lib/Transforms/Utils/GlobalStatus.cpp
@@ -136,7 +136,8 @@ static bool analyzeGlobalAux(const Value *V, GlobalStatus &GS,
GS.StoredType = GlobalStatus::Stored;
}
}
- } else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) {
+ } else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I) ||
+ isa<AddrSpaceCastInst>(I)) {
// Skip over bitcasts and GEPs; we don't care about the type or offset
// of the pointer.
if (analyzeGlobalAux(I, GS, VisitedUsers))
diff --git a/llvm/test/Transforms/GlobalOpt/unnamed-addr.ll b/llvm/test/Transforms/GlobalOpt/unnamed-addr.ll
index 9f11f1bd92c2..352dbac8f210 100644
--- a/llvm/test/Transforms/GlobalOpt/unnamed-addr.ll
+++ b/llvm/test/Transforms/GlobalOpt/unnamed-addr.ll
@@ -5,12 +5,14 @@
@c = internal global i32 0, align 4
@d = internal constant [4 x i8] c"foo\00", align 1
@e = linkonce_odr global i32 0
+ at f = internal addrspace(3) global float undef, align 4
; CHECK: @a = internal global i32 0, align 4
; CHECK: @b = internal global i32 0, align 4
; CHECK: @c = internal unnamed_addr global i32 0, align 4
; CHECK: @d = internal unnamed_addr constant [4 x i8] c"foo\00", align 1
; CHECK: @e = linkonce_odr local_unnamed_addr global i32 0
+; CHECK: @f = internal unnamed_addr addrspace(3) global float undef, align 4
; CHECK: define internal fastcc void @used_internal() unnamed_addr {
define internal void @used_internal() {
@@ -72,3 +74,15 @@ entry:
%tmp1 = load i32, i32* @c, align 4
ret i32 %tmp1
}
+
+define float @use_addrspace_cast_for_load() {
+ %p = addrspacecast float addrspace(3)* @f to float*
+ %v = load float, float* %p
+ ret float %v
+}
+
+define void @use_addrspace_cast_for_store(float %x) {
+ %p = addrspacecast float addrspace(3)* @f to float*
+ store float %x, float* %p
+ ret void
+}
More information about the llvm-commits
mailing list