[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenOpenCL / as_type.cl
blobafc76b7b57a9d64c68cb549e186293637a48e074
1 // RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - | FileCheck %s
3 typedef __attribute__(( ext_vector_type(3) )) char char3;
4 typedef __attribute__(( ext_vector_type(4) )) char char4;
5 typedef __attribute__(( ext_vector_type(16) )) char char16;
6 typedef __attribute__(( ext_vector_type(3) )) int int3;
8 //CHECK: define{{.*}} spir_func <3 x i8> @f1(<4 x i8> noundef %[[x:.*]])
9 //CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[x]], <4 x i8> poison, <3 x i32> <i32 0, i32 1, i32 2>
10 //CHECK: ret <3 x i8> %[[astype]]
11 char3 f1(char4 x) {
12 return __builtin_astype(x, char3);
15 //CHECK: define{{.*}} spir_func <4 x i8> @f2(<3 x i8> noundef %[[x:.*]])
16 //CHECK: %[[astype:.*]] = shufflevector <3 x i8> %[[x]], <3 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
17 //CHECK: ret <4 x i8> %[[astype]]
18 char4 f2(char3 x) {
19 return __builtin_astype(x, char4);
22 //CHECK: define{{.*}} spir_func <3 x i8> @f3(i32 noundef %[[x:.*]])
23 //CHECK: %[[cast:.*]] = bitcast i32 %[[x]] to <4 x i8>
24 //CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[cast]], <4 x i8> poison, <3 x i32> <i32 0, i32 1, i32 2>
25 //CHECK: ret <3 x i8> %[[astype]]
26 char3 f3(int x) {
27 return __builtin_astype(x, char3);
30 //CHECK: define{{.*}} spir_func <4 x i8> @f4(i32 noundef %[[x:.*]])
31 //CHECK: %[[astype:.*]] = bitcast i32 %[[x]] to <4 x i8>
32 //CHECK-NOT: shufflevector
33 //CHECK: ret <4 x i8> %[[astype]]
34 char4 f4(int x) {
35 return __builtin_astype(x, char4);
38 //CHECK: define{{.*}} spir_func i32 @f5(<3 x i8> noundef %[[x:.*]])
39 //CHECK: %[[shuffle:.*]] = shufflevector <3 x i8> %[[x]], <3 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
40 //CHECK: %[[astype:.*]] = bitcast <4 x i8> %[[shuffle]] to i32
41 //CHECK: ret i32 %[[astype]]
42 int f5(char3 x) {
43 return __builtin_astype(x, int);
46 //CHECK: define{{.*}} spir_func i32 @f6(<4 x i8> noundef %[[x:.*]])
47 //CHECK: %[[astype:.*]] = bitcast <4 x i8> %[[x]] to i32
48 //CHECK-NOT: shufflevector
49 //CHECK: ret i32 %[[astype]]
50 int f6(char4 x) {
51 return __builtin_astype(x, int);
54 //CHECK: define{{.*}} spir_func <3 x i8> @f7(<3 x i8> noundef returned %[[x:.*]])
55 //CHECK-NOT: bitcast
56 //CHECK-NOT: shufflevector
57 //CHECK: ret <3 x i8> %[[x]]
58 char3 f7(char3 x) {
59 return __builtin_astype(x, char3);
62 //CHECK: define{{.*}} spir_func <3 x i32> @f8(<16 x i8> noundef %[[x:.*]])
63 //CHECK: %[[cast:.*]] = bitcast <16 x i8> %[[x]] to <4 x i32>
64 //CHECK: %[[astype:.*]] = shufflevector <4 x i32> %[[cast]], <4 x i32> poison, <3 x i32> <i32 0, i32 1, i32 2>
65 //CHECK: ret <3 x i32> %[[astype]]
66 int3 f8(char16 x) {
67 return __builtin_astype(x, int3);
70 //CHECK: define{{.*}} spir_func ptr addrspace(1) @addr_cast(ptr noundef readnone %[[x:.*]])
71 //CHECK: %[[cast:.*]] ={{.*}} addrspacecast ptr %[[x]] to ptr addrspace(1)
72 //CHECK: ret ptr addrspace(1) %[[cast]]
73 global int* addr_cast(int *x) {
74 return __builtin_astype(x, global int*);
77 //CHECK: define{{.*}} spir_func ptr addrspace(1) @int_to_ptr(i32 noundef %[[x:.*]])
78 //CHECK: %[[cast:.*]] = inttoptr i32 %[[x]] to ptr addrspace(1)
79 //CHECK: ret ptr addrspace(1) %[[cast]]
80 global int* int_to_ptr(int x) {
81 return __builtin_astype(x, global int*);
84 //CHECK: define{{.*}} spir_func i32 @ptr_to_int(ptr noundef %[[x:.*]])
85 //CHECK: %[[cast:.*]] = ptrtoint ptr %[[x]] to i32
86 //CHECK: ret i32 %[[cast]]
87 int ptr_to_int(int *x) {
88 return __builtin_astype(x, int);
91 //CHECK: define{{.*}} spir_func <3 x i8> @ptr_to_char3(ptr noundef %[[x:.*]])
92 //CHECK: %[[cast1:.*]] = ptrtoint ptr %[[x]] to i32
93 //CHECK: %[[cast2:.*]] = bitcast i32 %[[cast1]] to <4 x i8>
94 //CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[cast2]], <4 x i8> poison, <3 x i32> <i32 0, i32 1, i32 2>
95 //CHECK: ret <3 x i8> %[[astype]]
96 char3 ptr_to_char3(int *x) {
97 return __builtin_astype(x, char3);
100 //CHECK: define{{.*}} spir_func ptr @char3_to_ptr(<3 x i8> noundef %[[x:.*]])
101 //CHECK: %[[astype:.*]] = shufflevector <3 x i8> %[[x]], <3 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
102 //CHECK: %[[cast1:.*]] = bitcast <4 x i8> %[[astype]] to i32
103 //CHECK: %[[cast2:.*]] = inttoptr i32 %[[cast1]] to ptr
104 //CHECK: ret ptr %[[cast2]]
105 int* char3_to_ptr(char3 x) {
106 return __builtin_astype(x, int*);