1 | // RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - | FileCheck %s |
2 | |
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; |
7 | |
8 | //CHECK: define spir_func <3 x i8> @f1(<4 x i8> %[[x:.*]]) |
9 | //CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[x]], <4 x i8> undef, <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); |
13 | } |
14 | |
15 | //CHECK: define spir_func <4 x i8> @f2(<3 x i8> %[[x:.*]]) |
16 | //CHECK: %[[astype:.*]] = shufflevector <3 x i8> %[[x]], <3 x i8> undef, <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); |
20 | } |
21 | |
22 | //CHECK: define spir_func <3 x i8> @f3(i32 %[[x:.*]]) |
23 | //CHECK: %[[cast:.*]] = bitcast i32 %[[x]] to <4 x i8> |
24 | //CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[cast]], <4 x i8> undef, <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); |
28 | } |
29 | |
30 | //CHECK: define spir_func <4 x i8> @f4(i32 %[[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); |
36 | } |
37 | |
38 | //CHECK: define spir_func i32 @f5(<3 x i8> %[[x:.*]]) |
39 | //CHECK: %[[shuffle:.*]] = shufflevector <3 x i8> %[[x]], <3 x i8> undef, <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); |
44 | } |
45 | |
46 | //CHECK: define spir_func i32 @f6(<4 x i8> %[[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); |
52 | } |
53 | |
54 | //CHECK: define spir_func <3 x i8> @f7(<3 x i8> 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); |
60 | } |
61 | |
62 | //CHECK: define spir_func <3 x i32> @f8(<16 x i8> %[[x:.*]]) |
63 | //CHECK: %[[cast:.*]] = bitcast <16 x i8> %[[x]] to <4 x i32> |
64 | //CHECK: %[[astype:.*]] = shufflevector <4 x i32> %[[cast]], <4 x i32> undef, <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); |
68 | } |
69 | |
70 | //CHECK: define spir_func i32 addrspace(1)* @addr_cast(i32* readnone %[[x:.*]]) |
71 | //CHECK: %[[cast:.*]] = addrspacecast i32* %[[x]] to i32 addrspace(1)* |
72 | //CHECK: ret i32 addrspace(1)* %[[cast]] |
73 | global int* addr_cast(int *x) { |
74 | return __builtin_astype(x, global int*); |
75 | } |
76 | |
77 | //CHECK: define spir_func i32 addrspace(1)* @int_to_ptr(i32 %[[x:.*]]) |
78 | //CHECK: %[[cast:.*]] = inttoptr i32 %[[x]] to i32 addrspace(1)* |
79 | //CHECK: ret i32 addrspace(1)* %[[cast]] |
80 | global int* int_to_ptr(int x) { |
81 | return __builtin_astype(x, global int*); |
82 | } |
83 | |
84 | //CHECK: define spir_func i32 @ptr_to_int(i32* %[[x:.*]]) |
85 | //CHECK: %[[cast:.*]] = ptrtoint i32* %[[x]] to i32 |
86 | //CHECK: ret i32 %[[cast]] |
87 | int ptr_to_int(int *x) { |
88 | return __builtin_astype(x, int); |
89 | } |
90 | |
91 | //CHECK: define spir_func <3 x i8> @ptr_to_char3(i32* %[[x:.*]]) |
92 | //CHECK: %[[cast1:.*]] = ptrtoint i32* %[[x]] to i32 |
93 | //CHECK: %[[cast2:.*]] = bitcast i32 %[[cast1]] to <4 x i8> |
94 | //CHECK: %[[astype:.*]] = shufflevector <4 x i8> %[[cast2]], <4 x i8> undef, <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); |
98 | } |
99 | |
100 | //CHECK: define spir_func i32* @char3_to_ptr(<3 x i8> %[[x:.*]]) |
101 | //CHECK: %[[astype:.*]] = shufflevector <3 x i8> %[[x]], <3 x i8> undef, <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 i32* |
104 | //CHECK: ret i32* %[[cast2]] |
105 | int* char3_to_ptr(char3 x) { |
106 | return __builtin_astype(x, int*); |
107 | } |
108 | |