Files
Joshua Cranmer 41c214f0b1 [AsmWriter] Change the output syntax of floating-point literals. (#190649)
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.
2026-05-07 13:16:14 -04:00

66 lines
2.5 KiB
C++

// RUN: %clang_cc1 -emit-llvm -triple i386-linux -Wno-unknown-pragmas -frounding-math %s -o - | FileCheck %s
constexpr float func_01(float x, float y) {
return x + y;
}
float V1 = func_01(1.0F, 0x0.000001p0F);
float V2 = 1.0F + 0x0.000001p0F;
float V3 = func_01(1.0F, 2.0F);
// CHECK: @V1 = {{.*}}global float 1.000000e+00, align 4
// CHECK: @V2 = {{.*}}global float 1.000000e+00, align 4
// CHECK: @V3 = {{.*}}global float 3.000000e+00, align 4
void test_builtin_elementwise_fma_round_upward() {
#pragma STDC FENV_ACCESS ON
#pragma STDC FENV_ROUND FE_UPWARD
// CHECK: store float f0x40C00008, ptr %f1
// CHECK: store float f0x40C00008, ptr %f2
constexpr float f1 = __builtin_elementwise_fma(2.0F, 3.000001F, 0.000001F);
constexpr float f2 = 2.0F * 3.000001F + 0.000001F;
static_assert(f1 == f2);
static_assert(f1 == 6.00000381F);
// CHECK: store double f0x40180000C9539B89, ptr %d1
// CHECK: store double f0x40180000C9539B89, ptr %d2
constexpr double d1 = __builtin_elementwise_fma(2.0, 3.000001, 0.000001);
constexpr double d2 = 2.0 * 3.000001 + 0.000001;
static_assert(d1 == d2);
static_assert(d1 == 6.0000030000000004);
}
void test_builtin_elementwise_fma_round_downward() {
#pragma STDC FENV_ACCESS ON
#pragma STDC FENV_ROUND FE_DOWNWARD
// CHECK: store float f0x40C00006, ptr %f3
// CHECK: store float f0x40C00006, ptr %f4
constexpr float f3 = __builtin_elementwise_fma(2.0F, 3.000001F, 0.000001F);
constexpr float f4 = 2.0F * 3.000001F + 0.000001F;
static_assert(f3 == f4);
// CHECK: store double f0x40180000C9539B87, ptr %d3
// CHECK: store double f0x40180000C9539B87, ptr %d4
constexpr double d3 = __builtin_elementwise_fma(2.0, 3.000001, 0.000001);
constexpr double d4 = 2.0 * 3.000001 + 0.000001;
static_assert(d3 == d4);
}
void test_builtin_elementwise_fma_round_nearest() {
#pragma STDC FENV_ACCESS ON
#pragma STDC FENV_ROUND FE_TONEAREST
// CHECK: store float f0x40C00006, ptr %f5
// CHECK: store float f0x40C00006, ptr %f6
constexpr float f5 = __builtin_elementwise_fma(2.0F, 3.000001F, 0.000001F);
constexpr float f6 = 2.0F * 3.000001F + 0.000001F;
static_assert(f5 == f6);
static_assert(f5 == 6.00000286F);
// CHECK: store double f0x40180000C9539B89, ptr %d5
// CHECK: store double f0x40180000C9539B89, ptr %d6
constexpr double d5 = __builtin_elementwise_fma(2.0, 3.000001, 0.000001);
constexpr double d6 = 2.0 * 3.000001 + 0.000001;
static_assert(d5 == d6);
static_assert(d5 == 6.0000030000000004);
}