This makes infinities and NaNs return the new, more explicit formats
added in 8d9299cd7a
and extends the base decimal output literal to support non-double types.
In addition, the legacy hexadecimal floating-point literal format is no
longer output in any circumstance.
In general, this means that NaNs are reported as +/-qnan,
+/-nan(payload), or +/-snan(payload), depending on their payload and
infinities as +/-inf. The hexadecimal output generally changes to `f0x...`
notation, and is used when 6 decimal digits are insufficient to accurately
represent the number, or for noncanonical ppc_fp128 values.
A script to change the output for most test files is available at
https://gist.github.com/jcranmer-intel/d279296ad91884c98b77fb23a9112a5a.
Full disclosure: the python portion of the script was written with the
use of AI tools. The C++ portion was written entirely by hand, reusing
LLVM's existing helpers for output.
The test changes included in this commit are *only* those which do not
work with that script, either because the script mangled the conversion
(e.g., intentionally matching only a prefix to allow some imprecision)
or because the tests were too unusual for the script to find the
floating-point literals being compared against.
143 lines
4.4 KiB
C++
143 lines
4.4 KiB
C++
// RUN: %clang -std=c++11 --target=aarch64-none-elf -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH64
|
|
|
|
/* Various contexts where type _Float16 can appear. */
|
|
|
|
|
|
/* Namespace */
|
|
|
|
namespace {
|
|
_Float16 f1n;
|
|
// CHECK-DAG: @_ZN12_GLOBAL__N_13f1nE = internal global half 0.000000e+00, align 2
|
|
|
|
_Float16 f2n = 33.f16;
|
|
// CHECK-DAG: @_ZN12_GLOBAL__N_13f2nE = internal global half 3.300000e+01, align 2
|
|
|
|
_Float16 arr1n[10];
|
|
// CHECK-AARCH64-DAG: @_ZN12_GLOBAL__N_15arr1nE = internal global [10 x half] zeroinitializer, align 2
|
|
|
|
_Float16 arr2n[] = { 1.2, 3.0, 3.e4 };
|
|
// CHECK-DAG: @_ZN12_GLOBAL__N_15arr2nE = internal global [3 x half] [half 1.200200e+00, half 3.000000e+00, half 3.000000e+04], align 2
|
|
|
|
const volatile _Float16 func1n(const _Float16 &arg) {
|
|
return arg + f2n + arr1n[4] - arr2n[1];
|
|
}
|
|
}
|
|
|
|
|
|
/* File */
|
|
|
|
_Float16 f1f;
|
|
// CHECK-AARCH64-DAG: @f1f = dso_local global half 0.000000e+00, align 2
|
|
|
|
_Float16 f2f = 32.4;
|
|
// CHECK-DAG: @f2f = dso_local global half 3.240630e+01, align 2
|
|
|
|
_Float16 arr1f[10];
|
|
// CHECK-AARCH64-DAG: @arr1f = dso_local global [10 x half] zeroinitializer, align 2
|
|
|
|
_Float16 arr2f[] = { -1.2, -3.0, -3.e4 };
|
|
// CHECK-DAG: @arr2f = dso_local global [3 x half] [half -1.200200e+00, half -3.000000e+00, half -3.000000e+04], align 2
|
|
|
|
_Float16 func1f(_Float16 arg);
|
|
|
|
|
|
/* Class */
|
|
|
|
class C1 {
|
|
_Float16 f1c;
|
|
|
|
static const _Float16 f2c;
|
|
// CHECK-DAG: @_ZN2C13f2cE = external dso_local constant half, align 2
|
|
|
|
volatile _Float16 f3c;
|
|
|
|
public:
|
|
C1(_Float16 arg) : f1c(arg), f3c(arg) { }
|
|
// Check that we mangle _Float16 to DF16_
|
|
// CHECK-DAG: define linkonce_odr dso_local void @_ZN2C1C2EDF16_(ptr{{.*}}, half{{.*}})
|
|
|
|
_Float16 func1c(_Float16 arg ) {
|
|
return f1c + arg;
|
|
}
|
|
// CHECK-DAG: define linkonce_odr dso_local noundef half @_ZN2C16func1cEDF16_(ptr{{.*}}, half{{.*}})
|
|
|
|
static _Float16 func2c(_Float16 arg) {
|
|
return arg * C1::f2c;
|
|
}
|
|
// CHECK-DAG: define linkonce_odr dso_local noundef half @_ZN2C16func2cEDF16_(half{{.*}})
|
|
};
|
|
|
|
/* Template */
|
|
|
|
template <class C> C func1t(C arg) {
|
|
return arg * 2.f16;
|
|
}
|
|
// CHECK-DAG: define linkonce_odr dso_local noundef half @_Z6func1tIDF16_ET_S0_(half{{.*}})
|
|
|
|
template <class C> struct S1 {
|
|
C mem1;
|
|
};
|
|
|
|
template <> struct S1<_Float16> {
|
|
_Float16 mem2;
|
|
};
|
|
|
|
|
|
/* Local */
|
|
|
|
extern int printf (const char *__restrict __format, ...);
|
|
|
|
int main(void) {
|
|
_Float16 f1l = 1e3f16;
|
|
// CHECK-DAG: store half 1.000000e+03, ptr %{{.*}}, align 2
|
|
|
|
_Float16 f2l = -0.f16;
|
|
// CHECK-DAG: store half -0.000000e+00, ptr %{{.*}}, align 2
|
|
|
|
_Float16 f3l = 1.000976562;
|
|
// CHECK-DAG: store half 1.000980e+00, ptr %{{.*}}, align 2
|
|
|
|
C1 c1(f1l);
|
|
// CHECK-DAG: [[F1L:%[a-z0-9]+]] = load half, ptr %{{.*}}, align 2
|
|
// CHECK-DAG: call void @_ZN2C1C2EDF16_(ptr {{[^,]*}} %{{.*}}, half noundef %{{.*}})
|
|
|
|
S1<_Float16> s1 = { 132.f16 };
|
|
// CHECK-DAG: @__const.main.s1 = private unnamed_addr constant %struct.S1 { half 1.320000e+02 }, align 2
|
|
// CHECK-DAG: call void @llvm.memcpy.p0.p0.i64(ptr align 2 %{{.*}}, ptr align 2 @__const.main.s1, i64 2, i1 false)
|
|
|
|
_Float16 f4l = func1n(f1l) + func1f(f2l) + c1.func1c(f3l) + c1.func2c(f1l) +
|
|
func1t(f1l) + s1.mem2 - f1n + f2n;
|
|
|
|
auto f5l = -1.f16, *f6l = &f2l, f7l = func1t(f3l);
|
|
// CHECK-DAG: store half -1.000000e+00, ptr %{{.*}}, align 2
|
|
// CHECK-DAG: store ptr %{{.*}}, ptr %{{.*}}, align 8
|
|
|
|
_Float16 f8l = f4l++;
|
|
// CHECK-DAG: %{{.*}} = load half, ptr %{{.*}}, align 2
|
|
// CHECK-DAG: [[INC:%[a-z0-9]+]] = fadd half {{.*}}, 1.000000e+00
|
|
// CHECK-DAG: store half [[INC]], ptr %{{.*}}, align 2
|
|
|
|
_Float16 arr1l[] = { -1.f16, -0.f16, -11.f16 };
|
|
// CHECK-DAG: @__const.main.arr1l = private unnamed_addr constant [3 x half] [half -1.000000e+00, half -0.000000e+00, half -1.100000e+01], align 2
|
|
|
|
float cvtf = f2n;
|
|
//CHECK-DAG: [[H2F:%[a-z0-9]+]] = fpext half {{%[0-9]+}} to float
|
|
//CHECK-DAG: store float [[H2F]], ptr %{{.*}}, align 4
|
|
|
|
double cvtd = f2n;
|
|
//CHECK-DAG: [[H2D:%[a-z0-9]+]] = fpext half {{%[0-9]+}} to double
|
|
//CHECK-DAG: store double [[H2D]], ptr %{{.*}}, align 8
|
|
|
|
|
|
long double cvtld = f2n;
|
|
//CHECK-AARCh64-DAG: [[H2LD:%[a-z0-9]+]] = fpext half {{%[0-9]+}} to fp128
|
|
//CHECK-AARCh64-DAG: store fp128 [[H2LD]], ptr %{{.*}}, align 16
|
|
|
|
_Float16 f2h = 42.0f;
|
|
//CHECK-DAG: store half 4.200000e+01, ptr %{{.*}}, align 2
|
|
_Float16 d2h = 42.0;
|
|
//CHECK-DAG: store half 4.200000e+01, ptr %{{.*}}, align 2
|
|
_Float16 ld2h = 42.0l;
|
|
//CHECK-DAG:store half 4.200000e+01, ptr %{{.*}}, align 2
|
|
}
|