103 changes: 103 additions & 0 deletions libc/src/math/generic/coshf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//===-- Half-precision cosh(x) function -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/coshf16.h"
#include "expxf16.h"
#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/except_value_utils.h"
#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"

namespace LIBC_NAMESPACE_DECL {

static constexpr fputil::ExceptValues<float16, 9> COSHF16_EXCEPTS_POS = {{
// x = 0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
{0x29a8U, 0x3c00U, 1U, 0U, 1U},
// x = 0x1.8c4p+0, coshf16(x) = 0x1.3a8p+1 (RZ)
{0x3e31U, 0x40eaU, 1U, 0U, 0U},
// x = 0x1.994p+0, coshf16(x) = 0x1.498p+1 (RZ)
{0x3e65U, 0x4126U, 1U, 0U, 0U},
// x = 0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
{0x3ed8U, 0x41b6U, 1U, 0U, 1U},
// x = 0x1.aap+1, coshf16(x) = 0x1.be8p+3 (RZ)
{0x42a8U, 0x4afaU, 1U, 0U, 1U},
// x = 0x1.cc4p+1, coshf16(x) = 0x1.23cp+4 (RZ)
{0x4331U, 0x4c8fU, 1U, 0U, 0U},
// x = 0x1.288p+2, coshf16(x) = 0x1.9b4p+5 (RZ)
{0x44a2U, 0x526dU, 1U, 0U, 0U},
// x = 0x1.958p+2, coshf16(x) = 0x1.1a4p+8 (RZ)
{0x4656U, 0x5c69U, 1U, 0U, 0U},
// x = 0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
{0x497cU, 0x7715U, 1U, 0U, 1U},
}};

static constexpr fputil::ExceptValues<float16, 4> COSHF16_EXCEPTS_NEG = {{
// x = -0x1.6ap-5, coshf16(x) = 0x1p+0 (RZ)
{0xa9a8U, 0x3c00U, 1U, 0U, 1U},
// x = -0x1.b6p+0, coshf16(x) = 0x1.6d8p+1 (RZ)
{0xbed8U, 0x41b6U, 1U, 0U, 1U},
// x = -0x1.288p+2, coshf16(x) = 0x1.9b4p+5 (RZ)
{0xc4a2U, 0x526dU, 1U, 0U, 0U},
// x = -0x1.5fp+3, coshf16(x) = 0x1.c54p+14 (RZ)
{0xc97cU, 0x7715U, 1U, 0U, 1U},
}};

LLVM_LIBC_FUNCTION(float16, coshf16, (float16 x)) {
using FPBits = fputil::FPBits<float16>;
FPBits x_bits(x);

uint16_t x_u = x_bits.uintval();
uint16_t x_abs = x_u & 0x7fffU;

// When |x| >= acosh(2^16), or x is NaN.
if (LIBC_UNLIKELY(x_abs >= 0x49e5U)) {
// cosh(NaN) = NaN
if (x_bits.is_nan()) {
if (x_bits.is_signaling_nan()) {
fputil::raise_except_if_required(FE_INVALID);
return FPBits::quiet_nan().get_val();
}

return x;
}

// When |x| >= acosh(2^16).
if (x_abs >= 0x49e5U) {
// cosh(+/-inf) = +inf
if (x_bits.is_inf())
return FPBits::inf().get_val();

switch (fputil::quick_get_round()) {
case FE_TONEAREST:
case FE_UPWARD:
fputil::set_errno_if_required(ERANGE);
fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
return FPBits::inf().get_val();
default:
return FPBits::max_normal().get_val();
}
}
}

if (x_bits.is_pos()) {
if (auto r = COSHF16_EXCEPTS_POS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
return r.value();
} else {
if (auto r = COSHF16_EXCEPTS_NEG.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
return r.value();
}

return eval_sinh_or_cosh</*IsSinh=*/false>(x);
}

} // namespace LIBC_NAMESPACE_DECL
114 changes: 114 additions & 0 deletions libc/src/math/generic/expxf16.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "src/__support/CPP/array.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PolyEval.h"
#include "src/__support/FPUtil/cast.h"
#include "src/__support/FPUtil/multiply_add.h"
#include "src/__support/FPUtil/nearest_integer.h"
#include "src/__support/macros/attributes.h"
Expand Down Expand Up @@ -174,6 +175,119 @@ LIBC_INLINE ExpRangeReduction exp10_range_reduction(float16 x) {
return {exp2_hi_mid, exp10_lo};
}

// Generated by Sollya with the following commands:
// > display = hexadecimal;
// > round(log2(exp(1)), SG, RN);
static constexpr float LOG2F_E = 0x1.715476p+0f;

// Generated by Sollya with the following commands:
// > display = hexadecimal;
// > round(log(2), SG, RN);
static constexpr float LOGF_2 = 0x1.62e43p-1f;

// Generated by Sollya with the following commands:
// > display = hexadecimal;
// > for i from 0 to 31 do printsingle(round(2^(i * 2^-5), SG, RN));
static constexpr cpp::array<uint32_t, 32> EXP2_MID_5_BITS = {
0x3f80'0000U, 0x3f82'cd87U, 0x3f85'aac3U, 0x3f88'980fU, 0x3f8b'95c2U,
0x3f8e'a43aU, 0x3f91'c3d3U, 0x3f94'f4f0U, 0x3f98'37f0U, 0x3f9b'8d3aU,
0x3f9e'f532U, 0x3fa2'7043U, 0x3fa5'fed7U, 0x3fa9'a15bU, 0x3fad'583fU,
0x3fb1'23f6U, 0x3fb5'04f3U, 0x3fb8'fbafU, 0x3fbd'08a4U, 0x3fc1'2c4dU,
0x3fc5'672aU, 0x3fc9'b9beU, 0x3fce'248cU, 0x3fd2'a81eU, 0x3fd7'44fdU,
0x3fdb'fbb8U, 0x3fe0'ccdfU, 0x3fe5'b907U, 0x3fea'c0c7U, 0x3fef'e4baU,
0x3ff5'257dU, 0x3ffa'83b3U,
};

// This function correctly calculates sinh(x) and cosh(x) by calculating exp(x)
// and exp(-x) simultaneously.
// To compute e^x, we perform the following range reduction:
// find hi, mid, lo such that:
// x = (hi + mid) * log(2) + lo, in which
// hi is an integer,
// 0 <= mid * 2^5 < 32 is an integer
// -2^(-5) <= lo * log2(e) <= 2^-5.
// In particular,
// hi + mid = round(x * log2(e) * 2^5) * 2^(-5).
// Then,
// e^x = 2^(hi + mid) * e^lo = 2^hi * 2^mid * e^lo.
// We store 2^mid in the lookup table EXP2_MID_5_BITS, and compute 2^hi * 2^mid
// by adding hi to the exponent field of 2^mid.
// e^lo is computed using a degree-3 minimax polynomial generated by Sollya:
// e^lo ~ P(lo)
// = 1 + lo + c2 * lo^2 + ... + c5 * lo^5
// = (1 + c2*lo^2 + c4*lo^4) + lo * (1 + c3*lo^2 + c5*lo^4)
// = P_even + lo * P_odd
// To compute e^(-x), notice that:
// e^(-x) = 2^(-(hi + mid)) * e^(-lo)
// ~ 2^(-(hi + mid)) * P(-lo)
// = 2^(-(hi + mid)) * (P_even - lo * P_odd)
// So:
// sinh(x) = (e^x - e^(-x)) / 2
// ~ 0.5 * (2^(hi + mid) * (P_even + lo * P_odd) -
// 2^(-(hi + mid)) * (P_even - lo * P_odd))
// = 0.5 * (P_even * (2^(hi + mid) - 2^(-(hi + mid))) +
// lo * P_odd * (2^(hi + mid) + 2^(-(hi + mid))))
// And similarly:
// cosh(x) = (e^x + e^(-x)) / 2
// ~ 0.5 * (P_even * (2^(hi + mid) + 2^(-(hi + mid))) +
// lo * P_odd * (2^(hi + mid) - 2^(-(hi + mid))))
// The main point of these formulas is that the expensive part of calculating
// the polynomials approximating lower parts of e^x and e^(-x) is shared and
// only done once.
template <bool IsSinh> LIBC_INLINE float16 eval_sinh_or_cosh(float16 x) {
float xf = x;
float kf = fputil::nearest_integer(xf * (LOG2F_E * 0x1.0p+5f));
int x_hi_mid_p = static_cast<int>(kf);
int x_hi_mid_m = -x_hi_mid_p;

unsigned x_hi_p = static_cast<unsigned>(x_hi_mid_p) >> 5;
unsigned x_hi_m = static_cast<unsigned>(x_hi_mid_m) >> 5;
unsigned x_mid_p = static_cast<unsigned>(x_hi_mid_p) & 0x1f;
unsigned x_mid_m = static_cast<unsigned>(x_hi_mid_m) & 0x1f;

uint32_t exp2_hi_mid_bits_p =
EXP2_MID_5_BITS[x_mid_p] +
static_cast<uint32_t>(x_hi_p << fputil::FPBits<float>::FRACTION_LEN);
uint32_t exp2_hi_mid_bits_m =
EXP2_MID_5_BITS[x_mid_m] +
static_cast<uint32_t>(x_hi_m << fputil::FPBits<float>::FRACTION_LEN);
// exp2_hi_mid_p = 2^(hi + mid)
float exp2_hi_mid_p = fputil::FPBits<float>(exp2_hi_mid_bits_p).get_val();
// exp2_hi_mid_m = 2^(-(hi + mid))
float exp2_hi_mid_m = fputil::FPBits<float>(exp2_hi_mid_bits_m).get_val();

// exp2_hi_mid_sum = 2^(hi + mid) + 2^(-(hi + mid))
float exp2_hi_mid_sum = exp2_hi_mid_p + exp2_hi_mid_m;
// exp2_hi_mid_diff = 2^(hi + mid) - 2^(-(hi + mid))
float exp2_hi_mid_diff = exp2_hi_mid_p - exp2_hi_mid_m;

// lo = x - (hi + mid) = round(x * log2(e) * 2^5) * log(2) * (-2^(-5)) + x
float lo = fputil::multiply_add(kf, LOGF_2 * -0x1.0p-5f, xf);
float lo_sq = lo * lo;

// Degree-3 minimax polynomial generated by Sollya with the following
// commands:
// > display = hexadecimal;
// > P = fpminimax(expm1(x)/x, 2, [|SG...|], [-2^-5, 2^-5]);
// > 1 + x * P;
constexpr cpp::array<float, 4> COEFFS = {0x1p+0f, 0x1p+0f, 0x1.0004p-1f,
0x1.555778p-3f};
float half_p_odd =
fputil::polyeval(lo_sq, COEFFS[1] * 0.5f, COEFFS[3] * 0.5f);
float half_p_even =
fputil::polyeval(lo_sq, COEFFS[0] * 0.5f, COEFFS[2] * 0.5f);

// sinh(x) = lo * (0.5 * P_odd * (2^(hi + mid) + 2^(-(hi + mid)))) +
// (0.5 * P_even * (2^(hi + mid) - 2^(-(hi + mid))))
if constexpr (IsSinh)
return fputil::cast<float16>(fputil::multiply_add(
lo, half_p_odd * exp2_hi_mid_sum, half_p_even * exp2_hi_mid_diff));
// cosh(x) = lo * (0.5 * P_odd * (2^(hi + mid) - 2^(-(hi + mid)))) +
// (0.5 * P_even * (2^(hi + mid) + 2^(-(hi + mid))))
return fputil::cast<float16>(fputil::multiply_add(
lo, half_p_odd * exp2_hi_mid_diff, half_p_even * exp2_hi_mid_sum));
}

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_GENERIC_EXPXF16_H
144 changes: 144 additions & 0 deletions libc/src/math/generic/sinhf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//===-- Half-precision sinh(x) function -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/sinhf16.h"
#include "expxf16.h"
#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/except_value_utils.h"
#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h"

namespace LIBC_NAMESPACE_DECL {

static constexpr fputil::ExceptValues<float16, 16> SINHF16_EXCEPTS_POS = {{
// x = 0x1.714p-5, sinhf16(x) = 0x1.714p-5 (RZ)
{0x29c5U, 0x29c5U, 1U, 0U, 1U},
// x = 0x1.25p-4, sinhf16(x) = 0x1.25p-4 (RZ)
{0x2c94U, 0x2c94U, 1U, 0U, 1U},
// x = 0x1.f5p-4, sinhf16(x) = 0x1.f64p-4 (RZ)
{0x2fd4U, 0x2fd9U, 1U, 0U, 0U},
// x = 0x1.b1cp-3, sinhf16(x) = 0x1.b4cp-3 (RZ)
{0x32c7U, 0x32d3U, 1U, 0U, 1U},
// x = 0x1.6e8p-2, sinhf16(x) = 0x1.764p-2 (RZ)
{0x35baU, 0x35d9U, 1U, 0U, 1U},
// x = 0x1.6b4p-1, sinhf16(x) = 0x1.8a4p-1 (RZ)
{0x39adU, 0x3a29U, 1U, 0U, 1U},
// x = 0x1.a58p-1, sinhf16(x) = 0x1.d68p-1 (RZ)
{0x3a96U, 0x3b5aU, 1U, 0U, 1U},
// x = 0x1.574p+0, sinhf16(x) = 0x1.c78p+0 (RZ)
{0x3d5dU, 0x3f1eU, 1U, 0U, 1U},
// x = 0x1.648p+1, sinhf16(x) = 0x1.024p+3 (RZ)
{0x4192U, 0x4809U, 1U, 0U, 0U},
// x = 0x1.cdcp+1, sinhf16(x) = 0x1.26cp+4 (RZ)
{0x4337U, 0x4c9bU, 1U, 0U, 0U},
// x = 0x1.d0cp+1, sinhf16(x) = 0x1.2d8p+4 (RZ)
{0x4343U, 0x4cb6U, 1U, 0U, 1U},
// x = 0x1.018p+2, sinhf16(x) = 0x1.bfp+4 (RZ)
{0x4406U, 0x4efcU, 1U, 0U, 0U},
// x = 0x1.2fcp+2, sinhf16(x) = 0x1.cc4p+5 (RZ)
{0x44bfU, 0x5331U, 1U, 0U, 1U},
// x = 0x1.4ecp+2, sinhf16(x) = 0x1.75cp+6 (RZ)
{0x453bU, 0x55d7U, 1U, 0U, 0U},
// x = 0x1.8a4p+2, sinhf16(x) = 0x1.d94p+7 (RZ)
{0x4629U, 0x5b65U, 1U, 0U, 1U},
// x = 0x1.5fp+3, sinhf16(x) = 0x1.c54p+14 (RZ)
{0x497cU, 0x7715U, 1U, 0U, 1U},
}};

static constexpr fputil::ExceptValues<float16, 12> SINHF16_EXCEPTS_NEG = {{
// x = -0x1.714p-5, sinhf16(x) = -0x1.714p-5 (RZ)
{0xa9c5U, 0xa9c5U, 0U, 1U, 1U},
// x = -0x1.25p-4, sinhf16(x) = -0x1.25p-4 (RZ)
{0xac94U, 0xac94U, 0U, 1U, 1U},
// x = -0x1.f5p-4, sinhf16(x) = -0x1.f64p-4 (RZ)
{0xafd4U, 0xafd9U, 0U, 1U, 0U},
// x = -0x1.6e8p-2, sinhf16(x) = -0x1.764p-2 (RZ)
{0xb5baU, 0xb5d9U, 0U, 1U, 1U},
// x = -0x1.a58p-1, sinhf16(x) = -0x1.d68p-1 (RZ)
{0xba96U, 0xbb5aU, 0U, 1U, 1U},
// x = -0x1.cdcp+1, sinhf16(x) = -0x1.26cp+4 (RZ)
{0xc337U, 0xcc9bU, 0U, 1U, 0U},
// x = -0x1.d0cp+1, sinhf16(x) = -0x1.2d8p+4 (RZ)
{0xc343U, 0xccb6U, 0U, 1U, 1U},
// x = -0x1.018p+2, sinhf16(x) = -0x1.bfp+4 (RZ)
{0xc406U, 0xcefcU, 0U, 1U, 0U},
// x = -0x1.2fcp+2, sinhf16(x) = -0x1.cc4p+5 (RZ)
{0xc4bfU, 0xd331U, 0U, 1U, 1U},
// x = -0x1.4ecp+2, sinhf16(x) = -0x1.75cp+6 (RZ)
{0xc53bU, 0xd5d7U, 0U, 1U, 0U},
// x = -0x1.8a4p+2, sinhf16(x) = -0x1.d94p+7 (RZ)
{0xc629U, 0xdb65U, 0U, 1U, 1U},
// x = -0x1.5fp+3, sinhf16(x) = -0x1.c54p+14 (RZ)
{0xc97cU, 0xf715U, 0U, 1U, 1U},
}};

LLVM_LIBC_FUNCTION(float16, sinhf16, (float16 x)) {
using FPBits = fputil::FPBits<float16>;
FPBits x_bits(x);

uint16_t x_u = x_bits.uintval();
uint16_t x_abs = x_u & 0x7fffU;

// When |x| = 0, or -2^(-14) <= x <= -2^(-9), or |x| >= asinh(2^16), or x is
// NaN.
if (LIBC_UNLIKELY(x_abs == 0U || (x_u >= 0x8400U && x_u <= 0xa400U) ||
x_abs >= 0x49e5U)) {
// sinh(NaN) = NaN
if (x_bits.is_nan()) {
if (x_bits.is_signaling_nan()) {
fputil::raise_except_if_required(FE_INVALID);
return FPBits::quiet_nan().get_val();
}

return x;
}

// sinh(+/-0) = sinh(+/-0)
if (x_abs == 0U)
return FPBits::zero(x_bits.sign()).get_val();

// When |x| >= asinh(2^16).
if (x_abs >= 0x49e5U) {
// sinh(+/-inf) = +/-inf
if (x_bits.is_inf())
return FPBits::inf(x_bits.sign()).get_val();

int rounding_mode = fputil::quick_get_round();
if (rounding_mode == FE_TONEAREST ||
(x_bits.is_pos() && rounding_mode == FE_UPWARD) ||
(x_bits.is_neg() && rounding_mode == FE_DOWNWARD)) {
fputil::set_errno_if_required(ERANGE);
fputil::raise_except_if_required(FE_OVERFLOW | FE_INEXACT);
return FPBits::inf(x_bits.sign()).get_val();
}
return FPBits::max_normal(x_bits.sign()).get_val();
}

// When -2^(-14) <= x <= -2^(-9).
if (fputil::fenv_is_round_down())
return FPBits(static_cast<uint16_t>(x_u + 1)).get_val();
return FPBits(static_cast<uint16_t>(x_u)).get_val();
}

if (x_bits.is_pos()) {
if (auto r = SINHF16_EXCEPTS_POS.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
return r.value();
} else {
if (auto r = SINHF16_EXCEPTS_NEG.lookup(x_u); LIBC_UNLIKELY(r.has_value()))
return r.value();
}

return eval_sinh_or_cosh</*IsSinh=*/true>(x);
}

} // namespace LIBC_NAMESPACE_DECL
21 changes: 21 additions & 0 deletions libc/src/math/sinhf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for sinhf16 -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_SINHF16_H
#define LLVM_LIBC_SRC_MATH_SINHF16_H

#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE_DECL {

float16 sinhf16(float16 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_SINHF16_H
22 changes: 22 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,17 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
coshf16_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
coshf16_test.cpp
DEPENDS
libc.src.math.coshf16
)

add_fp_unittest(
sinhf_test
NEED_MPFR
Expand All @@ -1932,6 +1943,17 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
sinhf16_test
NEED_MPFR
SUITE
libc-math-unittests
SRCS
sinhf16_test.cpp
DEPENDS
libc.src.math.sinhf16
)

add_fp_unittest(
tanhf_test
NEED_MPFR
Expand Down
40 changes: 40 additions & 0 deletions libc/test/src/math/coshf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===-- Exhaustive test for coshf16 ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/coshf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

using LlvmLibcCoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;

// Range: [0, Inf];
static constexpr uint16_t POS_START = 0x0000U;
static constexpr uint16_t POS_STOP = 0x7c00U;

// Range: [-Inf, 0];
static constexpr uint16_t NEG_START = 0x8000U;
static constexpr uint16_t NEG_STOP = 0xfc00U;

TEST_F(LlvmLibcCoshf16Test, PositiveRange) {
for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
float16 x = FPBits(v).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cosh, x,
LIBC_NAMESPACE::coshf16(x), 0.5);
}
}

TEST_F(LlvmLibcCoshf16Test, NegativeRange) {
for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
float16 x = FPBits(v).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cosh, x,
LIBC_NAMESPACE::coshf16(x), 0.5);
}
}
40 changes: 40 additions & 0 deletions libc/test/src/math/sinhf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===-- Exhaustive test for sinhf16 ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/sinhf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
#include "utils/MPFRWrapper/MPFRUtils.h"

using LlvmLibcSinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;

namespace mpfr = LIBC_NAMESPACE::testing::mpfr;

// Range: [0, Inf];
static constexpr uint16_t POS_START = 0x0000U;
static constexpr uint16_t POS_STOP = 0x7c00U;

// Range: [-Inf, 0];
static constexpr uint16_t NEG_START = 0x8000U;
static constexpr uint16_t NEG_STOP = 0xfc00U;

TEST_F(LlvmLibcSinhf16Test, PositiveRange) {
for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
float16 x = FPBits(v).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x,
LIBC_NAMESPACE::sinhf16(x), 0.5);
}
}

TEST_F(LlvmLibcSinhf16Test, NegativeRange) {
for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) {
float16 x = FPBits(v).get_val();
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x,
LIBC_NAMESPACE::sinhf16(x), 0.5);
}
}
26 changes: 26 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
coshf16_test
SUITE
libc-math-smoke-tests
SRCS
coshf16_test.cpp
DEPENDS
libc.hdr.fenv_macros
libc.src.errno.errno
libc.src.math.coshf16
libc.src.__support.FPUtil.cast
)

add_fp_unittest(
sinhf_test
SUITE
Expand All @@ -3741,6 +3754,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
sinhf16_test
SUITE
libc-math-smoke-tests
SRCS
sinhf16_test.cpp
DEPENDS
libc.hdr.fenv_macros
libc.src.errno.errno
libc.src.math.sinhf16
libc.src.__support.FPUtil.cast
)

add_fp_unittest(
tanhf_test
SUITE
Expand Down
90 changes: 90 additions & 0 deletions libc/test/src/math/smoke/coshf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//===-- Unittests for coshf16 ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/cast.h"
#include "src/errno/libc_errno.h"
#include "src/math/coshf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

using LlvmLibcCoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;

TEST_F(LlvmLibcCoshf16Test, SpecialNumbers) {
LIBC_NAMESPACE::libc_errno = 0;

EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::coshf16(aNaN));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::coshf16(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::coshf16(inf));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::coshf16(neg_inf));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(LIBC_NAMESPACE::fputil::cast<float16>(1.0),
LIBC_NAMESPACE::coshf16(zero));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(LIBC_NAMESPACE::fputil::cast<float16>(1.0),
LIBC_NAMESPACE::coshf16(neg_zero));
EXPECT_MATH_ERRNO(0);
}

TEST_F(LlvmLibcCoshf16Test, Overflow) {
LIBC_NAMESPACE::libc_errno = 0;

EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::coshf16(max_normal),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::coshf16(neg_max_normal),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

// round(acosh(2^16), HP, RU);
float16 x = LIBC_NAMESPACE::fputil::cast<float16>(0x1.794p+3);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(inf, LIBC_NAMESPACE::coshf16(x),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_UPWARD(inf, LIBC_NAMESPACE::coshf16(x),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_DOWNWARD(
max_normal, LIBC_NAMESPACE::coshf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_TOWARD_ZERO(
max_normal, LIBC_NAMESPACE::coshf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);

// round(-acosh(2^16), HP, RD);
x = LIBC_NAMESPACE::fputil::cast<float16>(-0x1.794p+3);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(inf, LIBC_NAMESPACE::coshf16(x),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_UPWARD(inf, LIBC_NAMESPACE::coshf16(x),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_DOWNWARD(
max_normal, LIBC_NAMESPACE::coshf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_TOWARD_ZERO(
max_normal, LIBC_NAMESPACE::coshf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);
}
88 changes: 88 additions & 0 deletions libc/test/src/math/smoke/sinhf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//===-- Unittests for sinhf16 ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "hdr/fenv_macros.h"
#include "src/__support/FPUtil/cast.h"
#include "src/errno/libc_errno.h"
#include "src/math/sinhf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

using LlvmLibcSinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;

TEST_F(LlvmLibcSinhf16Test, SpecialNumbers) {
LIBC_NAMESPACE::libc_errno = 0;

EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::sinhf16(aNaN));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::sinhf16(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(inf, LIBC_NAMESPACE::sinhf16(inf));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, LIBC_NAMESPACE::sinhf16(neg_inf));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::sinhf16(zero));
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::sinhf16(neg_zero));
EXPECT_MATH_ERRNO(0);
}

TEST_F(LlvmLibcSinhf16Test, Overflow) {
LIBC_NAMESPACE::libc_errno = 0;

EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::sinhf16(max_normal),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::sinhf16(neg_max_normal),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

// round(asinh(2^16), HP, RU);
float16 x = LIBC_NAMESPACE::fputil::cast<float16>(0x1.794p+3);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(inf, LIBC_NAMESPACE::sinhf16(x),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_UPWARD(inf, LIBC_NAMESPACE::sinhf16(x),
FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_DOWNWARD(
max_normal, LIBC_NAMESPACE::sinhf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_TOWARD_ZERO(
max_normal, LIBC_NAMESPACE::sinhf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);

// round(asinh(-2^16), HP, RD);
x = LIBC_NAMESPACE::fputil::cast<float16>(-0x1.794p+3);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_NEAREST(
neg_inf, LIBC_NAMESPACE::sinhf16(x), FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_UPWARD(
neg_max_normal, LIBC_NAMESPACE::sinhf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_DOWNWARD(
neg_inf, LIBC_NAMESPACE::sinhf16(x), FE_OVERFLOW | FE_INEXACT);
EXPECT_MATH_ERRNO(ERANGE);

EXPECT_FP_EQ_WITH_EXCEPTION_ROUNDING_TOWARD_ZERO(
neg_max_normal, LIBC_NAMESPACE::sinhf16(x), FE_INEXACT);
EXPECT_MATH_ERRNO(0);
}
7 changes: 3 additions & 4 deletions libcxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ set(CMAKE_FOLDER "libc++")

set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")

include(GNUInstallDirs)
include(WarningFlags)
Expand Down Expand Up @@ -443,8 +442,6 @@ else()
"Path where target-specific libc++ headers should be installed.")
endif()

file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR})
Expand All @@ -459,7 +456,9 @@ set(LIBCXX_COMPILE_FLAGS "")
set(LIBCXX_LINK_FLAGS "")
set(LIBCXX_LIBRARIES "")
set(LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
"Additional Compile only flags which can be provided in cache")
"Additional compile flags to use when building libc++. This should be a CMake ;-delimited list of individual
compiler options to use. For options that must be passed as-is to the compiler without deduplication (e.g.
`-Xclang -foo` option groups), consider using `SHELL:` (https://cmake.org/cmake/help/latest/command/add_compile_options.html#option-de-duplication).")
set(LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
"Additional libraries libc++ is linked to which can be provided in cache")

Expand Down
53 changes: 0 additions & 53 deletions libcxx/appveyor-reqs-install.cmd

This file was deleted.

71 changes: 0 additions & 71 deletions libcxx/appveyor.yml

This file was deleted.

4 changes: 2 additions & 2 deletions libcxx/cmake/caches/AMDGPU.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE BOOL "")

# Necessary compile flags for AMDGPU.
set(LIBCXX_ADDITIONAL_COMPILE_FLAGS
"-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
"-nogpulib;-flto;-fconvergent-functions;SHELL:-Xclang -mcode-object-version=none" CACHE STRING "")
set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS
"-nogpulib;-flto;-fconvergent-functions;-Xclang;-mcode-object-version=none" CACHE STRING "")
"-nogpulib;-flto;-fconvergent-functions;SHELL:-Xclang -mcode-object-version=none" CACHE STRING "")
set(CMAKE_REQUIRED_FLAGS "-nogpulib" CACHE STRING "")
12 changes: 4 additions & 8 deletions libcxx/docs/VendorDocumentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ General purpose options

Output name for the shared libc++ runtime library.

.. option:: LIBCXX_ADDITIONAL_COMPILE_FLAGS:STRING
.. option:: {LIBCXX,LIBCXXABI,LIBUNWIND}_ADDITIONAL_COMPILE_FLAGS:STRING

**Default**: ``""``

Additional Compile only flags which can be provided in cache.
Additional compile flags to use when building the runtimes. This should be a CMake ``;``-delimited list of individual
compiler options to use. For options that must be passed as-is to the compiler without deduplication (e.g.
``-Xclang -foo`` option groups), consider using ``SHELL:`` as `documented here <https://cmake.org/cmake/help/latest/command/add_compile_options.html#option-de-duplication>`_.

.. option:: LIBCXX_ADDITIONAL_LIBRARIES:STRING

Expand Down Expand Up @@ -346,12 +348,6 @@ The following options allow building libc++ for a different ABI version.
Build and use the LLVM unwinder. Note: This option can only be used when
libc++abi is the C++ ABI library used.

.. option:: LIBCXXABI_ADDITIONAL_COMPILE_FLAGS:STRING

**Default**: ``""``

Additional Compile only flags which can be provided in cache.

.. option:: LIBCXXABI_ADDITIONAL_LIBRARIES:STRING

**Default**: ``""``
Expand Down
8 changes: 4 additions & 4 deletions libcxx/include/new
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ _LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
}

template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) {
_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(__args...);
#else
Expand All @@ -302,7 +302,7 @@ inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __ali
}

template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) {
_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
#if !_LIBCPP_HAS_SIZED_DEALLOCATION
(void)__size;
return std::__libcpp_operator_delete(__ptr, __args...);
Expand All @@ -311,7 +311,7 @@ _LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __siz
#endif
}

inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) {
inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
(void)__align;
return __do_deallocate_handle_size(__ptr, __size);
Expand All @@ -325,7 +325,7 @@ inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size
#endif
}

inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) {
inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
(void)__align;
return __libcpp_operator_delete(__ptr);
Expand Down
2 changes: 1 addition & 1 deletion libcxx/test/configs/cmake-bridge.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config.name = os.path.basename('@LIBCXX_TEST_CONFIG@')
config.test_source_root = os.path.join('@LIBCXX_SOURCE_DIR@', 'test')
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
config.recursiveExpansionLimit = 10
config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
config.test_exec_root = os.path.join('@LIBCXX_BINARY_DIR@', 'test')

# Add substitutions for bootstrapping the test suite configuration
config.substitutions.append(('%{libcxx-dir}', '@LIBCXX_SOURCE_DIR@'))
Expand Down
3 changes: 1 addition & 2 deletions libcxxabi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ set(LIBCXXABI_CXX_FLAGS "")
set(LIBCXXABI_COMPILE_FLAGS "")
set(LIBCXXABI_LINK_FLAGS "")
set(LIBCXXABI_LIBRARIES "")
set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
"Additional Compile only flags which can be provided in cache")
set(LIBCXXABI_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING "See documentation LIBCXX_ADDITIONAL_COMPILE_FLAGS")
set(LIBCXXABI_ADDITIONAL_LIBRARIES "" CACHE STRING
"Additional libraries libc++abi is linked to which can be provided in cache")

Expand Down
2 changes: 1 addition & 1 deletion libcxxabi/test/configs/cmake-bridge.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config.name = os.path.basename('@LIBCXXABI_TEST_CONFIG@')
config.test_source_root = os.path.join('@LIBCXXABI_SOURCE_DIR@', 'test')
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
config.recursiveExpansionLimit = 10
config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
config.test_exec_root = os.path.join('@LIBCXXABI_BINARY_DIR@', 'test')

# TODO: This is a non-standard Lit attribute and we should have another way of accessing this.
config.host_triple = '@LLVM_HOST_TRIPLE@'
Expand Down
3 changes: 1 addition & 2 deletions libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ set(LIBUNWIND_C_FLAGS "")
set(LIBUNWIND_CXX_FLAGS "")
set(LIBUNWIND_COMPILE_FLAGS "")
set(LIBUNWIND_LINK_FLAGS "")
set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
"Additional Compile only flags which can be provided in cache")
set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING "See documentation for LIBCXX_ADDITIONAL_COMPILE_FLAGS")
set(LIBUNWIND_ADDITIONAL_LIBRARIES "" CACHE STRING
"Additional libraries libunwind is linked to which can be provided in cache")

Expand Down
2 changes: 1 addition & 1 deletion libunwind/test/configs/cmake-bridge.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config.name = os.path.basename('@LIBUNWIND_TEST_CONFIG@')
config.test_source_root = os.path.join('@LIBUNWIND_SOURCE_DIR@', 'test')
config.test_format = libcxx.test.format.CxxStandardLibraryTest()
config.recursiveExpansionLimit = 10
config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
config.test_exec_root = os.path.join('@LIBUNWIND_BINARY_DIR@', 'test')

# Add a few features that are common to all the configurations
if @LIBUNWIND_USES_ARM_EHABI@:
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
using namespace llvm;

static bool finalizeLinkage(Module &M) {
SmallPtrSet<Function *, 8> EntriesAndExports;
SmallPtrSet<Function *, 8> Funcs;

// Find all entry points and export functions
// Collect non-entry and non-exported functions to set to internal linkage.
for (Function &EF : M.functions()) {
if (!EF.hasFnAttribute("hlsl.shader") && !EF.hasFnAttribute("hlsl.export"))
if (EF.hasFnAttribute("hlsl.shader") || EF.hasFnAttribute("hlsl.export"))
continue;
EntriesAndExports.insert(&EF);
Funcs.insert(&EF);
}

for (Function &F : M.functions()) {
if (F.getLinkage() == GlobalValue::ExternalLinkage &&
!EntriesAndExports.contains(&F)) {
F.setLinkage(GlobalValue::InternalLinkage);
}
for (Function *F : Funcs) {
if (F->getLinkage() == GlobalValue::ExternalLinkage)
F->setLinkage(GlobalValue::InternalLinkage);
if (F->isDefTriviallyDead())
M.getFunctionList().erase(F);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ bool RISCVLegalizerInfo::legalizeVAStart(MachineInstr &MI,
return true;
}

bool RISCVLegalizerInfo::shouldBeInConstantPool(APInt APImm,
bool RISCVLegalizerInfo::shouldBeInConstantPool(const APInt &APImm,
bool ShouldOptForSize) const {
assert(APImm.getBitWidth() == 32 || APImm.getBitWidth() == 64);
int64_t Imm = APImm.getSExtValue();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RISCVLegalizerInfo : public LegalizerInfo {
MachineInstr &MI) const override;

private:
bool shouldBeInConstantPool(APInt APImm, bool ShouldOptForSize) const;
bool shouldBeInConstantPool(const APInt &APImm, bool ShouldOptForSize) const;
bool legalizeShlAshrLshr(MachineInstr &MI, MachineIRBuilder &MIRBuilder,
GISelChangeObserver &Observer) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ struct RuntimeLibcallSignatureTable {
Table[RTLIB::ATAN_F32] = f32_func_f32;
Table[RTLIB::ATAN_F64] = f64_func_f64;
Table[RTLIB::ATAN_F128] = i64_i64_func_i64_i64;
Table[RTLIB::ATAN2_F32] = f32_func_f32_f32;
Table[RTLIB::ATAN2_F64] = f64_func_f64_f64;
Table[RTLIB::ATAN2_F128] = i64_i64_func_i64_i64_i64_i64;
Table[RTLIB::SINH_F32] = f32_func_f32;
Table[RTLIB::SINH_F64] = f64_func_f64;
Table[RTLIB::SINH_F128] = i64_i64_func_i64_i64;
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ target triple = "dxil-pc-shadermodel6.7-library"
; CHECK-NEXT: ; Double-precision extensions for 11.1
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: {{^;$}}
define double @div(double %a, double %b) {
define double @div(double %a, double %b) #0 {
%res = fdiv double %a, %b
ret double %res
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}

; DXC: - Name: SFI0
; DXC-NEXT: Size: 8
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/CodeGen/DirectX/ShaderFlags/doubles.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ target triple = "dxil-pc-shadermodel6.7-library"
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: {{^;$}}

define double @add(double %a, double %b) {
define double @add(double %a, double %b) #0 {
%sum = fadd double %a, %b
ret double %sum
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}

; DXC: - Name: SFI0
; DXC-NEXT: Size: 8
; DXC-NEXT: Flags:
Expand Down
10 changes: 6 additions & 4 deletions llvm/test/CodeGen/DirectX/conflicting-bitcast-insert.ll
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
; RUN: llc --filetype=asm %s -o - | FileCheck %s
target triple = "dxil-unknown-shadermodel6.7-library"

define i64 @test(ptr %p) {
define i64 @test(ptr %p) #0 {
store i32 0, ptr %p
%v = load i64, ptr %p
ret i64 %v
}

; CHECK: define internal i64 @test(ptr %p) {
; CHECK: define i64 @test(ptr %p) #0 {
; CHECK-NEXT: %1 = bitcast ptr %p to ptr
; CHECK-NEXT: store i32 0, ptr %1, align 4
; CHECK-NEXT: %2 = bitcast ptr %p to ptr
; CHECK-NEXT: %3 = load i64, ptr %2, align 8

define i64 @testGEP(ptr %p) {
define i64 @testGEP(ptr %p) #0 {
%ptr = getelementptr i32, ptr %p, i32 4
%val = load i64, ptr %p
ret i64 %val
}

; CHECK: define internal i64 @testGEP(ptr %p) {
attributes #0 = { convergent norecurse nounwind "hlsl.export"}

; CHECK: define i64 @testGEP(ptr %p) #0 {
; CHECK-NEXT: %1 = bitcast ptr %p to ptr
; CHECK-NEXT: %ptr = getelementptr i32, ptr %1, i32 4
; CHECK-NEXT: %2 = bitcast ptr %p to ptr
Expand Down
222 changes: 222 additions & 0 deletions llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead-lib.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-library %s | FileCheck %s
; RUN: llc %s --filetype=asm -o - | FileCheck %s

target triple = "dxilv1.5-pc-shadermodel6.5-compute"

; Confirm that DXILFinalizeLinkage will remove functions that have compatible
; linkage and are not called from anywhere. This should be any function that
; is not explicitly marked export and is not an entry point.

; Has no specified inlining/linking behavior and is uncalled, this should be removed.
; CHECK-NOT: define {{.*}}doNothingUncalled
define void @"?doNothingUncalled@@YAXXZ"() #2 {
entry:
ret void
}

; Alwaysinline and uncalled, this should be removed.
; CHECK-NOT: define {{.*}}doAlwaysInlineUncalled
define void @"?doAlwaysInlineUncalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline and uncalled, this should be removed.
; CHECK-NOT: define {{.*}}doNoinlineUncalled
define void @"?doNoinlineUncalled@@YAXXZ"() #4 {
entry:
ret void
}

; No inlining attribute, internal, and uncalled; this should be removed.
; CHECK-NOT: define {{.*}}doInternalUncalled
define internal void @"?doInternalUncalled@@YAXXZ"() #2 {
entry:
ret void
}

; Alwaysinline, internal, and uncalled; this should be removed.
; CHECK-NOT: define {{.*}}doAlwaysInlineInternalUncalled
define internal void @"?doAlwaysInlineInternalUncalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, internal, and uncalled; this should be removed.
; CHECK-NOT: define {{.*}}doNoinlineInternalUncalled
define internal void @"?doNoinlineInternalUncalled@@YAXXZ"() #4 {
entry:
ret void
}

; Marked external and uncalled, this should become internal and be removed.
; CHECK-NOT: define {{.*}}doExternalUncalled
define external void @"?doExternalUncalled@@YAXXZ"() #2 {
entry:
ret void
}

; Alwaysinline, external and uncalled, this should become internal and be removed.
; CHECK-NOT: define {{.*}}doAlwaysInlineExternalUncalled
define external void @"?doAlwaysInlineExternalUncalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, external and uncalled, this should become internal and be removed.
; CHECK-NOT: define {{.*}}doNoinlineExternalUncalled
define external void @"?doNoinlineExternalUncalled@@YAXXZ"() #4 {
entry:
ret void
}

; No inlining attribute and called, this should stay.
; CHECK: define {{.*}}doNothingCalled
define void @"?doNothingCalled@@YAXXZ"() #2 {
entry:
ret void
}

; Alwaysinline and called, this should stay.
; CHECK: define {{.*}}doAlwaysInlineCalled
define void @"?doAlwaysInlineCalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline and called, this should stay.
; CHECK: define {{.*}}doNoinlineCalled
define void @"?doNoinlineCalled@@YAXXZ"() #4 {
entry:
ret void
}

; No inlining attribute, internal, and called; this should stay.
; CHECK: define {{.*}}doInternalCalled
define internal void @"?doInternalCalled@@YAXXZ"() #2 {
entry:
ret void
}

; Alwaysinline, internal, and called; this should stay.
; CHECK: define {{.*}}doAlwaysInlineInternalCalled
define internal void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, internal, and called; this should stay.
; CHECK: define {{.*}}doNoinlineInternalCalled
define internal void @"?doNoinlineInternalCalled@@YAXXZ"() #4 {
entry:
ret void
}

; Marked external and called, this should become internal and stay.
; CHECK: define {{.*}}doExternalCalled
define external void @"?doExternalCalled@@YAXXZ"() #2 {
entry:
ret void
}

; Always inlined, external and called, this should become internal and stay.
; CHECK: define {{.*}}doAlwaysInlineExternalCalled
define external void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, external and called, this should become internal and stay.
; CHECK: define {{.*}}doNoinlineExternalCalled
define external void @"?doNoinlineExternalCalled@@YAXXZ"() #4 {
entry:
ret void
}

; No inlining attribute and exported, this should stay.
; CHECK: define {{.*}}doNothingExported
define void @"?doNothingExported@@YAXXZ"() #3 {
entry:
ret void
}

; Alwaysinline and exported, this should stay.
; CHECK: define {{.*}}doAlwaysInlineExported
define void @"?doAlwaysInlineExported@@YAXXZ"() #1 {
entry:
ret void
}

; Noinline attribute and exported, this should stay.
; CHECK: define {{.*}}doNoinlineExported
define void @"?doNoinlineExported@@YAXXZ"() #5 {
entry:
ret void
}

; No inlining attribute, internal, and exported; this should stay.
; CHECK: define {{.*}}doInternalExported
define internal void @"?doInternalExported@@YAXXZ"() #3 {
entry:
ret void
}

; Alwaysinline, internal, and exported; this should stay.
; CHECK: define {{.*}}doAlwaysInlineInternalExported
define internal void @"?doAlwaysInlineInternalExported@@YAXXZ"() #1 {
entry:
ret void
}

; Noinline, internal, and exported; this should stay.
; CHECK: define {{.*}}doNoinlineInternalExported
define internal void @"?doNoinlineInternalExported@@YAXXZ"() #5 {
entry:
ret void
}

; Marked external and exported, this should stay.
; CHECK: define {{.*}}doExternalExported
define external void @"?doExternalExported@@YAXXZ"() #3 {
entry:
ret void
}

; Alwaysinline, external and exported, this should stay.
; CHECK: define {{.*}}doAlwaysInlineExternalExported
define external void @"?doAlwaysInlineExternalExported@@YAXXZ"() #1 {
entry:
ret void
}

; Noinline, external and exported, this should stay.
; CHECK: define {{.*}}doNoinlineExternalExported
define external void @"?doNoinlineExternalExported@@YAXXZ"() #5 {
entry:
ret void
}

; Entry point function, this should stay.
; CHECK: define void @main()
define void @main() #6 {
entry:
call void @"?doNothingCalled@@YAXXZ"() #7
call void @"?doAlwaysInlineCalled@@YAXXZ"() #7
call void @"?doNoinlineCalled@@YAXXZ"() #7
call void @"?doInternalCalled@@YAXXZ"() #7
call void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #7
call void @"?doNoinlineInternalCalled@@YAXXZ"() #7
call void @"?doExternalCalled@@YAXXZ"() #7
call void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #7
call void @"?doNoinlineExternalCalled@@YAXXZ"() #7
ret void
}

attributes #0 = { alwaysinline convergent norecurse nounwind }
attributes #1 = { alwaysinline convergent norecurse nounwind "hlsl.export"}
attributes #2 = { convergent norecurse nounwind }
attributes #3 = { convergent norecurse nounwind "hlsl.export"}
attributes #4 = { convergent noinline norecurse nounwind }
attributes #5 = { convergent noinline norecurse nounwind "hlsl.export"}
attributes #6 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
attributes #7 = { convergent }
156 changes: 156 additions & 0 deletions llvm/test/CodeGen/DirectX/finalize-linkage-remove-dead.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
; RUN: opt -S -dxil-finalize-linkage -mtriple=dxil-unknown-shadermodel6.5-compute %s | FileCheck %s
; RUN: llc %s --filetype=asm -o - | FileCheck %s

target triple = "dxilv1.5-pc-shadermodel6.5-compute"

; Confirm that DXILFinalizeLinkage will remove functions that have compatible
; linkage and are not called from anywhere. This should be any function that
; is not an entry point.

; Has no specified inlining/linking behavior and is uncalled, this should be removed.
; CHECK-NOT: define {{.*}}doNothingUncalled
define void @"?doNothingUncalled@@YAXXZ"() #1 {
entry:
ret void
}

; Alwaysinline and uncalled, this should be removed.
; CHECK-NOT: define {{.*}}doAlwaysInlineUncalled
define void @"?doAlwaysInlineUncalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline and uncalled, this should be removed.
; CHECK-NOT: define {{.*}}doNoinlineUncalled
define void @"?doNoinlineUncalled@@YAXXZ"() #3 {
entry:
ret void
}

; No inlining attribute, internal, and uncalled; this should be removed.
; CHECK-NOT: define {{.*}}doInternalUncalled
define internal void @"?doInternalUncalled@@YAXXZ"() #1 {
entry:
ret void
}

; Alwaysinline, internal, and uncalled; this should be removed.
; CHECK-NOT: define {{.*}}doAlwaysInlineInternalUncalled
define internal void @"?doAlwaysInlineInternalUncalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, internal, and uncalled; this should be removed.
; CHECK-NOT: define {{.*}}doNoinlineInternalUncalled
define internal void @"?doNoinlineInternalUncalled@@YAXXZ"() #3 {
entry:
ret void
}

; Marked external and uncalled, this should become internal and be removed.
; CHECK-NOT: define {{.*}}doExternalUncalled
define external void @"?doExternalUncalled@@YAXXZ"() #1 {
entry:
ret void
}

; Alwaysinline, external and uncalled, this should become internal and be removed.
; CHECK-NOT: define {{.*}}doAlwaysInlineExternalUncalled
define external void @"?doAlwaysInlineExternalUncalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, external and uncalled, this should become internal and be removed.
; CHECK-NOT: define {{.*}}doNoinlineExternalUncalled
define external void @"?doNoinlineExternalUncalled@@YAXXZ"() #3 {
entry:
ret void
}

; No inlining attribute and called, this should stay.
; CHECK: define {{.*}}doNothingCalled
define void @"?doNothingCalled@@YAXXZ"() #1 {
entry:
ret void
}

; Alwaysinline and called, this should stay.
; CHECK: define {{.*}}doAlwaysInlineCalled
define void @"?doAlwaysInlineCalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline and called, this should stay.
; CHECK: define {{.*}}doNoinlineCalled
define void @"?doNoinlineCalled@@YAXXZ"() #3 {
entry:
ret void
}

; No inlining attribute, internal, and called; this should stay.
; CHECK: define {{.*}}doInternalCalled
define internal void @"?doInternalCalled@@YAXXZ"() #1 {
entry:
ret void
}

; Alwaysinline, internal, and called; this should stay.
; CHECK: define {{.*}}doAlwaysInlineInternalCalled
define internal void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, internal, and called; this should stay.
; CHECK: define {{.*}}doNoinlineInternalCalled
define internal void @"?doNoinlineInternalCalled@@YAXXZ"() #3 {
entry:
ret void
}

; Marked external and called, this should become internal and stay.
; CHECK: define {{.*}}doExternalCalled
define external void @"?doExternalCalled@@YAXXZ"() #1 {
entry:
ret void
}

; Always inlined, external and called, this should become internal and stay.
; CHECK: define {{.*}}doAlwaysInlineExternalCalled
define external void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #0 {
entry:
ret void
}

; Noinline, external and called, this should become internal and stay.
; CHECK: define {{.*}}doNoinlineExternalCalled
define external void @"?doNoinlineExternalCalled@@YAXXZ"() #3 {
entry:
ret void
}

; Entry point function, this should stay.
; CHECK: define void @main()
define void @main() #4 {
entry:
call void @"?doNothingCalled@@YAXXZ"() #5
call void @"?doAlwaysInlineCalled@@YAXXZ"() #5
call void @"?doNoinlineCalled@@YAXXZ"() #5
call void @"?doInternalCalled@@YAXXZ"() #5
call void @"?doAlwaysInlineInternalCalled@@YAXXZ"() #5
call void @"?doNoinlineInternalCalled@@YAXXZ"() #5
call void @"?doExternalCalled@@YAXXZ"() #5
call void @"?doAlwaysInlineExternalCalled@@YAXXZ"() #5
call void @"?doNoinlineExternalCalled@@YAXXZ"() #5
ret void
}

attributes #0 = { alwaysinline convergent norecurse nounwind }
attributes #1 = { convergent norecurse nounwind }
attributes #3 = { convergent noinline norecurse nounwind }
attributes #4 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
attributes #5 = { convergent }
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/DirectX/finalize_linkage.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target triple = "dxilv1.5-pc-shadermodel6.5-compute"
; DXILFinalizeLinkage changes linkage of all functions that are not
; entry points or exported function to internal.

; CHECK: define internal void @"?f1@@YAXXZ"()
; CHECK-NOT: define internal void @"?f1@@YAXXZ"()
define void @"?f1@@YAXXZ"() #0 {
entry:
ret void
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/fneg-conversion.ll
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
; RUN: llc %s --filetype=asm -o - | FileCheck %s
target triple = "dxil-unknown-shadermodel6.7-library"

define float @negateF(float %0) {
define float @negateF(float %0) #0 {
; CHECK: %2 = fsub float -0.000000e+00, %0
%2 = fneg float %0
ret float %2
}

define double @negateD(double %0) {
define double @negateD(double %0) #0 {
; CHECK: %2 = fsub double -0.000000e+00, %0
%2 = fneg double %0
ret double %2
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}
14 changes: 8 additions & 6 deletions llvm/test/CodeGen/DirectX/omit-bitcast-insert.ll
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
; RUN: llc --filetype=asm %s -o - | FileCheck %s
target triple = "dxil-unknown-shadermodel6.7-library"

define i64 @test(ptr %p) {
define i64 @test(ptr %p) #0 {
%v = load i64, ptr %p
ret i64 %v
}

; CHECK: define internal i64 @test(ptr %p) {
; CHECK: define i64 @test(ptr %p) #0 {
; CHECK-NEXT: %v = load i64, ptr %p, align 8
; CHECK-NEXT: ret i64 %v

define i64 @test2(ptr %p) {
define i64 @test2(ptr %p) #0 {
store i64 0, ptr %p
%v = load i64, ptr %p
ret i64 %v
}

; CHECK: define internal i64 @test2(ptr %p) {
; CHECK: define i64 @test2(ptr %p) #0 {
; CHECK-NEXT: store i64 0, ptr %p
; CHECK-NEXT: %v = load i64, ptr %p, align 8
; CHECK-NEXT: ret i64 %v

define i32 @test3(ptr %0) {
define i32 @test3(ptr %0) #0 {
%2 = getelementptr i32, ptr %0, i32 4
%3 = load i32, ptr %2
ret i32 %3
}

; CHECK: define internal i32 @test3(ptr %0) {
attributes #0 = { convergent norecurse nounwind "hlsl.export"}

; CHECK: define i32 @test3(ptr %0) #0 {
; CHECK-NEXT: %2 = getelementptr i32, ptr %0, i32 4
; CHECK-NEXT: %3 = load i32, ptr %2
10 changes: 6 additions & 4 deletions llvm/test/CodeGen/DirectX/scalar-load.ll
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


; CHECK-LABEL: load_array_vec_test
define <4 x i32> @load_array_vec_test() {
define <4 x i32> @load_array_vec_test() #0 {
; CHECK-COUNT-8: load i32, ptr addrspace(3) {{(.*@arrayofVecData.scalarized.*|%.*)}}, align 4
; CHECK-NOT: load i32, ptr addrspace(3) {{.*}}, align 4
%1 = load <4 x i32>, <4 x i32> addrspace(3)* getelementptr inbounds ([2 x <4 x i32>], [2 x <4 x i32>] addrspace(3)* @"arrayofVecData", i32 0, i32 0), align 4
Expand All @@ -30,15 +30,15 @@ define <4 x i32> @load_array_vec_test() {
}

; CHECK-LABEL: load_vec_test
define <4 x i32> @load_vec_test() {
define <4 x i32> @load_vec_test() #0 {
; CHECK-COUNT-4: load i32, ptr addrspace(3) {{(@vecData.scalarized|getelementptr \(i32, ptr addrspace\(3\) @vecData.scalarized, i32 .*\)|%.*)}}, align {{.*}}
; CHECK-NOT: load i32, ptr addrspace(3) {{.*}}, align 4
%1 = load <4 x i32>, <4 x i32> addrspace(3)* @"vecData", align 4
ret <4 x i32> %1
}

; CHECK-LABEL: load_static_array_of_vec_test
define <4 x i32> @load_static_array_of_vec_test(i32 %index) {
define <4 x i32> @load_static_array_of_vec_test(i32 %index) #0 {
; CHECK: getelementptr [3 x [4 x i32]], ptr @staticArrayOfVecData.scalarized, i32 0, i32 %index
; CHECK-COUNT-4: load i32, ptr {{.*}}, align 4
; CHECK-NOT: load i32, ptr {{.*}}, align 4
Expand All @@ -48,11 +48,13 @@ define <4 x i32> @load_static_array_of_vec_test(i32 %index) {
}

; CHECK-LABEL: multid_load_test
define <4 x i32> @multid_load_test() {
define <4 x i32> @multid_load_test() #0 {
; CHECK-COUNT-8: load i32, ptr addrspace(3) {{(.*@groushared2dArrayofVectors.scalarized.*|%.*)}}, align 4
; CHECK-NOT: load i32, ptr addrspace(3) {{.*}}, align 4
%1 = load <4 x i32>, <4 x i32> addrspace(3)* getelementptr inbounds ([3 x [3 x <4 x i32>]], [3 x [3 x <4 x i32>]] addrspace(3)* @"groushared2dArrayofVectors", i32 0, i32 0, i32 0), align 4
%2 = load <4 x i32>, <4 x i32> addrspace(3)* getelementptr inbounds ([3 x [3 x <4 x i32>]], [3 x [3 x <4 x i32>]] addrspace(3)* @"groushared2dArrayofVectors", i32 0, i32 1, i32 1), align 4
%3 = add <4 x i32> %1, %2
ret <4 x i32> %3
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/scalar-store.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
; CHECK-NOT: @vecData

; CHECK-LABEL: store_array_vec_test
define void @store_array_vec_test () local_unnamed_addr {
define void @store_array_vec_test () local_unnamed_addr #0 {
; CHECK-COUNT-6: store float {{1|2|3|4|6}}.000000e+00, ptr addrspace(3) {{(.*@arrayofVecData.scalarized.*|%.*)}}, align {{4|8|16}}
; CHECK-NOT: store float {{1|2|3|4|6}}.000000e+00, ptr addrspace(3) {{(.*@arrayofVecData.scalarized.*|%.*)}}, align {{4|8|16}}
store <3 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>, ptr addrspace(3) @"arrayofVecData", align 16
Expand All @@ -21,9 +21,11 @@ define void @store_array_vec_test () local_unnamed_addr {
}

; CHECK-LABEL: store_vec_test
define void @store_vec_test(<4 x i32> %inputVec) {
define void @store_vec_test(<4 x i32> %inputVec) #0 {
; CHECK-COUNT-4: store i32 %inputVec.{{.*}}, ptr addrspace(3) {{(@vecData.scalarized|getelementptr \(i32, ptr addrspace\(3\) @vecData.scalarized, i32 .*\)|%.*)}}, align 4
; CHECK-NOT: store i32 %inputVec.{{.*}}, ptr addrspace(3)
store <4 x i32> %inputVec, <4 x i32> addrspace(3)* @"vecData", align 4
ret void
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}
4 changes: 3 additions & 1 deletion llvm/test/CodeGen/DirectX/scalarize-two-calls.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

; CHECK: target triple = "dxilv1.3-pc-shadermodel6.3-library"
; CHECK-LABEL: cos_sin_float_test
define noundef <4 x float> @cos_sin_float_test(<4 x float> noundef %a) {
define noundef <4 x float> @cos_sin_float_test(<4 x float> noundef %a) #0 {
; CHECK: [[ee0:%.*]] = extractelement <4 x float> %a, i64 0
; CHECK: [[ie0:%.*]] = call float @dx.op.unary.f32(i32 13, float [[ee0]])
; CHECK: [[ee1:%.*]] = extractelement <4 x float> %a, i64 1
Expand All @@ -23,3 +23,5 @@ define noundef <4 x float> @cos_sin_float_test(<4 x float> noundef %a) {
%3 = tail call <4 x float> @llvm.cos.v4f32(<4 x float> %2)
ret <4 x float> %3
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/DirectX/strip-fn-attrs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ define dso_local float @fma(float %0, float %1, float %2) local_unnamed_addr #0
; CHECK: attributes #0 = { nounwind memory(none) }
; CHECK-NOT: attributes #

attributes #0 = { norecurse nounwind readnone willreturn }
attributes #0 = { norecurse nounwind readnone willreturn "hlsl.export"}
316 changes: 170 additions & 146 deletions llvm/test/CodeGen/WebAssembly/libcalls-trig.ll

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions llvm/test/CodeGen/X86/fp-strict-libcalls-msvc32.ll
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ define float @atan(float %x) #0 {
ret float %result
}

define float @atan2(float %x, float %y) #0 {
; CHECK-LABEL: atan2:
; CHECK: # %bb.0:
; CHECK-NEXT: subl $20, %esp
; CHECK-NEXT: flds {{[0-9]+}}(%esp)
; CHECK-NEXT: flds {{[0-9]+}}(%esp)
; CHECK-NEXT: fxch %st(1)
; CHECK-NEXT: fstpl {{[0-9]+}}(%esp)
; CHECK-NEXT: fstpl (%esp)
; CHECK-NEXT: wait
; CHECK-NEXT: calll _atan2
; CHECK-NEXT: fstps {{[0-9]+}}(%esp)
; CHECK-NEXT: flds {{[0-9]+}}(%esp)
; CHECK-NEXT: wait
; CHECK-NEXT: addl $20, %esp
; CHECK-NEXT: retl
%result = call float @llvm.experimental.constrained.atan2.f32(float %x, float %y, metadata !"round.dynamic", metadata !"fpexcept.strict") #0
ret float %result
}

define float @cosh(float %x) #0 {
; CHECK-LABEL: cosh:
; CHECK: # %bb.0:
Expand Down Expand Up @@ -263,6 +283,7 @@ define float @sinh(float %x) #0 {
}

define float @tanh(float %x) #0 {
; CHECK-LABEL: tanh:
; CHECK: # %bb.0:
; CHECK-NEXT: subl $12, %esp
; CHECK-NEXT: flds {{[0-9]+}}(%esp)
Expand Down Expand Up @@ -293,6 +314,7 @@ declare float @llvm.experimental.constrained.tan.f32(float, metadata, metadata)
declare float @llvm.experimental.constrained.acos.f32(float, metadata, metadata)
declare float @llvm.experimental.constrained.asin.f32(float, metadata, metadata)
declare float @llvm.experimental.constrained.atan.f32(float, metadata, metadata)
declare float @llvm.experimental.constrained.atan2.f32(float, float, metadata, metadata)
declare float @llvm.experimental.constrained.cosh.f32(float, metadata, metadata)
declare float @llvm.experimental.constrained.sinh.f32(float, metadata, metadata)
declare float @llvm.experimental.constrained.tanh.f32(float, metadata, metadata)