2011-04-10 12:44:11 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
|
2007-08-04 00:42:43 +08:00
|
|
|
|
2008-04-19 07:10:10 +08:00
|
|
|
typedef __attribute__(( ext_vector_type(4) )) float float4;
|
|
|
|
typedef __attribute__(( ext_vector_type(2) )) float float2;
|
2009-01-06 06:55:36 +08:00
|
|
|
typedef __attribute__(( ext_vector_type(4) )) int int4;
|
2011-04-10 12:44:11 +08:00
|
|
|
typedef __attribute__(( ext_vector_type(4) )) unsigned int uint4;
|
2007-08-04 00:42:43 +08:00
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @foo = {{(dso_local )?}}global <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>
|
2008-01-25 13:34:48 +08:00
|
|
|
float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
|
2007-08-04 00:42:43 +08:00
|
|
|
|
2018-02-24 03:30:48 +08:00
|
|
|
// CHECK: @bar = {{(dso_local )?}}constant <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 0x7FF0000000000000>
|
2009-01-18 11:20:47 +08:00
|
|
|
const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() };
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test1
|
|
|
|
// CHECK: fadd <4 x float>
|
2007-08-04 00:42:43 +08:00
|
|
|
float4 test1(float4 V) {
|
|
|
|
return V.wzyx+V;
|
|
|
|
}
|
|
|
|
|
|
|
|
float2 vec2, vec2_2;
|
|
|
|
float4 vec4, vec4_2;
|
|
|
|
float f;
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test2
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 0, i32 1>
|
|
|
|
// CHECK: extractelement
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 1, i32 1, i32 1, i32 1>
|
|
|
|
// CHECK: insertelement
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 1, i32 0>
|
2022-02-16 05:06:01 +08:00
|
|
|
void test2(void) {
|
2009-01-18 10:01:21 +08:00
|
|
|
vec2 = vec4.xy; // shorten
|
2007-08-04 00:42:43 +08:00
|
|
|
f = vec2.x; // extract elt
|
|
|
|
vec4 = vec4.yyyy; // splat
|
|
|
|
|
|
|
|
vec2.x = f; // insert one.
|
|
|
|
vec2.yx = vec2; // reverse
|
|
|
|
}
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test3
|
|
|
|
// CHECK: store <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>
|
2009-01-06 06:55:36 +08:00
|
|
|
void test3(float4 *out) {
|
2007-10-25 02:05:48 +08:00
|
|
|
*out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
|
|
|
|
}
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test4
|
|
|
|
// CHECK: store <4 x float>
|
|
|
|
// CHECK: store <4 x float>
|
2009-01-06 06:55:36 +08:00
|
|
|
void test4(float4 *out) {
|
2007-10-25 02:05:48 +08:00
|
|
|
float a = 1.0f;
|
|
|
|
float b = 2.0f;
|
|
|
|
float c = 3.0f;
|
|
|
|
float d = 4.0f;
|
|
|
|
*out = ((float4) {a,b,c,d});
|
|
|
|
}
|
2007-12-30 10:59:45 +08:00
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test5
|
|
|
|
// CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer
|
|
|
|
// CHECK: fmul <4 x float>
|
|
|
|
// CHECK: fmul <4 x float>
|
|
|
|
// CHECK: shufflevector {{.*}} <4 x i32> zeroinitializer
|
|
|
|
// CHECK: fmul <4 x float>
|
2009-01-06 06:55:36 +08:00
|
|
|
void test5(float4 *out) {
|
2007-12-30 10:59:45 +08:00
|
|
|
float a;
|
|
|
|
float4 b;
|
|
|
|
|
|
|
|
a = 1.0f;
|
|
|
|
b = a;
|
|
|
|
b = b * 5.0f;
|
|
|
|
b = 5.0f * b;
|
|
|
|
b *= a;
|
|
|
|
|
|
|
|
*out = b;
|
|
|
|
}
|
2009-01-06 06:55:36 +08:00
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test6
|
2009-01-06 06:55:36 +08:00
|
|
|
void test6(float4 *ap, float4 *bp, float c) {
|
|
|
|
float4 a = *ap;
|
|
|
|
float4 b = *bp;
|
2011-04-10 12:44:11 +08:00
|
|
|
|
|
|
|
// CHECK: fadd <4 x float>
|
|
|
|
// CHECK: fsub <4 x float>
|
|
|
|
// CHECK: fmul <4 x float>
|
|
|
|
// CHECK: fdiv <4 x float>
|
2009-01-06 06:55:36 +08:00
|
|
|
a = a + b;
|
|
|
|
a = a - b;
|
|
|
|
a = a * b;
|
|
|
|
a = a / b;
|
2011-04-10 12:44:11 +08:00
|
|
|
|
|
|
|
// CHECK: fadd <4 x float>
|
|
|
|
// CHECK: fsub <4 x float>
|
|
|
|
// CHECK: fmul <4 x float>
|
|
|
|
// CHECK: fdiv <4 x float>
|
2009-01-06 06:55:36 +08:00
|
|
|
a = a + c;
|
|
|
|
a = a - c;
|
|
|
|
a = a * c;
|
|
|
|
a = a / c;
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: fadd <4 x float>
|
|
|
|
// CHECK: fsub <4 x float>
|
|
|
|
// CHECK: fmul <4 x float>
|
|
|
|
// CHECK: fdiv <4 x float>
|
2009-01-06 06:55:36 +08:00
|
|
|
a += b;
|
|
|
|
a -= b;
|
|
|
|
a *= b;
|
|
|
|
a /= b;
|
2011-04-10 12:44:11 +08:00
|
|
|
|
|
|
|
// CHECK: fadd <4 x float>
|
|
|
|
// CHECK: fsub <4 x float>
|
|
|
|
// CHECK: fmul <4 x float>
|
|
|
|
// CHECK: fdiv <4 x float>
|
2009-01-06 06:55:36 +08:00
|
|
|
a += c;
|
|
|
|
a -= c;
|
|
|
|
a *= c;
|
|
|
|
a /= c;
|
|
|
|
|
2009-03-31 15:46:52 +08:00
|
|
|
// Vector comparisons can sometimes crash the x86 backend: rdar://6326239,
|
|
|
|
// reject them until the implementation is stable.
|
|
|
|
#if 0
|
2009-01-06 06:55:36 +08:00
|
|
|
int4 cmp;
|
|
|
|
cmp = a < b;
|
|
|
|
cmp = a <= b;
|
|
|
|
cmp = a < b;
|
|
|
|
cmp = a >= b;
|
|
|
|
cmp = a == b;
|
|
|
|
cmp = a != b;
|
2009-03-31 15:46:52 +08:00
|
|
|
#endif
|
2009-01-06 06:55:36 +08:00
|
|
|
}
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test7
|
2009-01-06 06:55:36 +08:00
|
|
|
void test7(int4 *ap, int4 *bp, int c) {
|
|
|
|
int4 a = *ap;
|
|
|
|
int4 b = *bp;
|
2011-04-10 12:44:11 +08:00
|
|
|
|
2011-05-07 02:04:18 +08:00
|
|
|
// CHECK: add <4 x i32>
|
|
|
|
// CHECK: sub <4 x i32>
|
|
|
|
// CHECK: mul <4 x i32>
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: sdiv <4 x i32>
|
|
|
|
// CHECK: srem <4 x i32>
|
2009-01-06 06:55:36 +08:00
|
|
|
a = a + b;
|
|
|
|
a = a - b;
|
|
|
|
a = a * b;
|
|
|
|
a = a / b;
|
|
|
|
a = a % b;
|
2011-04-10 12:44:11 +08:00
|
|
|
|
2011-05-07 02:04:18 +08:00
|
|
|
// CHECK: add <4 x i32>
|
|
|
|
// CHECK: sub <4 x i32>
|
|
|
|
// CHECK: mul <4 x i32>
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: sdiv <4 x i32>
|
|
|
|
// CHECK: srem <4 x i32>
|
2009-01-06 06:55:36 +08:00
|
|
|
a = a + c;
|
|
|
|
a = a - c;
|
|
|
|
a = a * c;
|
|
|
|
a = a / c;
|
|
|
|
a = a % c;
|
|
|
|
|
2011-05-07 02:04:18 +08:00
|
|
|
// CHECK: add <4 x i32>
|
|
|
|
// CHECK: sub <4 x i32>
|
|
|
|
// CHECK: mul <4 x i32>
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: sdiv <4 x i32>
|
|
|
|
// CHECK: srem <4 x i32>
|
2009-01-06 06:55:36 +08:00
|
|
|
a += b;
|
|
|
|
a -= b;
|
|
|
|
a *= b;
|
|
|
|
a /= b;
|
|
|
|
a %= b;
|
2011-04-10 12:44:11 +08:00
|
|
|
|
2011-05-07 02:04:18 +08:00
|
|
|
// CHECK: add <4 x i32>
|
|
|
|
// CHECK: sub <4 x i32>
|
|
|
|
// CHECK: mul <4 x i32>
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: sdiv <4 x i32>
|
|
|
|
// CHECK: srem <4 x i32>
|
2009-01-06 06:55:36 +08:00
|
|
|
a += c;
|
|
|
|
a -= c;
|
|
|
|
a *= c;
|
|
|
|
a /= c;
|
|
|
|
a %= c;
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
|
2009-07-08 09:08:03 +08:00
|
|
|
// Vector comparisons.
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: icmp slt
|
|
|
|
// CHECK: icmp sle
|
|
|
|
// CHECK: icmp sgt
|
|
|
|
// CHECK: icmp sge
|
|
|
|
// CHECK: icmp eq
|
|
|
|
// CHECK: icmp ne
|
2009-01-06 06:55:36 +08:00
|
|
|
int4 cmp;
|
|
|
|
cmp = a < b;
|
|
|
|
cmp = a <= b;
|
2011-04-10 12:44:11 +08:00
|
|
|
cmp = a > b;
|
2009-01-06 06:55:36 +08:00
|
|
|
cmp = a >= b;
|
|
|
|
cmp = a == b;
|
|
|
|
cmp = a != b;
|
|
|
|
}
|
2009-07-22 14:07:16 +08:00
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test8
|
2009-07-22 14:07:16 +08:00
|
|
|
void test8(float4 *ap, float4 *bp, int c) {
|
|
|
|
float4 a = *ap;
|
|
|
|
float4 b = *bp;
|
|
|
|
|
|
|
|
// Vector comparisons.
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: fcmp olt
|
|
|
|
// CHECK: fcmp ole
|
|
|
|
// CHECK: fcmp ogt
|
|
|
|
// CHECK: fcmp oge
|
|
|
|
// CHECK: fcmp oeq
|
|
|
|
// CHECK: fcmp une
|
2009-07-22 14:07:16 +08:00
|
|
|
int4 cmp;
|
|
|
|
cmp = a < b;
|
|
|
|
cmp = a <= b;
|
2011-04-10 12:44:11 +08:00
|
|
|
cmp = a > b;
|
2009-07-22 14:07:16 +08:00
|
|
|
cmp = a >= b;
|
|
|
|
cmp = a == b;
|
|
|
|
cmp = a != b;
|
|
|
|
}
|
2009-12-24 05:31:11 +08:00
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test9
|
|
|
|
// CHECK: extractelement <4 x i32>
|
2009-12-24 05:31:11 +08:00
|
|
|
int test9(int4 V) {
|
|
|
|
return V.xy.x;
|
|
|
|
}
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test10
|
2011-05-07 02:04:18 +08:00
|
|
|
// CHECK: add <4 x i32>
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: extractelement <4 x i32>
|
2009-12-24 06:06:12 +08:00
|
|
|
int test10(int4 V) {
|
2009-12-24 05:31:11 +08:00
|
|
|
return (V+V).x;
|
|
|
|
}
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test11
|
|
|
|
// CHECK: extractelement <4 x i32>
|
2022-02-16 05:06:01 +08:00
|
|
|
int4 test11a(void);
|
|
|
|
int test11(void) {
|
2009-12-24 05:31:11 +08:00
|
|
|
return test11a().x;
|
|
|
|
}
|
2010-01-03 07:21:40 +08:00
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test12
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0>
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 0, i32 1, i32 2, i32 undef>
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 4, i32 5, i32 6, i32 3>
|
2010-01-03 07:21:40 +08:00
|
|
|
int4 test12(int4 V) {
|
|
|
|
V.xyz = V.zyx;
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: @test13
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0, i32 3>
|
2010-01-03 07:21:40 +08:00
|
|
|
int4 test13(int4 *V) {
|
|
|
|
return V->zyxw;
|
|
|
|
}
|
2011-04-10 12:44:11 +08:00
|
|
|
|
|
|
|
// CHECK: @test14
|
|
|
|
void test14(uint4 *ap, uint4 *bp, unsigned c) {
|
|
|
|
uint4 a = *ap;
|
|
|
|
uint4 b = *bp;
|
2011-10-18 05:00:38 +08:00
|
|
|
int4 d;
|
|
|
|
|
2011-04-10 12:44:11 +08:00
|
|
|
// CHECK: udiv <4 x i32>
|
|
|
|
// CHECK: urem <4 x i32>
|
|
|
|
a = a / b;
|
|
|
|
a = a % b;
|
|
|
|
|
|
|
|
// CHECK: udiv <4 x i32>
|
|
|
|
// CHECK: urem <4 x i32>
|
|
|
|
a = a / c;
|
|
|
|
a = a % c;
|
|
|
|
|
|
|
|
// CHECK: icmp ult
|
|
|
|
// CHECK: icmp ule
|
|
|
|
// CHECK: icmp ugt
|
|
|
|
// CHECK: icmp uge
|
|
|
|
// CHECK: icmp eq
|
|
|
|
// CHECK: icmp ne
|
2011-10-18 05:00:38 +08:00
|
|
|
d = a < b;
|
|
|
|
d = a <= b;
|
|
|
|
d = a > b;
|
|
|
|
d = a >= b;
|
|
|
|
d = a == b;
|
|
|
|
d = a != b;
|
2011-04-10 12:44:11 +08:00
|
|
|
}
|
2012-01-17 05:02:28 +08:00
|
|
|
|
|
|
|
// CHECK: @test15
|
|
|
|
int4 test15(uint4 V0) {
|
|
|
|
// CHECK: icmp eq <4 x i32>
|
|
|
|
int4 V = !V0;
|
|
|
|
V = V && V;
|
|
|
|
V = V || V;
|
|
|
|
return V;
|
2012-01-17 05:15:33 +08:00
|
|
|
}
|
2013-06-08 10:15:36 +08:00
|
|
|
|
|
|
|
// CHECK: @test16
|
|
|
|
void test16(float2 a, float2 b) {
|
|
|
|
float2 t0 = (a + b) / 2;
|
|
|
|
}
|
2013-09-03 04:32:37 +08:00
|
|
|
|
|
|
|
typedef char char16 __attribute__((ext_vector_type(16)));
|
|
|
|
|
|
|
|
// CHECK: @test17
|
|
|
|
void test17(void) {
|
|
|
|
char16 valA;
|
|
|
|
char valB;
|
|
|
|
char valC;
|
|
|
|
char16 destVal = valC ? valA : valB;
|
|
|
|
}
|
2016-07-23 02:49:43 +08:00
|
|
|
|
|
|
|
typedef __attribute__(( ext_vector_type(16) )) float float16;
|
|
|
|
|
|
|
|
float16 vec16, vec16_2;
|
|
|
|
|
|
|
|
// CHECK: @test_rgba
|
2022-02-16 05:06:01 +08:00
|
|
|
void test_rgba(void) {
|
2016-07-23 02:49:43 +08:00
|
|
|
// CHECK: fadd <4 x float>
|
|
|
|
vec4_2 = vec4.abgr + vec4;
|
|
|
|
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 0, i32 1>
|
|
|
|
vec2 = vec4.rg;
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 2, i32 3>
|
|
|
|
vec2_2 = vec4.ba;
|
|
|
|
// CHECK: extractelement {{.*}} 2
|
|
|
|
f = vec4.b;
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 2, i32 2, i32 2, i32 2>
|
|
|
|
vec4_2 = vec4_2.bbbb;
|
|
|
|
|
|
|
|
// CHECK: insertelement {{.*}} 0
|
|
|
|
vec2.r = f;
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 1, i32 0>
|
|
|
|
vec2.gr = vec2;
|
|
|
|
|
|
|
|
// CHECK: extractelement {{.*}} 0
|
|
|
|
f = vec4_2.rg.r;
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 2, i32 1, i32 0>
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 0, i32 1, i32 2, i32 undef>
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 4, i32 5, i32 6, i32 3>
|
|
|
|
vec4.rgb = vec4.bgr;
|
|
|
|
|
|
|
|
// CHECK: extractelement {{.*}} 11
|
|
|
|
// CHECK: insertelement {{.*}} 2
|
|
|
|
vec4.b = vec16.sb;
|
|
|
|
// CHECK: shufflevector {{.*}} <i32 10, i32 11, i32 12, i32 13>
|
|
|
|
vec4_2 = vec16.sabcd;
|
|
|
|
}
|