From: Anton Korobeynikov Date: Fri, 14 Oct 2011 23:32:50 +0000 (+0000) Subject: Missed tests for half FP support X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8eb5b29ec11f5f6922132a68f8e88a9b0f69a489;p=clang Missed tests for half FP support git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142017 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/CodeGen/fp16-ops.c b/test/CodeGen/fp16-ops.c new file mode 100644 index 0000000000..cbbfb884df --- /dev/null +++ b/test/CodeGen/fp16-ops.c @@ -0,0 +1,283 @@ +// RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s +typedef unsigned cond_t; + +volatile cond_t test; +volatile __fp16 h0 = 0.0, h1 = 1.0, h2; +volatile float f0, f1, f2; + +void foo(void) { + // CHECK: define void @foo() + + // Check unary ops + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK fptoi float + test = (h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une float + test = (!h1); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = -h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = +h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1++; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + ++h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + --h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1--; + + // Check binary ops with various operands + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = h0 * h2; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call i16 @llvm.convert.to.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = h0 * (__fp16) -2.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = h0 * f2; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = f0 * h2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h0 / h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h0 / (__fp16) -2.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h0 / f2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (f0 / h2); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 + h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = ((__fp16)-2.0 + h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 + f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (f2 + h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 - h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = ((__fp16)-2.0 - h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h2 - f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub float + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (f2 - h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (h2 < h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (h2 < (__fp16)42.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (h2 < f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp olt + test = (f2 < h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = (h0 > h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = ((__fp16)42.0 > h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = (h0 > f2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ogt + test = (f0 > h2); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (h2 <= h0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (h2 <= (__fp16)42.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (h2 <= f0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp ole + test = (f2 <= h0); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (h0 >= h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (h0 >= (__fp16)-2.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (h0 >= f2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oge + test = (f0 >= h2); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (h1 == h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (h1 == (__fp16)1.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (h1 == f1); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp oeq + test = (f1 == h1); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (h1 != h2); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (h1 != (__fp16)1.0); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (h1 != f1); + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + test = (f1 != h1); + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fcmp une + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call i16 @llvm.convert.to.fp16 + h1 = (h1 ? h2 : h0); + // Check assignments (inc. compound) + h0 = h1; + // CHECK: call i16 @llvm.convert.to.fp16 + h0 = (__fp16)-2.0; + // CHECK: call i16 @llvm.convert.to.fp16 + h0 = f0; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd float + // CHECK: call i16 @llvm.convert.to.fp16 + h0 += h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd + // CHECK: call i16 @llvm.convert.to.fp16 + h0 += (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fadd + // CHECK: call i16 @llvm.convert.to.fp16 + h0 += f2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub + // CHECK: call i16 @llvm.convert.to.fp16 + h0 -= h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub + // CHECK: call i16 @llvm.convert.to.fp16 + h0 -= (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fsub + // CHECK: call i16 @llvm.convert.to.fp16 + h0 -= f2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul + // CHECK: call i16 @llvm.convert.to.fp16 + h0 *= h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul + // CHECK: call i16 @llvm.convert.to.fp16 + h0 *= (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fmul + // CHECK: call i16 @llvm.convert.to.fp16 + h0 *= f2; + + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv + // CHECK: call i16 @llvm.convert.to.fp16 + h0 /= h1; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv + // CHECK: call i16 @llvm.convert.to.fp16 + h0 /= (__fp16)1.0; + // CHECK: call float @llvm.convert.from.fp16 + // CHECK: fdiv + // CHECK: call i16 @llvm.convert.to.fp16 + h0 /= f2; +} diff --git a/test/CodeGenCXX/fp16-mangle.cpp b/test/CodeGenCXX/fp16-mangle.cpp new file mode 100644 index 0000000000..4a056d6c6b --- /dev/null +++ b/test/CodeGenCXX/fp16-mangle.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s + +// CHECK: @_ZN1SIDhDhE1iE = global i32 3 +template struct S { static int i; }; +template <> int S<__fp16, __fp16>::i = 3; + +// CHECK: define void @_Z1fPDh(i16* %x) +void f (__fp16 *x) { } + +// CHECK: define void @_Z1gPDhS_(i16* %x, i16* %y) +void g (__fp16 *x, __fp16 *y) { } + diff --git a/test/CodeGenCXX/fp16-overload.cpp b/test/CodeGenCXX/fp16-overload.cpp new file mode 100644 index 0000000000..75622109c1 --- /dev/null +++ b/test/CodeGenCXX/fp16-overload.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -o - -triple arm-none-linux-gnueabi %s | FileCheck %s + +extern int foo(float x); +extern int foo(double x); + +__fp16 a; + +// CHECK: call i32 @_Z3foof +// CHECK-NOT: call i32 @_Z3food +int bar (void) { return foo(a); } diff --git a/test/Sema/fp16-sema.c b/test/Sema/fp16-sema.c new file mode 100644 index 0000000000..e678f9a829 --- /dev/null +++ b/test/Sema/fp16-sema.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Functions cannot have parameters of type __fp16. +extern void f (__fp16); // expected-error {{parameters cannot have __fp16 type; did you forget * ?}} +extern void g (__fp16 *); + +extern void (*pf) (__fp16); // expected-error {{parameters cannot have __fp16 type; did you forget * ?}} +extern void (*pg) (__fp16*); + +typedef void(*tf) (__fp16); // expected-error {{parameters cannot have __fp16 type; did you forget * ?}} +typedef void(*tg) (__fp16*); + +void kf(a) + __fp16 a; { // expected-error {{parameters cannot have __fp16 type; did you forget * ?}} +} + +void kg(a) + __fp16 *a; { +} + +// Functions cannot return type __fp16. +extern __fp16 f1 (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}} +extern __fp16 *g1 (void); + +extern __fp16 (*pf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}} +extern __fp16 *(*gf1) (void); + +typedef __fp16 (*tf1) (void); // expected-error {{function return value cannot have __fp16 type; did you forget * ?}} +typedef __fp16 *(*tg1) (void); +