1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[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
This commit is contained in:
Michael Liao 2020-10-08 19:18:10 -04:00
parent 90ee9123ed
commit 8139d279fa
2 changed files with 16 additions and 1 deletions

View File

@ -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))

View File

@ -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
@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
}