1 // RUN: clang-cc -emit-llvm %s -o %t
2 
3 typedef __attribute__(( ext_vector_type(4) )) float float4;
4 typedef __attribute__(( ext_vector_type(2) )) float float2;
5 typedef __attribute__(( ext_vector_type(4) )) int int4;
6 
7 float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
8 
9 const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() };
10 
11 float4 test1(float4 V) {
12   return V.wzyx+V;
13 }
14 
15 float2 vec2, vec2_2;
16 float4 vec4, vec4_2;
17 float f;
18 
19 void test2() {
20     vec2 = vec4.xy;  // shorten
21     f = vec2.x;      // extract elt
22     vec4 = vec4.yyyy;  // splat
23 
24     vec2.x = f;      // insert one.
25     vec2.yx = vec2; // reverse
26 }
27 
28 void test3(float4 *out) {
29   *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
30 }
31 
32 void test4(float4 *out) {
33   float a = 1.0f;
34   float b = 2.0f;
35   float c = 3.0f;
36   float d = 4.0f;
37   *out = ((float4) {a,b,c,d});
38 }
39 
40 void test5(float4 *out) {
41   float a;
42   float4 b;
43 
44   a = 1.0f;
45   b = a;
46   b = b * 5.0f;
47   b = 5.0f * b;
48   b *= a;
49 
50   *out = b;
51 }
52 
53 void test6(float4 *ap, float4 *bp, float c) {
54   float4 a = *ap;
55   float4 b = *bp;
56 
57   a = a + b;
58   a = a - b;
59   a = a * b;
60   a = a / b;
61 
62   a = a + c;
63   a = a - c;
64   a = a * c;
65   a = a / c;
66 
67   a += b;
68   a -= b;
69   a *= b;
70   a /= b;
71 
72   a += c;
73   a -= c;
74   a *= c;
75   a /= c;
76 
77   // Vector comparisons can sometimes crash the x86 backend: rdar://6326239,
78   // reject them until the implementation is stable.
79 #if 0
80   int4 cmp;
81   cmp = a < b;
82   cmp = a <= b;
83   cmp = a < b;
84   cmp = a >= b;
85   cmp = a == b;
86   cmp = a != b;
87 #endif
88 }
89 
90 void test7(int4 *ap, int4 *bp, int c) {
91   int4 a = *ap;
92   int4 b = *bp;
93 
94   a = a + b;
95   a = a - b;
96   a = a * b;
97   a = a / b;
98   a = a % b;
99 
100   a = a + c;
101   a = a - c;
102   a = a * c;
103   a = a / c;
104   a = a % c;
105 
106   a += b;
107   a -= b;
108   a *= b;
109   a /= b;
110   a %= b;
111 
112   a += c;
113   a -= c;
114   a *= c;
115   a /= c;
116   a %= c;
117 
118   // Vector comparisons.
119   int4 cmp;
120   cmp = a < b;
121   cmp = a <= b;
122   cmp = a < b;
123   cmp = a >= b;
124   cmp = a == b;
125   cmp = a != b;
126 }
127