Files
clang-p2996/clang/test/CodeGen/address-space.c
Yaxun Liu 84744c152a CodeGen: Cast temporary variable to proper address space
In C++ all variables are in default address space. Previously change has been
made to cast automatic variables to default address space. However that is
not sufficient since all temporary variables need to be casted to default
address space.

This patch casts all temporary variables to default address space except those
for passing indirect arguments since they are only used for load/store.

This patch only affects target having non-zero alloca address space.

Differential Revision: https://reviews.llvm.org/D33706

llvm-svn: 305711
2017-06-19 17:03:41 +00:00

51 lines
1.6 KiB
C

// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefixes=CHECK,X86,GIZ %s
// RUN: %clang_cc1 -triple amdgcn -emit-llvm < %s | FileCheck -check-prefixes=CHECK,PIZ %s
// RUN: %clang_cc1 -triple amdgcn---amdgiz -emit-llvm < %s | FileCheck -check-prefixes=CHECK,AMDGIZ,GIZ %s
// CHECK: @foo = common addrspace(1) global
int foo __attribute__((address_space(1)));
// CHECK: @ban = common addrspace(1) global
int ban[10] __attribute__((address_space(1)));
// CHECK: @a = common global
int a __attribute__((address_space(0)));
// CHECK-LABEL: define i32 @test1()
// CHECK: load i32, i32 addrspace(1)* @foo
int test1() { return foo; }
// CHECK-LABEL: define i32 @test2(i32 %i)
// CHECK: load i32, i32 addrspace(1)*
// CHECK-NEXT: ret i32
int test2(int i) { return ban[i]; }
// Both A and B point into addrspace(2).
__attribute__((address_space(2))) int *A, *B;
// CHECK-LABEL: define void @test3()
// GIZ: load i32 addrspace(2)*, i32 addrspace(2)** @B
// PIZ: load i32 addrspace(2)*, i32 addrspace(2)* addrspace(4)* @B
// CHECK: load i32, i32 addrspace(2)*
// GIZ: load i32 addrspace(2)*, i32 addrspace(2)** @A
// PIZ: load i32 addrspace(2)*, i32 addrspace(2)* addrspace(4)* @A
// CHECK: store i32 {{.*}}, i32 addrspace(2)*
void test3() {
*A = *B;
}
// PR7437
typedef struct {
float aData[1];
} MyStruct;
// CHECK-LABEL: define void @test4(
// GIZ: call void @llvm.memcpy.p0i8.p2i8
// GIZ: call void @llvm.memcpy.p2i8.p0i8
// PIZ: call void @llvm.memcpy.p4i8.p2i8
// PIZ: call void @llvm.memcpy.p2i8.p4i8
void test4(MyStruct __attribute__((address_space(2))) *pPtr) {
MyStruct s = pPtr[0];
pPtr[0] = s;
}