teak-llvm/clang/test/CodeGen/convertvector.c
Hal Finkel c4d7c82c7f Add the intrinsic __builtin_convertvector
LLVM supports applying conversion instructions to vectors of the same number of
elements (fptrunc, fptosi, etc.) but there had been no way for a Clang user to
cause such instructions to be generated when using builtin vector types.

C-style casting on vectors is already defined in terms of bitcasts, and so
cannot be used for these conversions as well (without leading to a very
confusing set of semantics). As a result, this adds a __builtin_convertvector
intrinsic (patterned after the OpenCL __builtin_astype intrinsic). This is
intended to aid the creation of vector intrinsic headers that create generic IR
instead of target-dependent intrinsics (in other words, this is a generic
_mm_cvtepi32_ps). As noted in the documentation, the action of
__builtin_convertvector is defined in terms of the action of a C-style cast on
each vector element.

llvm-svn: 190915
2013-09-18 03:29:45 +00:00

115 lines
3.2 KiB
C

// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -target-cpu corei7-avx -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -target-cpu corei7-avx -emit-llvm -x c++ %s -o - | FileCheck %s
typedef double vector8double __attribute__((__vector_size__(64)));
typedef float vector8float __attribute__((__vector_size__(32)));
typedef long vector8long __attribute__((__vector_size__(64)));
typedef short vector8short __attribute__((__vector_size__(16)));
typedef unsigned long vector8ulong __attribute__((__vector_size__(64)));
typedef unsigned short vector8ushort __attribute__((__vector_size__(16)));
#ifdef __cplusplus
#define BOOL bool
#else
#define BOOL _Bool
#endif
typedef BOOL vector8bool __attribute__((__ext_vector_type__(8)));
#ifdef __cplusplus
extern "C" {
#endif
vector8float flt_trunc(vector8double x) {
return __builtin_convertvector(x, vector8float);
// CHECK-LABEL: @flt_trunc
// CHECK: fptrunc <8 x double> %{{[^ ]}} to <8 x float>
}
vector8double flt_ext(vector8float x) {
return __builtin_convertvector(x, vector8double);
// CHECK-LABEL: @flt_ext
// CHECK: fpext <8 x float> %{{[^ ]}} to <8 x double>
}
vector8bool flt_tobool(vector8float x) {
return __builtin_convertvector(x, vector8bool);
// CHECK-LABEL: @flt_tobool
// CHECK-NOT: fptoui <8 x float> %{{[^ ]}} to <8 x i1>
// CHECK: fcmp une <8 x float> %{{[^ ]}}, zeroinitializer
}
vector8long flt_tosi(vector8float x) {
return __builtin_convertvector(x, vector8long);
// CHECK-LABEL: @flt_tosi
// CHECK: fptosi <8 x float> %{{[^ ]}} to <8 x i64>
}
vector8ulong flt_toui(vector8float x) {
return __builtin_convertvector(x, vector8ulong);
// CHECK-LABEL: @flt_toui
// CHECK: fptoui <8 x float> %{{[^ ]}} to <8 x i64>
}
vector8ulong fltd_toui(vector8double x) {
return __builtin_convertvector(x, vector8ulong);
// CHECK-LABEL: @fltd_toui
// CHECK: fptoui <8 x double> %{{[^ ]}} to <8 x i64>
}
vector8ulong int_zext(vector8ushort x) {
return __builtin_convertvector(x, vector8ulong);
// CHECK-LABEL: @int_zext
// CHECK: zext <8 x i16> %{{[^ ]}} to <8 x i64>
}
vector8long int_sext(vector8short x) {
return __builtin_convertvector(x, vector8long);
// CHECK-LABEL: @int_sext
// CHECK: sext <8 x i16> %{{[^ ]}} to <8 x i64>
}
vector8bool int_tobool(vector8short x) {
return __builtin_convertvector(x, vector8bool);
// CHECK-LABEL: @int_tobool
// CHECK-NOT: trunc <8 x i16> %{{[^ ]}} to <8 x i1>
// CHECK: icmp ne <8 x i16> %{{[^ ]}}, zeroinitializer
}
vector8float int_tofp(vector8short x) {
return __builtin_convertvector(x, vector8float);
// CHECK-LABEL: @int_tofp
// CHECK: sitofp <8 x i16> %{{[^ ]}} to <8 x float>
}
vector8float uint_tofp(vector8ushort x) {
return __builtin_convertvector(x, vector8float);
// CHECK-LABEL: @uint_tofp
// CHECK: uitofp <8 x i16> %{{[^ ]}} to <8 x float>
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
template<typename T>
T int_toT(vector8long x) {
return __builtin_convertvector(x, T);
}
extern "C" {
vector8double int_toT_fp(vector8long x) {
// CHECK-LABEL: @int_toT_fp
// CHECK: sitofp <8 x i64> %{{[^ ]}} to <8 x double>
return int_toT<vector8double>(x);
}
}
#else
vector8double int_toT_fp(vector8long x) {
return __builtin_convertvector(x, vector8double);
}
#endif