Clang Project

clang_source_code/test/CodeGen/vecshift.c
1// RUN: %clang_cc1  -Wno-error-vec-elem-size -emit-llvm %s -o - | FileCheck %s
2// RUN: %clang_cc1  -Wno-error-vec-elem-size -DEXT -emit-llvm %s -o - | FileCheck %s
3
4#ifdef EXT
5typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
6typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
7typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
8typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8;
9typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8;
10typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8;
11typedef __attribute__((__ext_vector_type__(4))) char vector_char4;
12typedef __attribute__((__ext_vector_type__(4))) short vector_short4;
13typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
14typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
15typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
16typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
17#else
18typedef __attribute__((vector_size(8))) char vector_char8;
19typedef __attribute__((vector_size(16))) short vector_short8;
20typedef __attribute__((vector_size(32))) int vector_int8;
21typedef __attribute__((vector_size(8))) unsigned char vector_uchar8;
22typedef __attribute__((vector_size(16))) unsigned short vector_ushort8;
23typedef __attribute__((vector_size(32))) unsigned int vector_uint8;
24typedef __attribute__((vector_size(4))) char vector_char4;
25typedef __attribute__((vector_size(4))) short vector_short4;
26typedef __attribute__((vector_size(16))) int vector_int4;
27typedef __attribute__((vector_size(4))) unsigned char vector_uchar4;
28typedef __attribute__((vector_size(8))) unsigned short vector_ushort4;
29typedef __attribute__((vector_size(16))) unsigned int vector_uint4;
30#endif
31
32char c;
33short s;
34int i;
35unsigned char uc;
36unsigned short us;
37unsigned int ui;
38vector_char8 vc8;
39vector_short8 vs8;
40vector_int8 vi8;
41vector_uchar8 vuc8;
42vector_ushort8 vus8;
43vector_uint8 vui8;
44vector_char4 vc4;
45vector_short4 vs4;
46vector_int4 vi4;
47vector_uchar4 vuc4;
48vector_ushort4 vus4;
49vector_uint4 vui4;
50
51void foo() {
52  vc8 = 1 << vc8;
53// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
54// CHECK: shl <8 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>, [[t0]]
55  vuc8 = 1 << vuc8;
56// CHECK: [[t1:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
57// CHECK: shl <8 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>, [[t1]]
58  vi8 = 1 << vi8;
59// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
60// CHECK: shl <8 x i32> <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>, [[t2]]
61  vui8 = 1 << vui8;
62// CHECK: [[t3:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
63// CHECK: shl <8 x i32> <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>, [[t3]]
64  vs8 = 1 << vs8;
65// CHECK: [[t4:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
66// CHECK: shl <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, [[t4]]
67  vus8 = 1 << vus8;
68// CHECK: [[t5:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
69// CHECK: shl <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, [[t5]]
70
71  vc8 = c << vc8;
72// CHECK: [[t6:%.+]] = load i8, i8* @c,
73// CHECK: [[splat_splatinsert:%.+]] = insertelement <8 x i8> undef, i8 [[t6]], i32 0
74// CHECK: [[splat_splat:%.+]] = shufflevector <8 x i8> [[splat_splatinsert]], <8 x i8> undef, <8 x i32> zeroinitializer
75// CHECK: [[t7:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
76// CHECK: shl <8 x i8> [[splat_splat]], [[t7]]
77  vuc8 = i << vuc8;
78// CHECK: [[t8:%.+]] = load i32, i32* @i,
79// CHECK: [[tconv:%.+]] = trunc i32 [[t8]] to i8
80// CHECK: [[splat_splatinsert7:%.+]] = insertelement <8 x i8> undef, i8 [[tconv]], i32 0
81// CHECK: [[splat_splat8:%.+]] = shufflevector <8 x i8> [[splat_splatinsert7]], <8 x i8> undef, <8 x i32> zeroinitializer
82// CHECK: [[t9:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
83// CHECK: shl <8 x i8> [[splat_splat8]], [[t9]]
84  vi8 = uc << vi8;
85// CHECK: [[t10:%.+]] = load i8, i8* @uc,
86// CHECK: [[conv10:%.+]] = zext i8 [[t10]] to i32
87// CHECK: [[splat_splatinsert11:%.+]] = insertelement <8 x i32> undef, i32 [[conv10]], i32 0
88// CHECK: [[splat_splat12:%.+]] = shufflevector <8 x i32> [[splat_splatinsert11]], <8 x i32> undef, <8 x i32> zeroinitializer
89// CHECK: [[t11:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
90// CHECK: shl <8 x i32> [[splat_splat12]], [[t11]]
91  vui8 = us << vui8;
92// CHECK: [[t12:%.+]] = load i16, i16* @us,
93// CHECK: [[conv14:%.+]] = zext i16 [[t12]] to i32
94// CHECK: [[splat_splatinsert15:%.+]] = insertelement <8 x i32> undef, i32 [[conv14]], i32 0
95// CHECK: [[splat_splat16:%.+]] = shufflevector <8 x i32> [[splat_splatinsert15]], <8 x i32> undef, <8 x i32> zeroinitializer
96// CHECK: [[t13:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
97// CHECK: shl <8 x i32> [[splat_splat16]], [[t13]]
98  vs8 = ui << vs8;
99// CHECK: [[t14:%.+]] = load i32, i32* @ui,
100// CHECK: [[conv18:%.+]] = trunc i32 [[t14]] to i16
101// CHECK: [[splat_splatinsert19:%.+]] = insertelement <8 x i16> undef, i16 [[conv18]], i32 0
102// CHECK: [[splat_splat20:%.+]] = shufflevector <8 x i16> [[splat_splatinsert19]], <8 x i16> undef, <8 x i32> zeroinitializer
103// CHECK: [[t15:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
104// CHECK: shl <8 x i16> [[splat_splat20]], [[t15]]
105  vus8 = 1 << vus8;
106// CHECK: [[t16:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
107// CHECK: [[shl22:%.+]] = shl <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, [[t16]]
108
109 vc8 = vc8 << vc8;
110// CHECK: [[t17:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
111// CHECK: [[t18:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
112// CHECK: shl <8 x i8> [[t17]], [[t18]]
113  vi8 = vi8 << vuc8;
114// CHECK: [[t19:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
115// CHECK: [[t20:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
116// CHECK: [[shprom:%.+]] = zext <8 x i8> [[t20]] to <8 x i32>
117// CHECK: shl <8 x i32> [[t19]], [[shprom]]
118  vuc8 = vuc8 << vi8;
119// CHECK: [[t21:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
120// CHECK: [[t22:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
121// CHECK: [[sh_prom25:%.+]] = trunc <8 x i32> [[t22]] to <8 x i8>
122// CHECK: shl <8 x i8> [[t21]], [[sh_prom25]]
123  vus8 = vus8 << vui8;
124// CHECK: [[t23:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
125// CHECK: [[t24:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
126// CHECK: [[sh_prom27:%.+]] = trunc <8 x i32> [[t24]] to <8 x i16>
127// CHECK: shl <8 x i16> [[t23]], [[sh_prom27]]
128  vui8 = vui8 << vs8;
129// CHECK: [[t25:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
130// CHECK: [[t26:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
131// CHECK: [[sh_prom29:%.+]] = zext <8 x i16> [[t26]] to <8 x i32>
132// CHECK: shl <8 x i32> [[t25]], [[sh_prom29]]
133
134  vui8 <<= s;
135// CHECK: [[t27:%.+]] = load i16, i16* @s,
136// CHECK: [[conv40:%.+]] = sext i16 [[t27]] to i32
137// CHECK: [[splat_splatinsert41:%.+]] = insertelement <8 x i32> undef, i32 [[conv40]], i32 0
138// CHECK: [[splat_splat42:%.+]] = shufflevector <8 x i32> [[splat_splatinsert41]], <8 x i32> undef, <8 x i32> zeroinitializer
139// CHECK: [[t28:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
140// CHECK: shl <8 x i32> [[t28]], [[splat_splat42]]
141  vi8 <<= us;
142// CHECK: [[t29:%.+]] = load i16, i16* @us,
143// CHECK: [[conv44:%.+]] = zext i16 [[t29]] to i32
144// CHECK: [[splat_splatinsert45:%.+]] = insertelement <8 x i32> undef, i32 [[conv44]], i32 0
145// CHECK: [[splat_splat46:%.+]] = shufflevector <8 x i32> [[splat_splatinsert45]], <8 x i32> undef, <8 x i32> zeroinitializer
146// CHECK: [[t30:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
147// CHECK: shl <8 x i32> [[t30]], [[splat_splat46]]
148  vus8 <<= i;
149// CHECK: [[t31:%.+]] = load i32, i32* @i,
150// CHECK: [[splat_splatinsert48:%.+]] = insertelement <8 x i32> undef, i32 [[t31]], i32 0
151// CHECK: [[splat_splat49:%.+]] = shufflevector <8 x i32> [[splat_splatinsert48]], <8 x i32> undef, <8 x i32> zeroinitializer
152// CHECK: [[t32:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
153// CHECK: [[sh_prom50:%.+]] = trunc <8 x i32> [[splat_splat49]] to <8 x i16>
154// CHECK: shl <8 x i16> [[t32]], [[sh_prom50]]
155  vs8 <<= ui;
156// CHECK: [[t33:%.+]] = load i32, i32* @ui,
157// CHECK: [[splat_splatinsert52:%.+]] = insertelement <8 x i32> undef, i32 [[t33]], i32 0
158// CHECK: [[splat_splat53:%.+]] = shufflevector <8 x i32> [[splat_splatinsert52]], <8 x i32> undef, <8 x i32> zeroinitializer
159// CHECK: [[t34:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
160// CHECK: [[sh_prom54:%.+]] = trunc <8 x i32> [[splat_splat53]] to <8 x i16>
161// CHECK: shl <8 x i16> [[t34]], [[sh_prom54]]
162}
163