blob: becbc4ac504c1fc455530159cd2333cd2a7e2f38 [file] [log] [blame]
Yaxun Liub34ec822017-04-11 17:24:23 +00001// RUN: %clang_cc1 -triple amdgcn -emit-llvm < %s | FileCheck -check-prefixes=PIZ,COM %s
2// RUN: %clang_cc1 -triple amdgcn---amdgiz -emit-llvm < %s | FileCheck -check-prefixes=CHECK,COM %s
3
4// PIZ-DAG: @foo = common addrspace(4) global i32 0
5// CHECK-DAG: @foo = common global i32 0
6int foo;
7
8// PIZ-DAG: @ban = common addrspace(4) global [10 x i32] zeroinitializer
9// CHECK-DAG: @ban = common global [10 x i32] zeroinitializer
10int ban[10];
11
12// PIZ-DAG: @A = common addrspace(4) global i32 addrspace(4)* null
13// PIZ-DAG: @B = common addrspace(4) global i32 addrspace(4)* null
14// CHECK-DAG: @A = common global i32* null
15// CHECK-DAG: @B = common global i32* null
16int *A;
17int *B;
18
19// COM-LABEL: define i32 @test1()
20// PIZ: load i32, i32 addrspace(4)* @foo
21// CHECK: load i32, i32* @foo
22int test1() { return foo; }
23
24// COM-LABEL: define i32 @test2(i32 %i)
Yaxun Liu84744c12017-06-19 17:03:41 +000025// COM: %[[addr:.*]] = getelementptr
26// PIZ: load i32, i32 addrspace(4)* %[[addr]]
Yaxun Liub34ec822017-04-11 17:24:23 +000027// PIZ-NEXT: ret i32
Yaxun Liu84744c12017-06-19 17:03:41 +000028// CHECK: load i32, i32* %[[addr]]
Yaxun Liub34ec822017-04-11 17:24:23 +000029// CHECK-NEXT: ret i32
30int test2(int i) { return ban[i]; }
31
32// COM-LABEL: define void @test3()
33// PIZ: load i32 addrspace(4)*, i32 addrspace(4)* addrspace(4)* @B
34// PIZ: load i32, i32 addrspace(4)*
35// PIZ: load i32 addrspace(4)*, i32 addrspace(4)* addrspace(4)* @A
36// PIZ: store i32 {{.*}}, i32 addrspace(4)*
37// CHECK: load i32*, i32** @B
38// CHECK: load i32, i32*
39// CHECK: load i32*, i32** @A
40// CHECK: store i32 {{.*}}, i32*
41void test3() {
42 *A = *B;
43}
44
45// PIZ-LABEL: define void @test4(i32 addrspace(4)* %a)
Yaxun Liu84744c12017-06-19 17:03:41 +000046// PIZ: %[[alloca:.*]] = alloca i32 addrspace(4)*
47// PIZ: %[[a_addr:.*]] = addrspacecast{{.*}} %[[alloca]] to i32 addrspace(4)* addrspace(4)*
48// PIZ: store i32 addrspace(4)* %a, i32 addrspace(4)* addrspace(4)* %[[a_addr]]
49// PIZ: %[[r0:.*]] = load i32 addrspace(4)*, i32 addrspace(4)* addrspace(4)* %[[a_addr]]
Yaxun Liub34ec822017-04-11 17:24:23 +000050// PIZ: %[[arrayidx:.*]] = getelementptr inbounds i32, i32 addrspace(4)* %[[r0]]
51// PIZ: store i32 0, i32 addrspace(4)* %[[arrayidx]]
52// CHECK-LABEL: define void @test4(i32* %a)
Yaxun Liu25d1b432017-07-05 04:58:24 +000053// CHECK: %[[alloca:.*]] = alloca i32*, align 8, addrspace(5)
Yaxun Liu84744c12017-06-19 17:03:41 +000054// CHECK: %[[a_addr:.*]] = addrspacecast{{.*}} %[[alloca]] to i32**
55// CHECK: store i32* %a, i32** %[[a_addr]]
56// CHECK: %[[r0:.*]] = load i32*, i32** %[[a_addr]]
Yaxun Liub34ec822017-04-11 17:24:23 +000057// CHECK: %[[arrayidx:.*]] = getelementptr inbounds i32, i32* %[[r0]]
58// CHECK: store i32 0, i32* %[[arrayidx]]
59void test4(int *a) {
60 a[0] = 0;
61}