Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 2 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 3 | typedef __attribute__(( ext_vector_type(4) )) float float4; |
| 4 | typedef __attribute__(( ext_vector_type(2) )) float float2; |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 5 | typedef __attribute__(( ext_vector_type(4) )) int int4; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 6 | typedef __attribute__(( ext_vector_type(4) )) unsigned int uint4; |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 7 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 8 | // CHECK: @foo = global <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00> |
Nate Begeman | d47d4f5 | 2008-01-25 05:34:48 +0000 | [diff] [blame] | 9 | float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 }; |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 10 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 11 | // CHECK: @bar = constant <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 0x7FF0000000000000> |
Nate Begeman | 59b5da6 | 2009-01-18 03:20:47 +0000 | [diff] [blame] | 12 | const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() }; |
| 13 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 14 | // CHECK: @test1 |
| 15 | // CHECK: fadd <4 x float> |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 16 | float4 test1(float4 V) { |
| 17 | return V.wzyx+V; |
| 18 | } |
| 19 | |
| 20 | float2 vec2, vec2_2; |
| 21 | float4 vec4, vec4_2; |
| 22 | float f; |
| 23 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 24 | // CHECK: @test2 |
| 25 | // CHECK: shufflevector {{.*}} <i32 0, i32 1> |
| 26 | // CHECK: extractelement |
| 27 | // CHECK: shufflevector {{.*}} <i32 1, i32 1, i32 1, i32 1> |
| 28 | // CHECK: insertelement |
| 29 | // CHECK: shufflevector {{.*}} <i32 1, i32 0> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 30 | void test2() { |
Nate Begeman | 190d6a2 | 2009-01-18 02:01:21 +0000 | [diff] [blame] | 31 | vec2 = vec4.xy; // shorten |
Chris Lattner | 90997ac | 2007-08-03 16:42:43 +0000 | [diff] [blame] | 32 | f = vec2.x; // extract elt |
| 33 | vec4 = vec4.yyyy; // splat |
| 34 | |
| 35 | vec2.x = f; // insert one. |
| 36 | vec2.yx = vec2; // reverse |
| 37 | } |
| 38 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 39 | // CHECK: @test3 |
| 40 | // CHECK: store <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 41 | void test3(float4 *out) { |
Devang Patel | a83cc33 | 2007-10-24 18:05:48 +0000 | [diff] [blame] | 42 | *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f }); |
| 43 | } |
| 44 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 45 | // CHECK: @test4 |
| 46 | // CHECK: store <4 x float> |
| 47 | // CHECK: store <4 x float> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 48 | void test4(float4 *out) { |
Devang Patel | a83cc33 | 2007-10-24 18:05:48 +0000 | [diff] [blame] | 49 | float a = 1.0f; |
| 50 | float b = 2.0f; |
| 51 | float c = 3.0f; |
| 52 | float d = 4.0f; |
| 53 | *out = ((float4) {a,b,c,d}); |
| 54 | } |
Nate Begeman | 4119d1a | 2007-12-30 02:59:45 +0000 | [diff] [blame] | 55 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 56 | // CHECK: @test5 |
| 57 | // CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer |
| 58 | // CHECK: fmul <4 x float> |
| 59 | // CHECK: fmul <4 x float> |
| 60 | // CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer |
| 61 | // CHECK: fmul <4 x float> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 62 | void test5(float4 *out) { |
Nate Begeman | 4119d1a | 2007-12-30 02:59:45 +0000 | [diff] [blame] | 63 | float a; |
| 64 | float4 b; |
| 65 | |
| 66 | a = 1.0f; |
| 67 | b = a; |
| 68 | b = b * 5.0f; |
| 69 | b = 5.0f * b; |
| 70 | b *= a; |
| 71 | |
| 72 | *out = b; |
| 73 | } |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 74 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 75 | // CHECK: @test6 |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 76 | void test6(float4 *ap, float4 *bp, float c) { |
| 77 | float4 a = *ap; |
| 78 | float4 b = *bp; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 79 | |
| 80 | // CHECK: fadd <4 x float> |
| 81 | // CHECK: fsub <4 x float> |
| 82 | // CHECK: fmul <4 x float> |
| 83 | // CHECK: fdiv <4 x float> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 84 | a = a + b; |
| 85 | a = a - b; |
| 86 | a = a * b; |
| 87 | a = a / b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 88 | |
| 89 | // CHECK: fadd <4 x float> |
| 90 | // CHECK: fsub <4 x float> |
| 91 | // CHECK: fmul <4 x float> |
| 92 | // CHECK: fdiv <4 x float> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 93 | a = a + c; |
| 94 | a = a - c; |
| 95 | a = a * c; |
| 96 | a = a / c; |
| 97 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 98 | // CHECK: fadd <4 x float> |
| 99 | // CHECK: fsub <4 x float> |
| 100 | // CHECK: fmul <4 x float> |
| 101 | // CHECK: fdiv <4 x float> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 102 | a += b; |
| 103 | a -= b; |
| 104 | a *= b; |
| 105 | a /= b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 106 | |
| 107 | // CHECK: fadd <4 x float> |
| 108 | // CHECK: fsub <4 x float> |
| 109 | // CHECK: fmul <4 x float> |
| 110 | // CHECK: fdiv <4 x float> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 111 | a += c; |
| 112 | a -= c; |
| 113 | a *= c; |
| 114 | a /= c; |
| 115 | |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 116 | // Vector comparisons can sometimes crash the x86 backend: rdar://6326239, |
| 117 | // reject them until the implementation is stable. |
| 118 | #if 0 |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 119 | int4 cmp; |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 120 | cmp = a < b; |
| 121 | cmp = a <= b; |
| 122 | cmp = a < b; |
| 123 | cmp = a >= b; |
| 124 | cmp = a == b; |
| 125 | cmp = a != b; |
Chris Lattner | d013aa1 | 2009-03-31 07:46:52 +0000 | [diff] [blame] | 126 | #endif |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 129 | // CHECK: @test7 |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 130 | void test7(int4 *ap, int4 *bp, int c) { |
| 131 | int4 a = *ap; |
| 132 | int4 b = *bp; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 133 | |
Eli Friedman | d4b9ee3 | 2011-05-06 18:04:18 +0000 | [diff] [blame] | 134 | // CHECK: add <4 x i32> |
| 135 | // CHECK: sub <4 x i32> |
| 136 | // CHECK: mul <4 x i32> |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 137 | // CHECK: sdiv <4 x i32> |
| 138 | // CHECK: srem <4 x i32> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 139 | a = a + b; |
| 140 | a = a - b; |
| 141 | a = a * b; |
| 142 | a = a / b; |
| 143 | a = a % b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 144 | |
Eli Friedman | d4b9ee3 | 2011-05-06 18:04:18 +0000 | [diff] [blame] | 145 | // CHECK: add <4 x i32> |
| 146 | // CHECK: sub <4 x i32> |
| 147 | // CHECK: mul <4 x i32> |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 148 | // CHECK: sdiv <4 x i32> |
| 149 | // CHECK: srem <4 x i32> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 150 | a = a + c; |
| 151 | a = a - c; |
| 152 | a = a * c; |
| 153 | a = a / c; |
| 154 | a = a % c; |
| 155 | |
Eli Friedman | d4b9ee3 | 2011-05-06 18:04:18 +0000 | [diff] [blame] | 156 | // CHECK: add <4 x i32> |
| 157 | // CHECK: sub <4 x i32> |
| 158 | // CHECK: mul <4 x i32> |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 159 | // CHECK: sdiv <4 x i32> |
| 160 | // CHECK: srem <4 x i32> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 161 | a += b; |
| 162 | a -= b; |
| 163 | a *= b; |
| 164 | a /= b; |
| 165 | a %= b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 166 | |
Eli Friedman | d4b9ee3 | 2011-05-06 18:04:18 +0000 | [diff] [blame] | 167 | // CHECK: add <4 x i32> |
| 168 | // CHECK: sub <4 x i32> |
| 169 | // CHECK: mul <4 x i32> |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 170 | // CHECK: sdiv <4 x i32> |
| 171 | // CHECK: srem <4 x i32> |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 172 | a += c; |
| 173 | a -= c; |
| 174 | a *= c; |
| 175 | a /= c; |
| 176 | a %= c; |
| 177 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 178 | |
Chris Lattner | 9c10fcf | 2009-07-08 01:08:03 +0000 | [diff] [blame] | 179 | // Vector comparisons. |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 180 | // CHECK: icmp slt |
| 181 | // CHECK: icmp sle |
| 182 | // CHECK: icmp sgt |
| 183 | // CHECK: icmp sge |
| 184 | // CHECK: icmp eq |
| 185 | // CHECK: icmp ne |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 186 | int4 cmp; |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 187 | cmp = a < b; |
| 188 | cmp = a <= b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 189 | cmp = a > b; |
Daniel Dunbar | 523aa60 | 2009-01-05 22:55:36 +0000 | [diff] [blame] | 190 | cmp = a >= b; |
| 191 | cmp = a == b; |
| 192 | cmp = a != b; |
| 193 | } |
Eli Friedman | 1360d4a | 2009-07-22 06:07:16 +0000 | [diff] [blame] | 194 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 195 | // CHECK: @test8 |
Eli Friedman | 1360d4a | 2009-07-22 06:07:16 +0000 | [diff] [blame] | 196 | void test8(float4 *ap, float4 *bp, int c) { |
| 197 | float4 a = *ap; |
| 198 | float4 b = *bp; |
| 199 | |
| 200 | // Vector comparisons. |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 201 | // CHECK: fcmp olt |
| 202 | // CHECK: fcmp ole |
| 203 | // CHECK: fcmp ogt |
| 204 | // CHECK: fcmp oge |
| 205 | // CHECK: fcmp oeq |
| 206 | // CHECK: fcmp une |
Eli Friedman | 1360d4a | 2009-07-22 06:07:16 +0000 | [diff] [blame] | 207 | int4 cmp; |
| 208 | cmp = a < b; |
| 209 | cmp = a <= b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 210 | cmp = a > b; |
Eli Friedman | 1360d4a | 2009-07-22 06:07:16 +0000 | [diff] [blame] | 211 | cmp = a >= b; |
| 212 | cmp = a == b; |
| 213 | cmp = a != b; |
| 214 | } |
Chris Lattner | 998eab1 | 2009-12-23 21:31:11 +0000 | [diff] [blame] | 215 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 216 | // CHECK: @test9 |
| 217 | // CHECK: extractelement <4 x i32> |
Chris Lattner | 998eab1 | 2009-12-23 21:31:11 +0000 | [diff] [blame] | 218 | int test9(int4 V) { |
| 219 | return V.xy.x; |
| 220 | } |
| 221 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 222 | // CHECK: @test10 |
Eli Friedman | d4b9ee3 | 2011-05-06 18:04:18 +0000 | [diff] [blame] | 223 | // CHECK: add <4 x i32> |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 224 | // CHECK: extractelement <4 x i32> |
Chris Lattner | 7c8f9b7 | 2009-12-23 22:06:12 +0000 | [diff] [blame] | 225 | int test10(int4 V) { |
Chris Lattner | 998eab1 | 2009-12-23 21:31:11 +0000 | [diff] [blame] | 226 | return (V+V).x; |
| 227 | } |
| 228 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 229 | // CHECK: @test11 |
| 230 | // CHECK: extractelement <4 x i32> |
Chris Lattner | 998eab1 | 2009-12-23 21:31:11 +0000 | [diff] [blame] | 231 | int4 test11a(); |
| 232 | int test11() { |
| 233 | return test11a().x; |
| 234 | } |
Eli Friedman | 9b71b97 | 2010-01-02 23:21:40 +0000 | [diff] [blame] | 235 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 236 | // CHECK: @test12 |
| 237 | // CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0> |
| 238 | // CHECK: shufflevector {{.*}} <i32 0, i32 1, i32 2, i32 undef> |
| 239 | // CHECK: shufflevector {{.*}} <i32 4, i32 5, i32 6, i32 3> |
Eli Friedman | 9b71b97 | 2010-01-02 23:21:40 +0000 | [diff] [blame] | 240 | int4 test12(int4 V) { |
| 241 | V.xyz = V.zyx; |
| 242 | return V; |
| 243 | } |
| 244 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 245 | // CHECK: @test13 |
| 246 | // CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0, i32 3> |
Eli Friedman | 9b71b97 | 2010-01-02 23:21:40 +0000 | [diff] [blame] | 247 | int4 test13(int4 *V) { |
| 248 | return V->zyxw; |
| 249 | } |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 250 | |
| 251 | // CHECK: @test14 |
| 252 | void test14(uint4 *ap, uint4 *bp, unsigned c) { |
| 253 | uint4 a = *ap; |
| 254 | uint4 b = *bp; |
Tanya Lattner | 6ec9643 | 2011-10-17 21:00:38 +0000 | [diff] [blame^] | 255 | int4 d; |
| 256 | |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 257 | // CHECK: udiv <4 x i32> |
| 258 | // CHECK: urem <4 x i32> |
| 259 | a = a / b; |
| 260 | a = a % b; |
| 261 | |
| 262 | // CHECK: udiv <4 x i32> |
| 263 | // CHECK: urem <4 x i32> |
| 264 | a = a / c; |
| 265 | a = a % c; |
| 266 | |
| 267 | // CHECK: icmp ult |
| 268 | // CHECK: icmp ule |
| 269 | // CHECK: icmp ugt |
| 270 | // CHECK: icmp uge |
| 271 | // CHECK: icmp eq |
| 272 | // CHECK: icmp ne |
Tanya Lattner | 6ec9643 | 2011-10-17 21:00:38 +0000 | [diff] [blame^] | 273 | d = a < b; |
| 274 | d = a <= b; |
| 275 | d = a > b; |
| 276 | d = a >= b; |
| 277 | d = a == b; |
| 278 | d = a != b; |
Eli Friedman | 52d6874 | 2011-04-10 04:44:11 +0000 | [diff] [blame] | 279 | } |