• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -ffake-address-space-map -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s
2// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL2.0 -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOFAKE %s
3// When -ffake-address-space-map is not used, all addr space mapped to 0 for x86_64.
4
5// test that we generate address space casts everywhere we need conversions of
6// pointers to different address spaces
7
8// CHECK: define void @test
9void test(global int *arg_glob, generic int *arg_gen) {
10  int var_priv;
11  arg_gen = arg_glob; // implicit cast global -> generic
12  // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(4)*
13  // CHECK-NOFAKE-NOT: addrspacecast
14
15  arg_gen = &var_priv; // implicit cast with obtaining adr, private -> generic
16  // CHECK: %{{[0-9]+}} = addrspacecast i32* %var_priv to i32 addrspace(4)*
17  // CHECK-NOFAKE-NOT: addrspacecast
18
19  arg_glob = (global int *)arg_gen; // explicit cast
20  // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(4)* %{{[0-9]+}} to i32 addrspace(1)*
21  // CHECK-NOFAKE-NOT: addrspacecast
22
23  global int *var_glob =
24      (global int *)arg_glob; // explicit cast in the same address space
25  // CHECK-NOT: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(1)*
26  // CHECK-NOFAKE-NOT: addrspacecast
27
28  var_priv = arg_gen - arg_glob; // arithmetic operation
29  // CHECK: %{{.*}} = ptrtoint i32 addrspace(4)* %{{.*}} to i64
30  // CHECK: %{{.*}} = ptrtoint i32 addrspace(1)* %{{.*}} to i64
31  // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
32  // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
33
34  var_priv = arg_gen > arg_glob; // comparison
35  // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(4)*
36
37  generic void *var_gen_v = arg_glob;
38  // CHECK: addrspacecast
39  // CHECK-NOT: bitcast
40  // CHECK-NOFAKE: bitcast
41  // CHECK-NOFAKE-NOT: addrspacecast
42}
43
44// Test ternary operator.
45// CHECK: define void @test_ternary
46void test_ternary(void) {
47  global int *var_glob;
48  generic int *var_gen;
49  generic int *var_gen2;
50  generic float *var_gen_f;
51  generic void *var_gen_v;
52
53  var_gen = var_gen ? var_gen : var_gen2; // operands of the same addr spaces and the same type
54  // CHECK: icmp
55  // CHECK-NOT: addrspacecast
56  // CHECK-NOT: bitcast
57  // CHECK: phi
58  // CHECK: store i32 addrspace(4)* %{{.+}}, i32 addrspace(4)** %{{.+}}
59
60  var_gen = var_gen ? var_gen : var_glob; // operands of overlapping addr spaces and the same type
61  // CHECK: icmp
62  // CHECK-NOT: bitcast
63  // CHECK: %{{.+}} = addrspacecast i32 addrspace(1)* %{{.+}} to i32 addrspace(4)*
64  // CHECK: phi
65  // CHECK: store
66
67  typedef int int_t;
68  global int_t *var_glob_typedef;
69  var_gen = var_gen ? var_gen : var_glob_typedef; // operands of overlapping addr spaces and equivalent types
70  // CHECK: icmp
71  // CHECK-NOT: bitcast
72  // CHECK: %{{.+}} = addrspacecast i32 addrspace(1)* %{{.+}} to i32 addrspace(4)*
73  // CHECK: phi
74  // CHECK: store
75
76  var_gen_v = var_gen ? var_gen : var_gen_f; // operands of the same addr space and different types
77  // CHECK: icmp
78  // CHECK: %{{.+}} = bitcast i32 addrspace(4)* %{{.+}} to i8 addrspace(4)*
79  // CHECK: %{{.+}} = bitcast float addrspace(4)* %{{.+}} to i8 addrspace(4)*
80  // CHECK: phi
81  // CHECK: store
82
83  var_gen_v = var_gen ? var_glob : var_gen_f; // operands of overlapping addr spaces and different types
84  // CHECK: icmp
85  // CHECK: %{{.+}} = addrspacecast i32 addrspace(1)* %{{.+}} to i8 addrspace(4)*
86  // CHECK: %{{.+}} = bitcast float addrspace(4)* %{{.+}} to i8 addrspace(4)*
87  // CHECK: phi
88  // CHECK: store
89}
90