[clang] [HLSL] Implement frexp() (PR #235154)

Dan Brown via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 29 10:31:16 PST 2026


https://github.com/danbrown-amd updated https://github.com/llvm/llvm-project/pull/235154

>From f8f81e6da8006f5a17f6d77c9045e5de31e346b0 Mon Sep 17 00:00:00 2001
From: danbrown-amd <danbrown at amd.com>
Date: Fri, 16 Oct 2026 18:15:51 -0600
Subject: [PATCH 1/2] [HLSL] Implement frexp()

Resolves #99119, #220654

Assisted-by: Claude Opus 5
---
 .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h |  33 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h      |  38 ++++
 clang/test/CodeGenHLSL/builtins/frexp.hlsl    |  96 ++++++++
 .../test/CodeGenHLSL/builtins/frexp_mat.hlsl  | 208 ++++++++++++++++++
 .../test/SemaHLSL/BuiltIns/frexp-errors.hlsl  |  50 +++++
 .../SemaHLSL/BuiltIns/frexp_mat-errors.hlsl   |  12 +
 6 files changed, 437 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/frexp.hlsl
 create mode 100644 clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 5bcce0f68c3865..1c63fd9aff02e9 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -104,6 +104,39 @@ template <typename T> constexpr T fmod_impl(T X, T Y) {
 #endif
 }
 
+// Returns the mantissa of X, which has the sign of X and an absolute value in
+// [0.5, 1), and writes the exponent to Exp such that X = Mant * 2^Exp. X can be
+// a scalar, vector or matrix of float.
+template <typename T> constexpr T frexp_impl(T X, out T Exp) {
+  auto Bits = bit_cast<uint>(X);
+  auto ExpBits = Bits & 0x7f800000u;
+  // Zeros, denormals, infinities and NaNs are returned as they are, with an
+  // exponent of 0. These are exactly the cases where the exponent field is 0 or
+  // all ones, so ExpBits - 1 is at least 0x7f7fffff, whether it wraps around or
+  // not. This avoids ||, which is not supported on vectors.
+  auto IsSpecial = (ExpBits - 1u) >= 0x7f7fffffu;
+  // Keep the sign and the fraction, and replace the exponent with the one for
+  // 0.5, which scales X into [0.5, 1).
+  auto MantBits = (Bits & 0x807fffffu) | 0x3f000000u;
+  T Mant = select(IsSpecial, X, bit_cast<float>(MantBits));
+  auto RawExp = (ExpBits >> 23u) - 126u;
+  Exp = select(IsSpecial, static_cast<T>(0),
+               static_cast<T>(bit_cast<int>(RawExp)));
+  return Mant;
+}
+
+// Matrices do not support the bitwise operators, so frexp_impl works on the
+// elements of the matrix as a vector.
+template <int R, int C>
+constexpr matrix<float, R, C> frexp_impl(matrix<float, R, C> X,
+                                         out matrix<float, R, C> Exp) {
+  vector<float, R * C> VecExp;
+  vector<float, R * C> VecMant =
+      frexp_impl(__builtin_bit_cast(vector<float, R * C>, X), VecExp);
+  Exp = __builtin_bit_cast(matrix<float, R, C>, VecExp);
+  return __builtin_bit_cast(matrix<float, R, C>, VecMant);
+}
+
 template <typename T> constexpr T smoothstep_impl(T Min, T Max, T X) {
 #if (__has_builtin(__builtin_spirv_smoothstep))
   return __builtin_spirv_smoothstep(Min, Max, X);
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 9ad6ba2f087d86..f331be96ac8c92 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -220,6 +220,44 @@ firstbithigh(vector<T, N> X) {
   return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 64>(X);
 }
 
+//===----------------------------------------------------------------------===//
+// frexp builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn T frexp(T X, out T Exp)
+/// \brief Returns the mantissa and exponent of the specified floating-point
+/// value.
+/// \param X The specified floating-point value.
+/// \param Exp The returned exponent of X.
+///
+/// The mantissa has the same sign as X and an absolute value in [0.5, 1), such
+/// that X = mantissa * 2^Exp. If X is 0, both the mantissa and the exponent
+/// are 0.
+inline float frexp(float X, out float Exp) {
+  return __detail::frexp_impl(X, Exp);
+}
+inline float2 frexp(float2 X, out float2 Exp) {
+  return __detail::frexp_impl(X, Exp);
+}
+inline float3 frexp(float3 X, out float3 Exp) {
+  return __detail::frexp_impl(X, Exp);
+}
+inline float4 frexp(float4 X, out float4 Exp) {
+  return __detail::frexp_impl(X, Exp);
+}
+template <int N>
+inline vector<__detail::enable_if_t<(N > 4), float>, N>
+frexp(vector<__detail::enable_if_t<(N > 4), float>, N> X,
+      out __detail::type_identity_t<vector<float, N>> Exp) {
+  return __detail::frexp_impl(X, Exp);
+}
+template <int R, int C>
+inline matrix<float, R, C>
+frexp(matrix<float, R, C> X,
+      out __detail::type_identity_t<matrix<float, R, C>> Exp) {
+  return __detail::frexp_impl(X, Exp);
+}
+
 //===----------------------------------------------------------------------===//
 // mul builtins
 //===----------------------------------------------------------------------===//
diff --git a/clang/test/CodeGenHLSL/builtins/frexp.hlsl b/clang/test/CodeGenHLSL/builtins/frexp.hlsl
new file mode 100644
index 00000000000000..d627b53abb6071
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/frexp.hlsl
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -O1 -emit-llvm -o - | FileCheck %s \
+// RUN:   --check-prefixes=CHECK,DXCHECK
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   spirv-unknown-vulkan-library %s -O1 -emit-llvm -o - | FileCheck %s \
+// RUN:   --check-prefixes=CHECK,SPVCHECK
+
+// The only difference between the targets is the calling convention on the
+// definitions. It is captured once, in the first function, as [[FN_TYPE]].
+
+// DXCHECK: define hidden [[FN_TYPE:]]noundef nofpclass(nan inf) float @{{.*}}test_frexp_f{{.*}}(
+// SPVCHECK: define hidden [[FN_TYPE:spir_func ]]noundef nofpclass(nan inf) float @{{.*}}test_frexp_f{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast float %X to i32
+// CHECK:      [[EXPBITS:%.*]] = and i32 [[BITS]], 2139095040
+// CHECK:      and i32 [[BITS]], -2139095041
+// CHECK:      or {{.*}}i32 {{.*}}, 1056964608
+// CHECK:      [[MANT:%.*]] = select {{.*}}, float %X, float {{.*}}
+// CHECK:      lshr {{.*}}i32 [[EXPBITS]], 23
+// CHECK:      sitofp {{.*}}i32 {{.*}} to float
+// CHECK:      [[EXP:%.*]] = select {{.*}}, float 0.000000e+00, float {{.*}}
+// CHECK-NEXT: store float [[EXP]], ptr %E
+// CHECK-NEXT: ret float [[MANT]]
+float test_frexp_f(float X, out float E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f2{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <2 x float> %X to <2 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <2 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <2 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<2 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> %X, <2 x float> {{.*}}
+// CHECK:      lshr {{.*}}<2 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<2 x i32> {{.*}} to <2 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <2 x float> zeroinitializer, <2 x float> {{.*}}
+// CHECK-NEXT: store <2 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <2 x float> [[MANT]]
+float2 test_frexp_f2(float2 X, out float2 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <3 x float> @{{.*}}test_frexp_f3{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <3 x float> %X to <3 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <3 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <3 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<3 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> %X, <3 x float> {{.*}}
+// CHECK:      lshr {{.*}}<3 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<3 x i32> {{.*}} to <3 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <3 x float> zeroinitializer, <3 x float> {{.*}}
+// CHECK-NEXT: store <3 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <3 x float> [[MANT]]
+float3 test_frexp_f3(float3 X, out float3 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f4{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
+// CHECK-NEXT: store <4 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <4 x float> [[MANT]]
+float4 test_frexp_f4(float4 X, out float4 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <5 x float> @{{.*}}test_frexp_f5{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <5 x float> %X to <5 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <5 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <5 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<5 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <5 x float> %X, <5 x float> {{.*}}
+// CHECK:      lshr {{.*}}<5 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<5 x i32> {{.*}} to <5 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <5 x float> zeroinitializer, <5 x float> {{.*}}
+// CHECK-NEXT: store <5 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <5 x float> [[MANT]]
+vector<float, 5> test_frexp_f5(vector<float, 5> X, out vector<float, 5> E) {
+  return frexp(X, E);
+}
+
+// The exponent can also be an integer, as with DXC. It is computed as a float
+// and converted when it is written back, which folds away here because the
+// exponent is an exact integer.
+
+// CHECK: define {{.*}}test_frexp_int_exp_scalar
+// CHECK:      [[EXPI:%.*]] = select {{.*}}, i32 0, i32 {{.*}}
+// CHECK-NEXT: store i32 [[EXPI]], ptr %E
+// CHECK-NEXT: ret float
+float test_frexp_int_exp_scalar(float X, out int E) { return frexp(X, E); }
+
+// CHECK: define {{.*}}test_frexp_int_exp_long
+// CHECK:      [[EXPI:%.*]] = select {{.*}}, <8 x i32> zeroinitializer, <8 x i32> {{.*}}
+// CHECK-NEXT: store <8 x i32> [[EXPI]], ptr %E
+// CHECK-NEXT: ret <8 x float>
+vector<float, 8> test_frexp_int_exp_long(vector<float, 8> X,
+                                         out vector<int, 8> E) {
+  return frexp(X, E);
+}
diff --git a/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl b/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl
new file mode 100644
index 00000000000000..8e71aa3d811940
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl
@@ -0,0 +1,208 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -O1 -emit-llvm -o - | FileCheck %s \
+// RUN:   --check-prefixes=CHECK,DXCHECK
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   spirv-unknown-vulkan-library %s -O1 -emit-llvm -o - | FileCheck %s \
+// RUN:   --check-prefixes=CHECK,SPVCHECK
+
+// Matrices are handled as vectors with one element per matrix element, so the
+// code is the same as for a vector of that size.
+
+// The only difference between the targets is the calling convention on the
+// definitions. It is captured once, in the first function, as [[FN_TYPE]].
+
+// DXCHECK: define hidden [[FN_TYPE:]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f1x2{{.*}}(
+// SPVCHECK: define hidden [[FN_TYPE:spir_func ]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f1x2{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <2 x float> %X to <2 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <2 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <2 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<2 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> %X, <2 x float> {{.*}}
+// CHECK:      lshr {{.*}}<2 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<2 x i32> {{.*}} to <2 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <2 x float> zeroinitializer, <2 x float> {{.*}}
+// CHECK-NEXT: store <2 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <2 x float> [[MANT]]
+float1x2 test_frexp_f1x2(float1x2 X, out float1x2 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <3 x float> @{{.*}}test_frexp_f1x3{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <3 x float> %X to <3 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <3 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <3 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<3 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> %X, <3 x float> {{.*}}
+// CHECK:      lshr {{.*}}<3 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<3 x i32> {{.*}} to <3 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <3 x float> zeroinitializer, <3 x float> {{.*}}
+// CHECK-NEXT: store <3 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <3 x float> [[MANT]]
+float1x3 test_frexp_f1x3(float1x3 X, out float1x3 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f1x4{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
+// CHECK-NEXT: store <4 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <4 x float> [[MANT]]
+float1x4 test_frexp_f1x4(float1x4 X, out float1x4 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f2x1{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <2 x float> %X to <2 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <2 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <2 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<2 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> %X, <2 x float> {{.*}}
+// CHECK:      lshr {{.*}}<2 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<2 x i32> {{.*}} to <2 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <2 x float> zeroinitializer, <2 x float> {{.*}}
+// CHECK-NEXT: store <2 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <2 x float> [[MANT]]
+float2x1 test_frexp_f2x1(float2x1 X, out float2x1 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f2x2{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
+// CHECK-NEXT: store <4 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <4 x float> [[MANT]]
+float2x2 test_frexp_f2x2(float2x2 X, out float2x2 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <6 x float> @{{.*}}test_frexp_f2x3{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <6 x float> %X to <6 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <6 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <6 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<6 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <6 x float> %X, <6 x float> {{.*}}
+// CHECK:      lshr {{.*}}<6 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<6 x i32> {{.*}} to <6 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <6 x float> zeroinitializer, <6 x float> {{.*}}
+// CHECK-NEXT: store <6 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <6 x float> [[MANT]]
+float2x3 test_frexp_f2x3(float2x3 X, out float2x3 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <8 x float> @{{.*}}test_frexp_f2x4{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <8 x float> %X to <8 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <8 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <8 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<8 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <8 x float> %X, <8 x float> {{.*}}
+// CHECK:      lshr {{.*}}<8 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<8 x i32> {{.*}} to <8 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <8 x float> zeroinitializer, <8 x float> {{.*}}
+// CHECK-NEXT: store <8 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <8 x float> [[MANT]]
+float2x4 test_frexp_f2x4(float2x4 X, out float2x4 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <3 x float> @{{.*}}test_frexp_f3x1{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <3 x float> %X to <3 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <3 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <3 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<3 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> %X, <3 x float> {{.*}}
+// CHECK:      lshr {{.*}}<3 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<3 x i32> {{.*}} to <3 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <3 x float> zeroinitializer, <3 x float> {{.*}}
+// CHECK-NEXT: store <3 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <3 x float> [[MANT]]
+float3x1 test_frexp_f3x1(float3x1 X, out float3x1 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <6 x float> @{{.*}}test_frexp_f3x2{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <6 x float> %X to <6 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <6 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <6 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<6 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <6 x float> %X, <6 x float> {{.*}}
+// CHECK:      lshr {{.*}}<6 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<6 x i32> {{.*}} to <6 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <6 x float> zeroinitializer, <6 x float> {{.*}}
+// CHECK-NEXT: store <6 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <6 x float> [[MANT]]
+float3x2 test_frexp_f3x2(float3x2 X, out float3x2 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <9 x float> @{{.*}}test_frexp_f3x3{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <9 x float> %X to <9 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <9 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <9 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<9 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <9 x float> %X, <9 x float> {{.*}}
+// CHECK:      lshr {{.*}}<9 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<9 x i32> {{.*}} to <9 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <9 x float> zeroinitializer, <9 x float> {{.*}}
+// CHECK-NEXT: store <9 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <9 x float> [[MANT]]
+float3x3 test_frexp_f3x3(float3x3 X, out float3x3 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <12 x float> @{{.*}}test_frexp_f3x4{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <12 x float> %X to <12 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <12 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <12 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<12 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <12 x float> %X, <12 x float> {{.*}}
+// CHECK:      lshr {{.*}}<12 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<12 x i32> {{.*}} to <12 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <12 x float> zeroinitializer, <12 x float> {{.*}}
+// CHECK-NEXT: store <12 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <12 x float> [[MANT]]
+float3x4 test_frexp_f3x4(float3x4 X, out float3x4 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f4x1{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
+// CHECK-NEXT: store <4 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <4 x float> [[MANT]]
+float4x1 test_frexp_f4x1(float4x1 X, out float4x1 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <8 x float> @{{.*}}test_frexp_f4x2{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <8 x float> %X to <8 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <8 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <8 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<8 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <8 x float> %X, <8 x float> {{.*}}
+// CHECK:      lshr {{.*}}<8 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<8 x i32> {{.*}} to <8 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <8 x float> zeroinitializer, <8 x float> {{.*}}
+// CHECK-NEXT: store <8 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <8 x float> [[MANT]]
+float4x2 test_frexp_f4x2(float4x2 X, out float4x2 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <12 x float> @{{.*}}test_frexp_f4x3{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <12 x float> %X to <12 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <12 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <12 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<12 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <12 x float> %X, <12 x float> {{.*}}
+// CHECK:      lshr {{.*}}<12 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<12 x i32> {{.*}} to <12 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <12 x float> zeroinitializer, <12 x float> {{.*}}
+// CHECK-NEXT: store <12 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <12 x float> [[MANT]]
+float4x3 test_frexp_f4x3(float4x3 X, out float4x3 E) { return frexp(X, E); }
+
+// CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <16 x float> @{{.*}}test_frexp_f4x4{{.*}}(
+// CHECK:      [[BITS:%.*]] = bitcast <16 x float> %X to <16 x i32>
+// CHECK:      [[EXPBITS:%.*]] = and <16 x i32> [[BITS]], splat (i32 2139095040)
+// CHECK:      and <16 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      or {{.*}}<16 x i32> {{.*}}, splat (i32 1056964608)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <16 x float> %X, <16 x float> {{.*}}
+// CHECK:      lshr {{.*}}<16 x i32> [[EXPBITS]], splat (i32 23)
+// CHECK:      sitofp {{.*}}<16 x i32> {{.*}} to <16 x float>
+// CHECK:      [[EXP:%.*]] = select {{.*}}, <16 x float> zeroinitializer, <16 x float> {{.*}}
+// CHECK-NEXT: store <16 x float> [[EXP]], ptr %E
+// CHECK-NEXT: ret <16 x float> [[MANT]]
+float4x4 test_frexp_f4x4(float4x4 X, out float4x4 E) { return frexp(X, E); }
diff --git a/clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl
new file mode 100644
index 00000000000000..676c40c43733f7
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library -fsyntax-only -verify %s
+
+float test_no_second_arg(float X) {
+  return frexp(X);
+  // expected-error at -1 {{no matching function for call to 'frexp'}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* 4 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* 2 {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
+}
+
+float test_too_many_args(float X) {
+  float E, F;
+  return frexp(X, E, F);
+  // expected-error at -1 {{no matching function for call to 'frexp'}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* 4 {{candidate function not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_intrinsics.h:* 2 {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
+}
+
+float test_exp_rvalue(float X) {
+  return frexp(X, 1.0f);
+  // expected-error at -1 {{cannot bind non-lvalue argument '1.F' to out parameter}}
+}
+
+float test_exp_const(float X) {
+  const float E = 0;
+  return frexp(X, E);
+  // expected-error at -1 {{read-only variable is not assignable}}
+}
+
+float3 test_vector_exp_rvalue(float3 X) {
+  return frexp(X, X * 2);
+  // expected-error at -1 {{cannot bind non-lvalue argument 'X * 2' to out parameter}}
+}
+
+vector<float, 8> test_long_vector_exp_rvalue(vector<float, 8> X) {
+  return frexp(X, X * 2);
+  // expected-error at -1 {{cannot bind non-lvalue argument 'X * 2' to out parameter}}
+}
+
+// Only float is supported, so other types are converted, as with DXC.
+float test_double_input(double X) {
+  float E;
+  return frexp(X, E);
+  // expected-warning at -1 {{implicit conversion loses floating-point precision: 'double' to 'float'}}
+}
+
+float test_int_input(int X) {
+  float E;
+  return frexp(X, E);
+  // expected-warning at -1 {{implicit conversion from 'int' to 'float' may lose precision}}
+}
diff --git a/clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl
new file mode 100644
index 00000000000000..c9e15dd7d00a16
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library -fsyntax-only -verify %s
+
+float2x2 test_exp_rvalue(float2x2 X) {
+  return frexp(X, X * 2);
+  // expected-error at -1 {{cannot bind non-lvalue argument 'X * 2' to out parameter}}
+}
+
+float2x2 test_exp_const(float2x2 X) {
+  const float2x2 E = 0;
+  return frexp(X, E);
+  // expected-error at -1 {{read-only variable is not assignable}}
+}

>From 376c2fbd69348da5139c2399e6b2eb80ba1be57a Mon Sep 17 00:00:00 2001
From: danbrown-amd <danbrown at amd.com>
Date: Sun, 29 Nov 2026 12:23:16 -0600
Subject: [PATCH 2/2] match dxc (DXIL) behavior instead of C++ standard amd
 remove unnecessary sema tests

---
 .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 17 +----
 clang/test/CodeGenHLSL/builtins/frexp.hlsl    | 25 ++++---
 .../test/CodeGenHLSL/builtins/frexp_mat.hlsl  | 75 +++++++++++--------
 .../test/SemaHLSL/BuiltIns/frexp-errors.hlsl  | 50 -------------
 .../SemaHLSL/BuiltIns/frexp_mat-errors.hlsl   | 12 ---
 5 files changed, 63 insertions(+), 116 deletions(-)
 delete mode 100644 clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl
 delete mode 100644 clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 1c63fd9aff02e9..62064620da014a 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -104,29 +104,18 @@ template <typename T> constexpr T fmod_impl(T X, T Y) {
 #endif
 }
 
-// Returns the mantissa of X, which has the sign of X and an absolute value in
-// [0.5, 1), and writes the exponent to Exp such that X = Mant * 2^Exp. X can be
-// a scalar, vector or matrix of float.
 template <typename T> constexpr T frexp_impl(T X, out T Exp) {
   auto Bits = bit_cast<uint>(X);
   auto ExpBits = Bits & 0x7f800000u;
-  // Zeros, denormals, infinities and NaNs are returned as they are, with an
-  // exponent of 0. These are exactly the cases where the exponent field is 0 or
-  // all ones, so ExpBits - 1 is at least 0x7f7fffff, whether it wraps around or
-  // not. This avoids ||, which is not supported on vectors.
-  auto IsSpecial = (ExpBits - 1u) >= 0x7f7fffffu;
-  // Keep the sign and the fraction, and replace the exponent with the one for
-  // 0.5, which scales X into [0.5, 1).
-  auto MantBits = (Bits & 0x807fffffu) | 0x3f000000u;
-  T Mant = select(IsSpecial, X, bit_cast<float>(MantBits));
+  auto IsSpecial = (ExpBits - 1u) >= 0x7f7fffffu; // true iff Bits 0 or inf
+  auto MantBits = (Bits & 0x007fffffu) | 0x3f000000u;
+  T Mant = select(IsSpecial, abs(X), bit_cast<float>(MantBits));
   auto RawExp = (ExpBits >> 23u) - 126u;
   Exp = select(IsSpecial, static_cast<T>(0),
                static_cast<T>(bit_cast<int>(RawExp)));
   return Mant;
 }
 
-// Matrices do not support the bitwise operators, so frexp_impl works on the
-// elements of the matrix as a vector.
 template <int R, int C>
 constexpr matrix<float, R, C> frexp_impl(matrix<float, R, C> X,
                                          out matrix<float, R, C> Exp) {
diff --git a/clang/test/CodeGenHLSL/builtins/frexp.hlsl b/clang/test/CodeGenHLSL/builtins/frexp.hlsl
index d627b53abb6071..67b82780776409 100644
--- a/clang/test/CodeGenHLSL/builtins/frexp.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/frexp.hlsl
@@ -12,9 +12,10 @@
 // SPVCHECK: define hidden [[FN_TYPE:spir_func ]]noundef nofpclass(nan inf) float @{{.*}}test_frexp_f{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast float %X to i32
 // CHECK:      [[EXPBITS:%.*]] = and i32 [[BITS]], 2139095040
-// CHECK:      and i32 [[BITS]], -2139095041
+// CHECK:      and i32 [[BITS]], 8388607
 // CHECK:      or {{.*}}i32 {{.*}}, 1056964608
-// CHECK:      [[MANT:%.*]] = select {{.*}}, float %X, float {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}float @llvm.fabs.f32({{.*}}float {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, float [[ABS]], float {{.*}}
 // CHECK:      lshr {{.*}}i32 [[EXPBITS]], 23
 // CHECK:      sitofp {{.*}}i32 {{.*}} to float
 // CHECK:      [[EXP:%.*]] = select {{.*}}, float 0.000000e+00, float {{.*}}
@@ -25,9 +26,10 @@ float test_frexp_f(float X, out float E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f2{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <2 x float> %X to <2 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <2 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <2 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <2 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<2 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> %X, <2 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<2 x float> @llvm.fabs.v2f32({{.*}}<2 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> [[ABS]], <2 x float> {{.*}}
 // CHECK:      lshr {{.*}}<2 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<2 x i32> {{.*}} to <2 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <2 x float> zeroinitializer, <2 x float> {{.*}}
@@ -38,9 +40,10 @@ float2 test_frexp_f2(float2 X, out float2 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <3 x float> @{{.*}}test_frexp_f3{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <3 x float> %X to <3 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <3 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <3 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <3 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<3 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> %X, <3 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<3 x float> @llvm.fabs.v3f32({{.*}}<3 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> [[ABS]], <3 x float> {{.*}}
 // CHECK:      lshr {{.*}}<3 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<3 x i32> {{.*}} to <3 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <3 x float> zeroinitializer, <3 x float> {{.*}}
@@ -51,9 +54,10 @@ float3 test_frexp_f3(float3 X, out float3 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f4{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<4 x float> @llvm.fabs.v4f32({{.*}}<4 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> [[ABS]], <4 x float> {{.*}}
 // CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
@@ -64,9 +68,10 @@ float4 test_frexp_f4(float4 X, out float4 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <5 x float> @{{.*}}test_frexp_f5{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <5 x float> %X to <5 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <5 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <5 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <5 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<5 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <5 x float> %X, <5 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<5 x float> @llvm.fabs.v5f32({{.*}}<5 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <5 x float> [[ABS]], <5 x float> {{.*}}
 // CHECK:      lshr {{.*}}<5 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<5 x i32> {{.*}} to <5 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <5 x float> zeroinitializer, <5 x float> {{.*}}
diff --git a/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl b/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl
index 8e71aa3d811940..db324bdaf086e3 100644
--- a/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/frexp_mat.hlsl
@@ -15,9 +15,10 @@
 // SPVCHECK: define hidden [[FN_TYPE:spir_func ]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f1x2{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <2 x float> %X to <2 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <2 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <2 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <2 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<2 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> %X, <2 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<2 x float> @llvm.fabs.v2f32({{.*}}<2 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> [[ABS]], <2 x float> {{.*}}
 // CHECK:      lshr {{.*}}<2 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<2 x i32> {{.*}} to <2 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <2 x float> zeroinitializer, <2 x float> {{.*}}
@@ -28,9 +29,10 @@ float1x2 test_frexp_f1x2(float1x2 X, out float1x2 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <3 x float> @{{.*}}test_frexp_f1x3{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <3 x float> %X to <3 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <3 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <3 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <3 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<3 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> %X, <3 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<3 x float> @llvm.fabs.v3f32({{.*}}<3 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> [[ABS]], <3 x float> {{.*}}
 // CHECK:      lshr {{.*}}<3 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<3 x i32> {{.*}} to <3 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <3 x float> zeroinitializer, <3 x float> {{.*}}
@@ -41,9 +43,10 @@ float1x3 test_frexp_f1x3(float1x3 X, out float1x3 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f1x4{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<4 x float> @llvm.fabs.v4f32({{.*}}<4 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> [[ABS]], <4 x float> {{.*}}
 // CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
@@ -54,9 +57,10 @@ float1x4 test_frexp_f1x4(float1x4 X, out float1x4 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <2 x float> @{{.*}}test_frexp_f2x1{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <2 x float> %X to <2 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <2 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <2 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <2 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<2 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> %X, <2 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<2 x float> @llvm.fabs.v2f32({{.*}}<2 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <2 x float> [[ABS]], <2 x float> {{.*}}
 // CHECK:      lshr {{.*}}<2 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<2 x i32> {{.*}} to <2 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <2 x float> zeroinitializer, <2 x float> {{.*}}
@@ -67,9 +71,10 @@ float2x1 test_frexp_f2x1(float2x1 X, out float2x1 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f2x2{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<4 x float> @llvm.fabs.v4f32({{.*}}<4 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> [[ABS]], <4 x float> {{.*}}
 // CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
@@ -80,9 +85,10 @@ float2x2 test_frexp_f2x2(float2x2 X, out float2x2 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <6 x float> @{{.*}}test_frexp_f2x3{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <6 x float> %X to <6 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <6 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <6 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <6 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<6 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <6 x float> %X, <6 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<6 x float> @llvm.fabs.v6f32({{.*}}<6 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <6 x float> [[ABS]], <6 x float> {{.*}}
 // CHECK:      lshr {{.*}}<6 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<6 x i32> {{.*}} to <6 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <6 x float> zeroinitializer, <6 x float> {{.*}}
@@ -93,9 +99,10 @@ float2x3 test_frexp_f2x3(float2x3 X, out float2x3 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <8 x float> @{{.*}}test_frexp_f2x4{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <8 x float> %X to <8 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <8 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <8 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <8 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<8 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <8 x float> %X, <8 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<8 x float> @llvm.fabs.v8f32({{.*}}<8 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <8 x float> [[ABS]], <8 x float> {{.*}}
 // CHECK:      lshr {{.*}}<8 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<8 x i32> {{.*}} to <8 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <8 x float> zeroinitializer, <8 x float> {{.*}}
@@ -106,9 +113,10 @@ float2x4 test_frexp_f2x4(float2x4 X, out float2x4 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <3 x float> @{{.*}}test_frexp_f3x1{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <3 x float> %X to <3 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <3 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <3 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <3 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<3 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> %X, <3 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<3 x float> @llvm.fabs.v3f32({{.*}}<3 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <3 x float> [[ABS]], <3 x float> {{.*}}
 // CHECK:      lshr {{.*}}<3 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<3 x i32> {{.*}} to <3 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <3 x float> zeroinitializer, <3 x float> {{.*}}
@@ -119,9 +127,10 @@ float3x1 test_frexp_f3x1(float3x1 X, out float3x1 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <6 x float> @{{.*}}test_frexp_f3x2{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <6 x float> %X to <6 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <6 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <6 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <6 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<6 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <6 x float> %X, <6 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<6 x float> @llvm.fabs.v6f32({{.*}}<6 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <6 x float> [[ABS]], <6 x float> {{.*}}
 // CHECK:      lshr {{.*}}<6 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<6 x i32> {{.*}} to <6 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <6 x float> zeroinitializer, <6 x float> {{.*}}
@@ -132,9 +141,10 @@ float3x2 test_frexp_f3x2(float3x2 X, out float3x2 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <9 x float> @{{.*}}test_frexp_f3x3{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <9 x float> %X to <9 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <9 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <9 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <9 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<9 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <9 x float> %X, <9 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<9 x float> @llvm.fabs.v9f32({{.*}}<9 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <9 x float> [[ABS]], <9 x float> {{.*}}
 // CHECK:      lshr {{.*}}<9 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<9 x i32> {{.*}} to <9 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <9 x float> zeroinitializer, <9 x float> {{.*}}
@@ -145,9 +155,10 @@ float3x3 test_frexp_f3x3(float3x3 X, out float3x3 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <12 x float> @{{.*}}test_frexp_f3x4{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <12 x float> %X to <12 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <12 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <12 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <12 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<12 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <12 x float> %X, <12 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<12 x float> @llvm.fabs.v12f32({{.*}}<12 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <12 x float> [[ABS]], <12 x float> {{.*}}
 // CHECK:      lshr {{.*}}<12 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<12 x i32> {{.*}} to <12 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <12 x float> zeroinitializer, <12 x float> {{.*}}
@@ -158,9 +169,10 @@ float3x4 test_frexp_f3x4(float3x4 X, out float3x4 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <4 x float> @{{.*}}test_frexp_f4x1{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <4 x float> %X to <4 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <4 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <4 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <4 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<4 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> %X, <4 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<4 x float> @llvm.fabs.v4f32({{.*}}<4 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <4 x float> [[ABS]], <4 x float> {{.*}}
 // CHECK:      lshr {{.*}}<4 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<4 x i32> {{.*}} to <4 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <4 x float> zeroinitializer, <4 x float> {{.*}}
@@ -171,9 +183,10 @@ float4x1 test_frexp_f4x1(float4x1 X, out float4x1 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <8 x float> @{{.*}}test_frexp_f4x2{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <8 x float> %X to <8 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <8 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <8 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <8 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<8 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <8 x float> %X, <8 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<8 x float> @llvm.fabs.v8f32({{.*}}<8 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <8 x float> [[ABS]], <8 x float> {{.*}}
 // CHECK:      lshr {{.*}}<8 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<8 x i32> {{.*}} to <8 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <8 x float> zeroinitializer, <8 x float> {{.*}}
@@ -184,9 +197,10 @@ float4x2 test_frexp_f4x2(float4x2 X, out float4x2 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <12 x float> @{{.*}}test_frexp_f4x3{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <12 x float> %X to <12 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <12 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <12 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <12 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<12 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <12 x float> %X, <12 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<12 x float> @llvm.fabs.v12f32({{.*}}<12 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <12 x float> [[ABS]], <12 x float> {{.*}}
 // CHECK:      lshr {{.*}}<12 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<12 x i32> {{.*}} to <12 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <12 x float> zeroinitializer, <12 x float> {{.*}}
@@ -197,9 +211,10 @@ float4x3 test_frexp_f4x3(float4x3 X, out float4x3 E) { return frexp(X, E); }
 // CHECK: define hidden [[FN_TYPE]]noundef nofpclass(nan inf) <16 x float> @{{.*}}test_frexp_f4x4{{.*}}(
 // CHECK:      [[BITS:%.*]] = bitcast <16 x float> %X to <16 x i32>
 // CHECK:      [[EXPBITS:%.*]] = and <16 x i32> [[BITS]], splat (i32 2139095040)
-// CHECK:      and <16 x i32> [[BITS]], splat (i32 -2139095041)
+// CHECK:      and <16 x i32> [[BITS]], splat (i32 8388607)
 // CHECK:      or {{.*}}<16 x i32> {{.*}}, splat (i32 1056964608)
-// CHECK:      [[MANT:%.*]] = select {{.*}}, <16 x float> %X, <16 x float> {{.*}}
+// CHECK:      [[ABS:%.*]] = {{.*}}call {{.*}}<16 x float> @llvm.fabs.v16f32({{.*}}<16 x float> {{.*}}%X)
+// CHECK:      [[MANT:%.*]] = select {{.*}}, <16 x float> [[ABS]], <16 x float> {{.*}}
 // CHECK:      lshr {{.*}}<16 x i32> [[EXPBITS]], splat (i32 23)
 // CHECK:      sitofp {{.*}}<16 x i32> {{.*}} to <16 x float>
 // CHECK:      [[EXP:%.*]] = select {{.*}}, <16 x float> zeroinitializer, <16 x float> {{.*}}
diff --git a/clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl
deleted file mode 100644
index 676c40c43733f7..00000000000000
--- a/clang/test/SemaHLSL/BuiltIns/frexp-errors.hlsl
+++ /dev/null
@@ -1,50 +0,0 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library -fsyntax-only -verify %s
-
-float test_no_second_arg(float X) {
-  return frexp(X);
-  // expected-error at -1 {{no matching function for call to 'frexp'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* 4 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* 2 {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-}
-
-float test_too_many_args(float X) {
-  float E, F;
-  return frexp(X, E, F);
-  // expected-error at -1 {{no matching function for call to 'frexp'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* 4 {{candidate function not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* 2 {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-}
-
-float test_exp_rvalue(float X) {
-  return frexp(X, 1.0f);
-  // expected-error at -1 {{cannot bind non-lvalue argument '1.F' to out parameter}}
-}
-
-float test_exp_const(float X) {
-  const float E = 0;
-  return frexp(X, E);
-  // expected-error at -1 {{read-only variable is not assignable}}
-}
-
-float3 test_vector_exp_rvalue(float3 X) {
-  return frexp(X, X * 2);
-  // expected-error at -1 {{cannot bind non-lvalue argument 'X * 2' to out parameter}}
-}
-
-vector<float, 8> test_long_vector_exp_rvalue(vector<float, 8> X) {
-  return frexp(X, X * 2);
-  // expected-error at -1 {{cannot bind non-lvalue argument 'X * 2' to out parameter}}
-}
-
-// Only float is supported, so other types are converted, as with DXC.
-float test_double_input(double X) {
-  float E;
-  return frexp(X, E);
-  // expected-warning at -1 {{implicit conversion loses floating-point precision: 'double' to 'float'}}
-}
-
-float test_int_input(int X) {
-  float E;
-  return frexp(X, E);
-  // expected-warning at -1 {{implicit conversion from 'int' to 'float' may lose precision}}
-}
diff --git a/clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl
deleted file mode 100644
index c9e15dd7d00a16..00000000000000
--- a/clang/test/SemaHLSL/BuiltIns/frexp_mat-errors.hlsl
+++ /dev/null
@@ -1,12 +0,0 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library -fsyntax-only -verify %s
-
-float2x2 test_exp_rvalue(float2x2 X) {
-  return frexp(X, X * 2);
-  // expected-error at -1 {{cannot bind non-lvalue argument 'X * 2' to out parameter}}
-}
-
-float2x2 test_exp_const(float2x2 X) {
-  const float2x2 E = 0;
-  return frexp(X, E);
-  // expected-error at -1 {{read-only variable is not assignable}}
-}



More information about the cfe-commits mailing list