[clang] 88af280 - [HLSL] Rewrite inline HLSL intrinsics into TableGen (#188362)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 7 13:30:44 PDT 2026


Author: Deric C.
Date: 2026-04-07T13:30:38-07:00
New Revision: 88af28072637213c32cd53c99c4b9d79ded6e746

URL: https://github.com/llvm/llvm-project/commit/88af28072637213c32cd53c99c4b9d79ded6e746
DIFF: https://github.com/llvm/llvm-project/commit/88af28072637213c32cd53c99c4b9d79ded6e746.diff

LOG: [HLSL] Rewrite inline HLSL intrinsics into TableGen (#188362)

Partially addresses https://github.com/llvm/llvm-project/issues/188345.
This PR rewrites all applicable inline HLSL intrinsics from
`hlsl_intrinsics.h` into TableGen.

The unsigned `abs` from `hlsl_alias_intrinsics.h` is also rewritten into
TableGen since it can also be defined inline.

The `NonUniformResourceIndex` is moved from `hlsl_intrinsics.h` over to
`hlsl_alias_intrinsics.h` since it can be defined as an alias.

`__detail::.*_impl` helper functions that were one liners have been
removed, and their corresponding HLSL intrinsics have been defined in
TableGen using the `Body` field instead.

Note that rewriting `refract` in TableGen instead of templates
introduces some significant changes to error messages and also
introduces a new offload test suite failure in the fp16 test because a
call to `refract(x, y, 0.5)` where x and y are half-typed vectors is
ambiguous due to 0.5 being a 32-bit float literal.

The generated `hlsl_inline_intrinsics_gen.inc` file looks like this:
https://gist.github.com/Icohedron/a1c4a47ad0bb184f857430835d7d2ca3

Assisted-by: GitHub Copilot

---------

Co-authored-by: Justin Bogner <mail at justinbogner.com>

Added: 
    

Modified: 
    clang/include/clang/Basic/HLSLIntrinsics.td
    clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
    clang/lib/Headers/hlsl/hlsl_detail.h
    clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
    clang/lib/Headers/hlsl/hlsl_intrinsics.h
    clang/test/CodeGenHLSL/builtins/dst.hlsl
    clang/test/CodeGenHLSL/builtins/ldexp.hlsl
    clang/test/CodeGenHLSL/resources/NonUniformResourceIndex.hlsl
    clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/dot2add-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl
    clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td
index b205491e6ca78..43cce9ea57cd6 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -313,8 +313,329 @@ class HLSLOneArgInlineBuiltin<string name> : HLSLBuiltin<name> {
 // Intrinsic definitions (sorted alphabetically by function name)
 //===----------------------------------------------------------------------===//
 
-// TODO: Convert hand-written overloads from hlsl_intrinsics.h and
-//       hlsl_alias_intrinsics.h into TableGen below.
-//       Include "hlsl_alias_intrinsics_gen.inc" in hlsl_alias_intrinsics.h
-//       Include "hlsl_inline_intrinsics_gen.inc" in hlsl_intrinsics.h
+def hlsl_abs_unsigned : HLSLOneArgInlineBuiltin<"abs"> {
+  let Doc = [{
+\fn T abs(T Val)
+\brief Returns the absolute value of the input value, \a Val.
+\param Val The input value.
+
+Unsigned overload — unsigned values are already non-negative, so this
+function returns its input unchanged.
+}];
+  let ParamNames = ["V"];
+  let Body = "return V;";
+  let IsConstexpr = 1;
+  let VaryingTypes = UnsignedIntTypes;
+  let VaryingMatDims = [];
+}
+
+def hlsl_check_access_fully_mapped : HLSLBuiltin<"CheckAccessFullyMapped"> {
+  let Doc = [{
+\fn bool CheckAccessFullyMapped(uint Status)
+\brief Checks whether the value is fully mapped.
+\param Status The status value to check.
+}];
+  let ParamNames = ["Status"];
+  let Body = "return static_cast<bool>(Status);";
+  let Args = [UIntTy];
+  let ReturnType = BoolTy;
+}
+
+def hlsl_d3d_color_to_ubyte4 : HLSLBuiltin<"D3DCOLORtoUBYTE4"> {
+  let Doc = [{
+\fn int4 D3DCOLORtoUBYTE4(float4 x)
+\brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
+\param x [in] The floating-point vector4 to convert.
+
+The return value is the UBYTE4 representation of the \a x parameter.
+
+This function swizzles and scales components of the \a x parameter. Use this
+function to compensate for the lack of UBYTE4 support in some hardware.
+}];
+  // Use the scaling factor used by FXC, and DXC for DXIL (i.e., 255.001953).
+  // The [DXC implementation] refers to [stack overflow] to justify the scaling
+  // factor:
+  // > Built-in rounding, necessary because of truncation. 0.001953 * 256 = 0.5
+  // 
+  // [DXC implementation]: https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
+  // [stack overflow]: https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
+  let Body = "return V.zyxw * 255.001953f;";
+  let ParamNames = ["V"];
+  let Args = [VectorType<FloatTy, 4>];
+  let ReturnType = VectorType<IntTy, 4>;
+  let IsConstexpr = 1;
+}
+
+def hlsl_ddx : HLSLOneArgDetail<"ddx", "ddx_impl"> {
+  let Doc = [{
+\fn T ddx(T x)
+\brief Computes the partial derivative of the specified value with regard to
+the screen-space x-coordinate.
+\param x [in] The floating-point scalar or vector to process.
+}];
+  let ParamNames = ["input"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+def hlsl_ddy : HLSLOneArgDetail<"ddy", "ddy_impl"> {
+  let Doc = [{
+\fn T ddy(T x)
+\brief Computes the partial derivative of the specified value with regard to
+the screen-space y-coordinate.
+\param x [in] The floating-point scalar or vector to process.
+}];
+  let ParamNames = ["input"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+def hlsl_distance : HLSLBuiltin<"distance"> {
+  let Doc = [{
+\fn K distance(T X, T Y)
+\brief Returns a distance scalar between \a X and \a Y.
+\param X The X input value.
+\param Y The Y input value.
+}];
+  let Body = "return __detail::length_impl(X - Y);";
+  let ParamNames = ["X", "Y"];
+  let Args = [Varying, Varying];
+  let ReturnType = VaryingElemType;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+def hlsl_dot2add : HLSLBuiltin<"dot2add"> {
+  let Doc = [{
+\fn float dot2add(half2 A, half2 B, float Acc)
+\brief Multiplies the elements of the two half-precision float input vectors
+together and sums the results into the 32-bit float accumulator.
+\param A The first input value to dot product.
+\param B The second input value to dot product.
+\param Acc The accumulator value added to the dot product.
+
+This instruction operates within a single 32-bit wide SIMD lane.
+The inputs are 16-bit quantities packed into the same lane.
+}];
+  let DetailFunc = "dot2add_impl";
+  let ParamNames = ["A", "B", "Acc"];
+  let Args = [VectorType<HalfTy, 2>, VectorType<HalfTy, 2>, FloatTy];
+  let ReturnType = FloatTy;
+  let Availability = SM6_4;
+}
 
+def hlsl_dst : HLSLBuiltin<"dst"> {
+  let Doc = [{
+\fn vector<T, 4> dst(vector<T, 4> Src0, vector<T, 4> Src1)
+\brief Calculates a distance vector.
+\param Src0 [in] Contains the squared distance.
+\param Src1 [in] Contains the reciprocal distance.
+
+Return the computed distance vector.
+}];
+  let ParamNames = ["Src0", "Src1"];
+  let Body = "return {1, Src0[1] * Src1[1], Src0[2], Src1[3]};";
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = AllFloatTypes;
+  let VaryingVecSizes = [4];
+  let VaryingMatDims = [];
+}
+
+def hlsl_faceforward : HLSLThreeArgDetail<"faceforward", "faceforward_impl"> {
+  let Doc = [{
+\fn T faceforward(T N, T I, T Ng)
+\brief Flips the surface-normal (if needed) to face in a direction opposite
+to \a I. Returns the result in terms of \a N.
+\param N The resulting floating-point surface-normal vector.
+\param I A floating-point, incident vector that points from the view
+position to the shading position.
+\param Ng A floating-point surface-normal vector.
+
+Return a floating-point, surface normal vector that is facing the view
+direction.
+}];
+  let ParamNames = ["N", "I", "Ng"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+def hlsl_fmod : HLSLBuiltin<"fmod"> {
+  let Doc = [{
+\fn T fmod(T x, T y)
+\brief Returns the floating-point remainder of x/y.
+\param x [in] The dividend.
+\param y [in] The divisor.
+
+Return the floating-point remainder of the x parameter divided by the y
+parameter.
+}];
+  let DetailFunc = "fmod_impl";
+  let ParamNames = ["X", "Y"];
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingMatDims = [];
+}
+def hlsl_fmod_vec : HLSLBuiltin<"fmod"> {
+  let DetailFunc = "fmod_vec_impl";
+  let ParamNames = ["X", "Y"];
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+def hlsl_fwidth : HLSLOneArgDetail<"fwidth", "fwidth_impl"> {
+  let Doc = [{
+\fn T fwidth(T x)
+\brief Computes the sum of the absolute values of the partial derivatives
+with regard to the x and y screen space coordinates.
+\param x [in] The floating-point scalar or vector to process.
+}];
+  let ParamNames = ["input"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+def hlsl_ldexp : HLSLBuiltin<"ldexp"> {
+  let Doc = [{
+\fn T ldexp(T X, T Exp)
+\brief Returns the result of multiplying the specified value by two raised
+to the power of the specified exponent.
+\param X [in] The specified value.
+\param Exp [in] The specified exponent.
+}];
+  let ParamNames = ["X", "Exp"];
+  let Body = "return exp2(Exp) * X;";
+  let Args = [Varying, Varying];
+  let ReturnType = Varying;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+def hlsl_length : HLSLBuiltin<"length"> {
+  let Doc = [{
+\fn T length(T x)
+\brief Returns the length of the specified floating-point vector.
+\param x [in] The vector of floats, or a scalar float.
+
+Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
+}];
+  let DetailFunc = "length_impl";
+  let ParamNames = ["X"];
+  let Args = [Varying];
+  let ReturnType = VaryingElemType;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+def hlsl_lit_half : HLSLBuiltin<"lit"> {
+  let Doc = [{
+\fn vector<T, 4> lit(T NDotL, T NDotH, T M)
+\brief Returns a lighting coefficient vector.
+\param NDotL The dot product of the normalized surface normal and the
+light vector.
+\param NDotH The dot product of the half-angle vector and the surface
+normal.
+\param M A specular exponent.
+
+This function returns a lighting coefficient vector (ambient, 
diff use,
+specular, 1).
+}];
+  let DetailFunc = "lit_impl";
+  let ParamNames = ["NDotL", "NDotH", "M"];
+  let Args = [HalfTy, HalfTy, HalfTy];
+  let ReturnType = VectorType<HalfTy, 4>;
+}
+
+def hlsl_lit_float : HLSLBuiltin<"lit"> {
+  let DetailFunc = "lit_impl";
+  let ParamNames = ["NDotL", "NDotH", "M"];
+  let Args = [FloatTy, FloatTy, FloatTy];
+  let ReturnType = VectorType<FloatTy, 4>;
+}
+
+def hlsl_reflect : HLSLTwoArgDetail<"reflect", "reflect_impl"> {
+  let Doc = [{
+\fn T reflect(T I, T N)
+\brief Returns a reflection using an incident ray, \a I, and a surface
+normal, \a N.
+\param I The incident ray.
+\param N The surface normal.
+
+The return value is a floating-point vector that represents the reflection
+of the incident ray, \a I, off a surface with the normal \a N.
+
+This function calculates the reflection vector using the following formula:
+V = I - 2 * N * dot(I N) .
+
+N must already be normalized in order to achieve the desired result.
+}];
+  let ParamNames = ["I", "N"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}
+
+def hlsl_refract : HLSLBuiltin<"refract"> {
+  let Doc = [{
+\fn T refract(T I, T N, T eta)
+\brief Returns a refraction using an entering ray, \a I, a surface
+normal, \a N and refraction index \a eta
+\param I The entering ray.
+\param N The surface normal.
+\param eta The refraction index.
+
+The return value is a floating-point vector that represents the refraction
+using the refraction index, \a eta, for the direction of the entering ray,
+\a I, off a surface with the normal \a N.
+
+This function calculates the refraction vector using the following formulas:
+k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
+if k < 0.0 the result is 0.0
+otherwise, the result is eta * I - (eta * dot(N, I) + sqrt(k)) * N
+
+I and N must already be normalized in order to achieve the desired result.
+
+I and N must be a scalar or vector whose component type is
+floating-point.
+
+eta must be a 16-bit or 32-bit floating-point scalar.
+
+Result type, the type of I, and the type of N must all be the same type.
+}];
+  let DetailFunc = "refract_impl";
+  let ParamNames = ["I", "N", "eta"];
+  let Args = [Varying, Varying, VaryingElemType];
+  let ReturnType = Varying;
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingScalar = 1;
+  let VaryingVecSizes = [2, 3, 4];
+  let VaryingMatDims = [];
+}
+
+def hlsl_smoothstep : HLSLThreeArgDetail<"smoothstep", "smoothstep_impl"> {
+  let Doc = [{
+\fn T smoothstep(T Min, T Max, T X)
+\brief Returns a smooth Hermite interpolation between 0 and 1, if \a X is in
+the range [\a Min, \a Max].
+\param Min The minimum range of the x parameter.
+\param Max The maximum range of the x parameter.
+\param X The specified value to be interpolated.
+
+The return value is 0.0 if \a X <= \a Min and 1.0 if \a X >= \a Max. When \a
+Min < \a X < \a Max, the function performs smooth Hermite interpolation
+between 0 and 1.
+}];
+  let ParamNames = ["Min", "Max", "X"];
+  let VaryingTypes = [HalfTy, FloatTy];
+  let VaryingMatDims = [];
+}

diff  --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 80c415ef66644..86a3f051f07c9 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -62,15 +62,6 @@ int16_t3 abs(int16_t3);
 _HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t4 abs(int16_t4);
-
-_HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
-constexpr uint16_t abs(uint16_t V) { return V; }
-_HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
-constexpr uint16_t2 abs(uint16_t2 V) { return V; }
-_HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
-constexpr uint16_t3 abs(uint16_t3 V) { return V; }
-_HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
-constexpr uint16_t4 abs(uint16_t4 V) { return V; }
 #endif
 
 _HLSL_16BIT_AVAILABILITY_SHADERMODEL_DEFAULT()
@@ -95,11 +86,6 @@ int3 abs(int3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int4 abs(int4);
 
-constexpr uint abs(uint V) { return V; }
-constexpr uint2 abs(uint2 V) { return V; }
-constexpr uint3 abs(uint3 V) { return V; }
-constexpr uint4 abs(uint4 V) { return V; }
-
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 float abs(float);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
@@ -118,11 +104,6 @@ int64_t3 abs(int64_t3);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int64_t4 abs(int64_t4);
 
-constexpr uint64_t abs(uint64_t V) { return V; }
-constexpr uint64_t2 abs(uint64_t2 V) { return V; }
-constexpr uint64_t3 abs(uint64_t3 V) { return V; }
-constexpr uint64_t4 abs(uint64_t4 V) { return V; }
-
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 double abs(double);
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
@@ -1948,6 +1929,29 @@ float3 normalize(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_normalize)
 float4 normalize(float4);
 
+//===----------------------------------------------------------------------===//
+// NonUniformResourceIndex builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn uint NonUniformResourceIndex(uint I)
+/// \brief A compiler hint to indicate that a resource index varies across
+/// threads within a wave (i.e., it is non-uniform).
+/// \param I [in] Resource array index
+///
+/// The return value is the \a I parameter.
+///
+/// When indexing into an array of shader resources (e.g., textures, buffers),
+/// some GPU hardware and drivers require the compiler to know whether the index
+/// is uniform (same for all threads) or non-uniform (varies per thread).
+///
+/// Using NonUniformResourceIndex explicitly marks an index as non-uniform,
+/// disabling certain assumptions or optimizations that could lead to incorrect
+/// behavior when dynamically accessing resource arrays with non-uniform
+/// indices.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_resource_nonuniformindex)
+uint NonUniformResourceIndex(uint);
+
 //===----------------------------------------------------------------------===//
 // or builtins
 //===----------------------------------------------------------------------===//

diff  --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h
index 80c4900121dfb..c691d85283de4 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -45,10 +45,6 @@ template <typename T> struct is_arithmetic {
   static const bool Value = __is_arithmetic(T);
 };
 
-template <typename T, int N>
-using HLSL_FIXED_VECTOR =
-    vector<__detail::enable_if_t<(N > 1 && N <= 4), T>, N>;
-
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index f04be2a1aff2a..45a066833afa2 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -12,22 +12,15 @@
 namespace hlsl {
 namespace __detail {
 
-constexpr int4 d3d_color_to_ubyte4_impl(float4 V) {
-  // Use the same scaling factor used by FXC, and DXC for DXIL
-  // (i.e., 255.001953)
-  // https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
-  // The DXC implementation refers to a comment on the following stackoverflow
-  // discussion to justify the scaling factor: "Built-in rounding, necessary
-  // because of truncation. 0.001953 * 256 = 0.5"
-  // https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
-  return V.zyxw * 255.001953f;
+template <typename T>
+constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
+length_impl(T X) {
+  return abs(X);
 }
 
-template <typename T> constexpr T length_impl(T X) { return abs(X); }
-
 template <typename T, int N>
 constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
-length_vec_impl(vector<T, N> X) {
+length_impl(vector<T, N> X) {
 #if (__has_builtin(__builtin_spirv_length))
   return __builtin_spirv_length(X);
 #else
@@ -35,21 +28,6 @@ length_vec_impl(vector<T, N> X) {
 #endif
 }
 
-template <typename T>
-constexpr vector<T, 4> dst_impl(vector<T, 4> Src0, vector<T, 4> Src1) {
-  return {1, Src0[1] * Src1[1], Src0[2], Src1[3]};
-}
-
-template <typename T> constexpr T distance_impl(T X, T Y) {
-  return length_impl(X - Y);
-}
-
-template <typename T, int N>
-constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
-distance_vec_impl(vector<T, N> X, vector<T, N> Y) {
-  return length_vec_impl(X - Y);
-}
-
 constexpr float dot2add_impl(half2 a, half2 b, float c) {
 #if (__has_builtin(__builtin_dx_dot2add))
   return __builtin_dx_dot2add(a, b, c);
@@ -73,12 +51,14 @@ enable_if_t<is_same<double, T>::value, T> mul_vec_impl(vector<T, N> x,
   return sum;
 }
 
-template <typename T> constexpr T reflect_impl(T I, T N) {
+template <typename T>
+constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
+reflect_impl(T I, T N) {
   return I - 2 * N * I * N;
 }
 
 template <typename T, int L>
-constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) {
+constexpr vector<T, L> reflect_impl(vector<T, L> I, vector<T, L> N) {
 #if (__has_builtin(__builtin_spirv_reflect))
   return __builtin_spirv_reflect(I, N);
 #else
@@ -128,17 +108,6 @@ template <typename T> constexpr T smoothstep_impl(T Min, T Max, T X) {
 #endif
 }
 
-template <typename T, int N>
-constexpr vector<T, N> smoothstep_vec_impl(vector<T, N> Min, vector<T, N> Max,
-                                           vector<T, N> X) {
-#if (__has_builtin(__builtin_spirv_smoothstep))
-  return __builtin_spirv_smoothstep(Min, Max, X);
-#else
-  vector<T, N> S = saturate((X - Min) / (Max - Min));
-  return (3 - 2 * S) * S * S;
-#endif
-}
-
 template <typename T> constexpr vector<T, 4> lit_impl(T NDotL, T NDotH, T M) {
   bool DiffuseCond = NDotL < 0;
   T Diffuse = select<T>(DiffuseCond, 0, NDotL);
@@ -152,11 +121,7 @@ template <typename T> constexpr vector<T, 4> lit_impl(T NDotL, T NDotH, T M) {
 }
 
 template <typename T> constexpr T faceforward_impl(T N, T I, T Ng) {
-  return select(dot(I, Ng) < 0, N, -N);
-}
-
-template <typename T> constexpr T ldexp_impl(T X, T Exp) {
-  return exp2(Exp) * X;
+  return select<T>(dot(I, Ng) < 0, N, -N);
 }
 
 template <typename K, typename T, int BitWidth>

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 6a37a50064411..cced7b0eabb1f 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -141,129 +141,6 @@ constexpr __detail::enable_if_t<__detail::is_same<int16_t, T>::value ||
 }
 #endif
 
-//===----------------------------------------------------------------------===//
-// distance builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn K distance(T X, T Y)
-/// \brief Returns a distance scalar between \a X and \a Y.
-/// \param X The X input value.
-/// \param Y The Y input value.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> distance(T X, T Y) {
-  return __detail::distance_impl(X, Y);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-distance(T X, T Y) {
-  return __detail::distance_impl(X, Y);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline half distance(__detail::HLSL_FIXED_VECTOR<half, N> X,
-                           __detail::HLSL_FIXED_VECTOR<half, N> Y) {
-  return __detail::distance_vec_impl(X, Y);
-}
-
-template <int N>
-const inline float distance(__detail::HLSL_FIXED_VECTOR<float, N> X,
-                            __detail::HLSL_FIXED_VECTOR<float, N> Y) {
-  return __detail::distance_vec_impl(X, Y);
-}
-
-//===----------------------------------------------------------------------===//
-// dot2add builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn float dot2add(half2 A, half2 B, float C)
-/// \brief Dot product of 2 vector of type half and add a float scalar value.
-/// \param A The first input value to dot product.
-/// \param B The second input value to dot product.
-/// \param C The input value added to the dot product.
-
-_HLSL_AVAILABILITY(shadermodel, 6.4)
-const inline float dot2add(half2 A, half2 B, float C) {
-  return __detail::dot2add_impl(A, B, C);
-}
-
-//===----------------------------------------------------------------------===//
-// dst builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn vector<T, 4> dst(vector<T, 4>, vector<T, 4>)
-/// \brief Calculates a distance vector.
-/// \param Src0 [in] Contains the squared distance
-/// \param Src1 [in] Contains the reciprocal distance
-///
-/// Return the computed distance vector
-
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline half4 dst(half4 Src0, half4 Src1) {
-  return __detail::dst_impl(Src0, Src1);
-}
-
-const inline float4 dst(float4 Src0, float4 Src1) {
-  return __detail::dst_impl(Src0, Src1);
-}
-
-const inline double4 dst(double4 Src0, double4 Src1) {
-  return __detail::dst_impl(Src0, Src1);
-}
-
-//===----------------------------------------------------------------------===//
-// faceforward builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T faceforward(T N, T I, T Ng)
-/// \brief Flips the surface-normal (if needed) to face in a direction opposite
-/// to \a I. Returns the result in terms of \a N.
-/// \param N The resulting floating-point surface-normal vector.
-/// \param I A floating-point, incident vector that points from the view
-/// position to the shading position.
-/// \param Ng A floating-point surface-normal vector.
-///
-/// Return a floating-point, surface normal vector that is facing the view
-/// direction.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> faceforward(T N, T I, T Ng) {
-  return __detail::faceforward_impl(N, I, Ng);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-faceforward(T N, T I, T Ng) {
-  return __detail::faceforward_impl(N, I, Ng);
-}
-
-template <int L>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, L> faceforward(
-    __detail::HLSL_FIXED_VECTOR<half, L> N,
-    __detail::HLSL_FIXED_VECTOR<half, L> I,
-    __detail::HLSL_FIXED_VECTOR<half, L> Ng) {
-  return __detail::faceforward_impl(N, I, Ng);
-}
-
-template <int L>
-const inline __detail::HLSL_FIXED_VECTOR<float, L>
-faceforward(__detail::HLSL_FIXED_VECTOR<float, L> N,
-            __detail::HLSL_FIXED_VECTOR<float, L> I,
-            __detail::HLSL_FIXED_VECTOR<float, L> Ng) {
-  return __detail::faceforward_impl(N, I, Ng);
-}
-
 //===----------------------------------------------------------------------===//
 // firstbithigh builtins
 //===----------------------------------------------------------------------===//
@@ -325,474 +202,6 @@ firstbithigh(vector<T, N> X) {
   return __detail::firstbithigh_impl<vector<uint, N>, vector<T, N>, 64>(X);
 }
 
-//===----------------------------------------------------------------------===//
-// fmod builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn T fmod(T x, T y)
-/// \brief Returns the linear interpolation of x to y.
-/// \param x [in] The dividend.
-/// \param y [in] The divisor.
-///
-/// Return the floating-point remainder of the x parameter divided by the y
-/// parameter.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> fmod(T X, T Y) {
-  return __detail::fmod_impl(X, Y);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-fmod(T X, T Y) {
-  return __detail::fmod_impl(X, Y);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, N> fmod(
-    __detail::HLSL_FIXED_VECTOR<half, N> X,
-    __detail::HLSL_FIXED_VECTOR<half, N> Y) {
-  return __detail::fmod_vec_impl(X, Y);
-}
-
-template <int N>
-const inline __detail::HLSL_FIXED_VECTOR<float, N>
-fmod(__detail::HLSL_FIXED_VECTOR<float, N> X,
-     __detail::HLSL_FIXED_VECTOR<float, N> Y) {
-  return __detail::fmod_vec_impl(X, Y);
-}
-
-//===----------------------------------------------------------------------===//
-// ldexp builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn T ldexp(T X, T Exp)
-/// \brief Returns the result of multiplying the specified value by two raised
-/// to the power of the specified exponent.
-/// \param X [in] The specified value.
-/// \param Exp [in] The specified exponent.
-///
-/// This function uses the following formula: X * 2^Exp
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> ldexp(T X, T Exp) {
-  return __detail::ldexp_impl(X, Exp);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-ldexp(T X, T Exp) {
-  return __detail::ldexp_impl(X, Exp);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, N> ldexp(
-    __detail::HLSL_FIXED_VECTOR<half, N> X,
-    __detail::HLSL_FIXED_VECTOR<half, N> Exp) {
-  return __detail::ldexp_impl(X, Exp);
-}
-
-template <int N>
-const inline __detail::HLSL_FIXED_VECTOR<float, N>
-ldexp(__detail::HLSL_FIXED_VECTOR<float, N> X,
-      __detail::HLSL_FIXED_VECTOR<float, N> Exp) {
-  return __detail::ldexp_impl(X, Exp);
-}
-
-//===----------------------------------------------------------------------===//
-// length builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn T length(T x)
-/// \brief Returns the length of the specified floating-point vector.
-/// \param x [in] The vector of floats, or a scalar float.
-///
-/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> length(T X) {
-  return __detail::length_impl(X);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-length(T X) {
-  return __detail::length_impl(X);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline half length(__detail::HLSL_FIXED_VECTOR<half, N> X) {
-  return __detail::length_vec_impl(X);
-}
-
-template <int N>
-const inline float length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
-  return __detail::length_vec_impl(X);
-}
-
-//===----------------------------------------------------------------------===//
-// lit builtins
-//===----------------------------------------------------------------------===//
-
-/// \fn vector<T, 4> lit(T NDotL, T NDotH, T M)
-/// \brief Returns a lighting coefficient vector.
-/// \param NDotL The dot product of the normalized surface normal and the
-/// light vector.
-/// \param NDotH The dot product of the half-angle vector and the surface
-/// normal.
-/// \param M A specular exponent.
-///
-/// This function returns a lighting coefficient vector (ambient, 
diff use,
-/// specular, 1).
-
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline half4 lit(half NDotL, half NDotH, half M) {
-  return __detail::lit_impl(NDotL, NDotH, M);
-}
-
-const inline float4 lit(float NDotL, float NDotH, float M) {
-  return __detail::lit_impl(NDotL, NDotH, M);
-}
-
-//===----------------------------------------------------------------------===//
-// D3DCOLORtoUBYTE4 builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T D3DCOLORtoUBYTE4(T x)
-/// \brief Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.
-/// \param x [in] The floating-point vector4 to convert.
-///
-/// The return value is the UBYTE4 representation of the \a x parameter.
-///
-/// This function swizzles and scales components of the \a x parameter. Use this
-/// function to compensate for the lack of UBYTE4 support in some hardware.
-
-constexpr int4 D3DCOLORtoUBYTE4(float4 V) {
-  return __detail::d3d_color_to_ubyte4_impl(V);
-}
-
-//===----------------------------------------------------------------------===//
-// NonUniformResourceIndex builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn uint NonUniformResourceIndex(uint I)
-/// \brief A compiler hint to indicate that a resource index varies across
-/// threads within a wave (i.e., it is non-uniform).
-/// \param I [in] Resource array index
-///
-/// The return value is the \Index parameter.
-///
-/// When indexing into an array of shader resources (e.g., textures, buffers),
-/// some GPU hardware and drivers require the compiler to know whether the index
-/// is uniform (same for all threads) or non-uniform (varies per thread).
-///
-/// Using NonUniformResourceIndex explicitly marks an index as non-uniform,
-/// disabling certain assumptions or optimizations that could lead to incorrect
-/// behavior when dynamically accessing resource arrays with non-uniform
-/// indices.
-
-constexpr uint32_t NonUniformResourceIndex(uint32_t Index) {
-  return __builtin_hlsl_resource_nonuniformindex(Index);
-}
-
-//===----------------------------------------------------------------------===//
-// reflect builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T reflect(T I, T N)
-/// \brief Returns a reflection using an incident ray, \a I, and a surface
-/// normal, \a N.
-/// \param I The incident ray.
-/// \param N The surface normal.
-///
-/// The return value is a floating-point vector that represents the reflection
-/// of the incident ray, \a I, off a surface with the normal \a N.
-///
-/// This function calculates the reflection vector using the following formula:
-/// V = I - 2 * N * dot(I N) .
-///
-/// N must already be normalized in order to achieve the desired result.
-///
-/// The operands must all be a scalar or vector whose component type is
-/// floating-point.
-///
-/// Result type and the type of all operands must be the same type.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> reflect(T I, T N) {
-  return __detail::reflect_impl(I, N);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-reflect(T I, T N) {
-  return __detail::reflect_impl(I, N);
-}
-
-template <int L>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, L> reflect(
-    __detail::HLSL_FIXED_VECTOR<half, L> I,
-    __detail::HLSL_FIXED_VECTOR<half, L> N) {
-  return __detail::reflect_vec_impl(I, N);
-}
-
-template <int L>
-const inline __detail::HLSL_FIXED_VECTOR<float, L>
-reflect(__detail::HLSL_FIXED_VECTOR<float, L> I,
-        __detail::HLSL_FIXED_VECTOR<float, L> N) {
-  return __detail::reflect_vec_impl(I, N);
-}
-
-//===----------------------------------------------------------------------===//
-// refract builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T refract(T I, T N, T eta)
-/// \brief Returns a refraction using an entering ray, \a I, a surface
-/// normal, \a N and refraction index \a eta
-/// \param I The entering ray.
-/// \param N The surface normal.
-/// \param eta The refraction index.
-///
-/// The return value is a floating-point vector that represents the refraction
-/// using the refraction index, \a eta, for the direction of the entering ray,
-/// \a I, off a surface with the normal \a N.
-///
-/// This function calculates the refraction vector using the following formulas:
-/// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
-/// if k < 0.0 the result is 0.0
-/// otherwise, the result is eta * I - (eta * dot(N, I) + sqrt(k)) * N
-///
-/// I and N must already be normalized in order to achieve the desired result.
-///
-/// I and N must be a scalar or vector whose component type is
-/// floating-point.
-///
-/// eta must be a 16-bit or 32-bit floating-point scalar.
-///
-/// Result type, the type of I, and the type of N must all be the same type.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> refract(T I, T N, T eta) {
-  return __detail::refract_impl(I, N, eta);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-refract(T I, T N, T eta) {
-  return __detail::refract_impl(I, N, eta);
-}
-
-template <int L>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, L> refract(
-    __detail::HLSL_FIXED_VECTOR<half, L> I,
-    __detail::HLSL_FIXED_VECTOR<half, L> N, half eta) {
-  return __detail::refract_impl(I, N, eta);
-}
-
-template <int L>
-const inline __detail::HLSL_FIXED_VECTOR<float, L>
-refract(__detail::HLSL_FIXED_VECTOR<float, L> I,
-        __detail::HLSL_FIXED_VECTOR<float, L> N, float eta) {
-  return __detail::refract_impl(I, N, eta);
-}
-
-//===----------------------------------------------------------------------===//
-// smoothstep builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T smoothstep(T Min, T Max, T X)
-/// \brief Returns a smooth Hermite interpolation between 0 and 1, if \a X is in
-/// the range [\a Min, \a Max].
-/// \param Min The minimum range of the x parameter.
-/// \param Max The maximum range of the x parameter.
-/// \param X The specified value to be interpolated.
-///
-/// The return value is 0.0 if \a X ≤ \a Min and 1.0 if \a X ≥ \a Max. When \a
-/// Min < \a X < \a Max, the function performs smooth Hermite interpolation
-/// between 0 and 1.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> smoothstep(T Min, T Max, T X) {
-  return __detail::smoothstep_impl(Min, Max, X);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-smoothstep(T Min, T Max, T X) {
-  return __detail::smoothstep_impl(Min, Max, X);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, N> smoothstep(
-    __detail::HLSL_FIXED_VECTOR<half, N> Min,
-    __detail::HLSL_FIXED_VECTOR<half, N> Max,
-    __detail::HLSL_FIXED_VECTOR<half, N> X) {
-  return __detail::smoothstep_vec_impl(Min, Max, X);
-}
-
-template <int N>
-const inline __detail::HLSL_FIXED_VECTOR<float, N>
-smoothstep(__detail::HLSL_FIXED_VECTOR<float, N> Min,
-           __detail::HLSL_FIXED_VECTOR<float, N> Max,
-           __detail::HLSL_FIXED_VECTOR<float, N> X) {
-  return __detail::smoothstep_vec_impl(Min, Max, X);
-}
-
-inline bool CheckAccessFullyMapped(uint Status) {
-  return static_cast<bool>(Status);
-}
-
-//===----------------------------------------------------------------------===//
-// ddx builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T ddx(T x)
-/// \brief Computes the sum of the absolute values of the partial derivatives
-/// with regard to the x screen space coordinate.
-/// \param x [in] The floating-point scalar or vector to process.
-///
-/// The return value is a floating-point scalar or vector where each element
-/// holds the computation of the matching element in the input.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> ddx(T input) {
-  return __detail::ddx_impl(input);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-ddx(T input) {
-  return __detail::ddx_impl(input);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, N> ddx(
-    __detail::HLSL_FIXED_VECTOR<half, N> input) {
-  return __detail::ddx_impl(input);
-}
-
-template <int N>
-const inline __detail::HLSL_FIXED_VECTOR<float, N>
-ddx(__detail::HLSL_FIXED_VECTOR<float, N> input) {
-  return __detail::ddx_impl(input);
-}
-
-//===----------------------------------------------------------------------===//
-// ddy builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T ddy(T x)
-/// \brief Computes the sum of the absolute values of the partial derivatives
-/// with regard to the y screen space coordinate.
-/// \param x [in] The floating-point scalar or vector to process.
-///
-/// The return value is a floating-point scalar or vector where each element
-/// holds the computation of the matching element in the input.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> ddy(T input) {
-  return __detail::ddy_impl(input);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-ddy(T input) {
-  return __detail::ddy_impl(input);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, N> ddy(
-    __detail::HLSL_FIXED_VECTOR<half, N> input) {
-  return __detail::ddy_impl(input);
-}
-
-template <int N>
-const inline __detail::HLSL_FIXED_VECTOR<float, N>
-ddy(__detail::HLSL_FIXED_VECTOR<float, N> input) {
-  return __detail::ddy_impl(input);
-}
-
-//===----------------------------------------------------------------------===//
-// fwidth builtin
-//===----------------------------------------------------------------------===//
-
-/// \fn T fwidth(T x)
-/// \brief Computes the sum of the absolute values of the partial derivatives
-/// with regard to the x and y screen space coordinates.
-/// \param x [in] The floating-point scalar or vector to process.
-///
-/// The return value is a floating-point scalar or vector where each element
-/// holds the computation of the matching element in the input.
-
-template <typename T>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   T> fwidth(T input) {
-  return __detail::fwidth_impl(input);
-}
-
-template <typename T>
-const inline __detail::enable_if_t<
-    __detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
-fwidth(T input) {
-  return __detail::fwidth_impl(input);
-}
-
-template <int N>
-_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::HLSL_FIXED_VECTOR<half, N> fwidth(
-    __detail::HLSL_FIXED_VECTOR<half, N> input) {
-  return __detail::fwidth_impl(input);
-}
-
-template <int N>
-const inline __detail::HLSL_FIXED_VECTOR<float, N>
-fwidth(__detail::HLSL_FIXED_VECTOR<float, N> input) {
-  return __detail::fwidth_impl(input);
-}
-
 //===----------------------------------------------------------------------===//
 // mul builtins
 //===----------------------------------------------------------------------===//

diff  --git a/clang/test/CodeGenHLSL/builtins/dst.hlsl b/clang/test/CodeGenHLSL/builtins/dst.hlsl
index d8292d31fba7c..681eb65fb7a48 100644
--- a/clang/test/CodeGenHLSL/builtins/dst.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/dst.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.2-library %s -fnative-half-type -fnative-int16-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
 
-// CHECK-LABEL: define {{.*}} <4 x float> @{{[A-Za-z1-9_]+}}dst_impl{{[A-Za-z1-9_]*}}(
-// CHECK-SAME: <4 x float> {{[A-Za-z )(]*}} [[P:%.*]], <4 x float> {{[A-Za-z )(]*}} [[Q:%.*]]) #[[ATTR0:[0-9]+]] { 
+// CHECK-LABEL: define {{.*}} <4 x float> @{{[A-Za-z1-9_]+}}dstWithFloat{{[A-Za-z1-9_]*}}(
+// CHECK-SAME: <4 x float> {{[A-Za-z )(]*}} [[P:%.*]], <4 x float> {{[A-Za-z )(]*}} [[Q:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK: [[VECEXT:%.*]] = extractelement <4 x float> [[PADDR:%.*]], i32 1
 // CHECK: [[VECEXT1:%.*]] = extractelement <4 x float> [[QADDR:%.*]], i32 1
 // CHECK: [[MULRES:%.*]] = fmul {{[A-Za-z ]*}} float [[VECEXT]], [[VECEXT1]]
@@ -17,7 +17,7 @@ float4 dstWithFloat(float4 p1, float4 p2)
     return dst(p1, p2);
 }
 
-// CHECK-LABEL: define {{.*}} <4 x half> @{{[A-Za-z1-9_]+}}dst_impl{{[A-Za-z1-9_]*}}(
+// CHECK-LABEL: define {{.*}} <4 x half> @{{[A-Za-z1-9_]+}}dstwithHalf{{[A-Za-z1-9_]*}}(
 // CHECK-SAME: <4 x half> {{[A-Za-z )(]*}} [[P:%.*]], <4 x half> {{[A-Za-z )(]*}} [[Q:%.*]]) #[[ATTR0]] {
 // CHECK: [[VECEXT:%.*]] = extractelement <4 x half> [[PADDR:%.*]], i32 1
 // CHECK: [[VECEXT1:%.*]] = extractelement <4 x half> [[QADDR:%.*]], i32 1
@@ -33,8 +33,8 @@ half4 dstwithHalf(half4 p1, half4 p2)
     return dst(p1, p2);
 }
 
-// CHECK-LABEL: define {{.*}} <4 x double> @{{[A-Za-z1-9_]+}}dst_impl{{[A-Za-z1-9_]*}}(
-// CHECK-SAME: <4 x double> {{[A-Za-z )(]*}} [[P:%.*]], <4 x double> {{[A-Za-z )(]*}} [[Q:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-LABEL: define {{.*}} <4 x double> @{{[A-Za-z1-9_]+}}dstWithDouble{{[A-Za-z1-9_]*}}(
+// CHECK-SAME: <4 x double> {{[A-Za-z )(]*}} [[P:%.*]], <4 x double> {{[A-Za-z )(]*}} [[Q:%.*]]) #[[ATTR0]] {
 // CHECK: [[VECEXT:%.*]] = extractelement <4 x double> [[PADDR:%.*]], i32 1
 // CHECK: [[VECEXT1:%.*]] = extractelement <4 x double> [[QADDR:%.*]], i32 1
 // CHECK: [[MULRES:%.*]] = fmul {{[A-Za-z ]*}} double [[VECEXT]], [[VECEXT1]]
@@ -48,4 +48,3 @@ double4 dstWithDouble(double4 p1, double4 p2)
 {
     return dst(p1, p2);
 }
-

diff  --git a/clang/test/CodeGenHLSL/builtins/ldexp.hlsl b/clang/test/CodeGenHLSL/builtins/ldexp.hlsl
index 2dec126788956..2c0458d079027 100644
--- a/clang/test/CodeGenHLSL/builtins/ldexp.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/ldexp.hlsl
@@ -1,49 +1,49 @@
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) half @_ZN4hlsl8__detail10ldexp_implIDhEET_S2_S2_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) half @_ZN4hlsl5ldexpEDhDh
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.exp2.f16(half %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn half [[EXP2]], %{{.*}}
-// CHECK: ret half %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn half [[EXP2]], %{{.*}}
+// CHECK: ret half [[MUL]]
 half test_ldexp_half(half X, half Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <2 x half> @_ZN4hlsl8__detail10ldexp_implIDv2_DhEET_S3_S3_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <2 x half> @_ZN4hlsl5ldexpEDv2_DhS0_
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.exp2.v2f16(<2 x half> %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn <2 x half> [[EXP2]], %{{.*}}
-// CHECK: ret <2 x half> %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x half> [[EXP2]], %{{.*}}
+// CHECK: ret <2 x half> [[MUL]]
 half2 test_ldexp_half2(half2 X, half2 Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <3 x half> @_ZN4hlsl8__detail10ldexp_implIDv3_DhEET_S3_S3_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <3 x half> @_ZN4hlsl5ldexpEDv3_DhS0_
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.exp2.v3f16(<3 x half> %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn <3 x half> [[EXP2]], %{{.*}}
-// CHECK: ret <3 x half> %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x half> [[EXP2]], %{{.*}}
+// CHECK: ret <3 x half> [[MUL]]
 half3 test_ldexp_half3(half3 X, half3 Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <4 x half> @_ZN4hlsl8__detail10ldexp_implIDv4_DhEET_S3_S3_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <4 x half> @_ZN4hlsl5ldexpEDv4_DhS0_
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.exp2.v4f16(<4 x half> %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn <4 x half> [[EXP2]], %{{.*}}
-// CHECK: ret <4 x half> %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x half> [[EXP2]], %{{.*}}
+// CHECK: ret <4 x half> [[MUL]]
 half4 test_ldexp_half4(half4 X, half4 Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) float @_ZN4hlsl8__detail10ldexp_implIfEET_S2_S2_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) float @_ZN4hlsl5ldexpEff
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn float @llvm.exp2.f32(float %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn float [[EXP2]], %{{.*}}
-// CHECK: ret float %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float [[EXP2]], %{{.*}}
+// CHECK: ret float [[MUL]]
 float test_ldexp_float(float X, float Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <2 x float> @_ZN4hlsl8__detail10ldexp_implIDv2_fEET_S3_S3_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <2 x float> @_ZN4hlsl5ldexpEDv2_fS0_
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.exp2.v2f32(<2 x float> %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn <2 x float> [[EXP2]], %{{.*}}
-// CHECK: ret <2 x float> %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> [[EXP2]], %{{.*}}
+// CHECK: ret <2 x float> [[MUL]]
 float2 test_ldexp_float2(float2 X, float2 Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <3 x float> @_ZN4hlsl8__detail10ldexp_implIDv3_fEET_S3_S3_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <3 x float> @_ZN4hlsl5ldexpEDv3_fS0_
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.exp2.v3f32(<3 x float> %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn <3 x float> [[EXP2]], %{{.*}}
-// CHECK: ret <3 x float> %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> [[EXP2]], %{{.*}}
+// CHECK: ret <3 x float> [[MUL]]
 float3 test_ldexp_float3(float3 X, float3 Exp) { return ldexp(X, Exp); }
 
-// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl8__detail10ldexp_implIDv4_fEET_S3_S3_
+// CHECK-LABEL: define linkonce_odr hidden noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl5ldexpEDv4_fS0_
 // CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.exp2.v4f32(<4 x float> %{{.*}})
-// CHECK: %mul = fmul reassoc nnan ninf nsz arcp afn <4 x float> [[EXP2]], %{{.*}}
-// CHECK: ret <4 x float> %mul
+// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> [[EXP2]], %{{.*}}
+// CHECK: ret <4 x float> [[MUL]]
 float4 test_ldexp_float4(float4 X, float4 Exp) { return ldexp(X, Exp); }

diff  --git a/clang/test/CodeGenHLSL/resources/NonUniformResourceIndex.hlsl b/clang/test/CodeGenHLSL/resources/NonUniformResourceIndex.hlsl
index ab512ce111d19..b2712561dceaf 100644
--- a/clang/test/CodeGenHLSL/resources/NonUniformResourceIndex.hlsl
+++ b/clang/test/CodeGenHLSL/resources/NonUniformResourceIndex.hlsl
@@ -1,28 +1,28 @@
 // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-compute -emit-llvm -disable-llvm-passes -o - %s \
-// RUN:   | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,DXIL
+// RUN:   | llvm-cxxfilt | FileCheck -DTARGET=dx %s
 // RUN: %clang_cc1 -finclude-default-header -triple spirv-pc-vulkan1.3-compute -emit-llvm -disable-llvm-passes -o - %s \
-// RUN:   | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,SPV
+// RUN:   | llvm-cxxfilt | FileCheck -DTARGET=spv %s
 
 RWBuffer<float> A[10];
 
 [numthreads(4,1,1)]
 void main(uint GI : SV_GroupID) {
   // CHECK: %[[GI:.*]] = load i32, ptr %GI.addr
-  // CHECK: %[[NURI_1:.*]] = call {{.*}} i32 @hlsl::NonUniformResourceIndex(unsigned int)(i32 noundef %[[GI]])
+  // CHECK: %[[NURI_1:.*]] = call i32 @llvm.[[TARGET]].resource.nonuniformindex(i32 %[[GI]])
   // CHECK: call void @hlsl::RWBuffer<float>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*)
   // CHECK-SAME: (ptr {{.*}}, i32 noundef 0, i32 noundef 0, i32 noundef 10, i32 noundef %[[NURI_1]], ptr noundef @A.str)
   float a = A[NonUniformResourceIndex(GI)][0];
 
   // CHECK: %[[GI:.*]] = load i32, ptr %GI.addr
   // CHECK: %[[ADD:.*]] = add i32 %[[GI]], 1
-  // CHECK: %[[NURI_2:.*]] = call {{.*}} i32 @hlsl::NonUniformResourceIndex(unsigned int)(i32 noundef %[[ADD]])
+  // CHECK: %[[NURI_2:.*]] = call i32 @llvm.[[TARGET]].resource.nonuniformindex(i32 %[[ADD]])
   // CHECK: %[[MOD:.*]] = urem i32 %[[NURI_2]], 10
   // CHECK: call void @hlsl::RWBuffer<float>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*)
   // CHECK-SAME: (ptr {{.*}}, i32 noundef 0, i32 noundef 0, i32 noundef 10, i32 noundef %[[MOD]], ptr noundef @A.str)
   float b = A[NonUniformResourceIndex(GI + 1) % 10][0];
 
   // CHECK: %[[GI:.*]] = load i32, ptr %GI.addr
-  // CHECK: %[[NURI_3:.*]] = call {{.*}} i32 @hlsl::NonUniformResourceIndex(unsigned int)(i32 noundef %[[GI]])
+  // CHECK: %[[NURI_3:.*]] = call i32 @llvm.[[TARGET]].resource.nonuniformindex(i32 %[[GI]])
   // CHECK: %[[MUL:.*]] = mul i32 3, %[[NURI_3]]
   // CHECK: %[[ADD2:.*]] = add i32 10, %[[MUL]]
   // CHECK: call void @hlsl::RWBuffer<float>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*)
@@ -30,9 +30,3 @@ void main(uint GI : SV_GroupID) {
   float c = A[10 + 3 * NonUniformResourceIndex(GI)][0];
   A[0][0] = a + b + c;
 }
-
-// CHECK: define {{.*}} i32 @hlsl::NonUniformResourceIndex(unsigned int)(i32 noundef %Index)
-// CHECK: %[[INDEX1:.*]] = load i32, ptr %Index.addr, align 4
-// DXIL: %[[INDEX2:.*]] = call i32 @llvm.dx.resource.nonuniformindex(i32 %[[INDEX1]])
-// SPV: %[[INDEX2:.*]] = call i32 @llvm.spv.resource.nonuniformindex(i32 %[[INDEX1]])
-// CHECK: ret i32 %[[INDEX2]]

diff  --git a/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
index e9bf4c91bd140..a970885b9821d 100644
--- a/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl
@@ -3,19 +3,19 @@
 int4 test_too_few_arg() {
   return D3DCOLORtoUBYTE4();
   // expected-error at -1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires single argument 'V', but no arguments were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* {{candidate function not viable: requires single argument 'V', but no arguments were provided}}
 }
 
 int4 test_too_many_arg(float4 v) {
   return D3DCOLORtoUBYTE4(v, v);
   // expected-error at -1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires single argument 'V', but 2 arguments were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* {{candidate function not viable: requires single argument 'V', but 2 arguments were provided}}
 }
 
 int4 float2_arg(float2 v) {
     return D3DCOLORtoUBYTE4(v);
     // expected-error at -1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
-    // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'vector<[...], 2>' to 'vector<[...], 4>' for 1st argument}}
+    // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* {{candidate function not viable: no known conversion from 'vector<[...], 2>' to 'vector<[...], 4>' for 1st argument}}
 }
 
 struct S {
@@ -25,5 +25,5 @@ struct S {
 int4 struct_arg(S v) {
     return D3DCOLORtoUBYTE4(v);
     // expected-error at -1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
-    // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'S' to 'float4' (aka 'vector<float, 4>') for 1st argument}}
+    // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* {{candidate function not viable: no known conversion from 'S' to 'float4' (aka 'vector<float, 4>') for 1st argument}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
index 4ec1bcef2b6fc..cbd4456a39905 100644
--- a/clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/distance-errors.hlsl
@@ -3,55 +3,36 @@
 float test_no_second_arg(float2 p0) {
   return distance(p0);
   // expected-error at -1 {{no matching function for call to 'distance'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
 }
 
 float test_too_many_arg(float2 p0) {
   return distance(p0, p0, p0);
   // expected-error at -1 {{no matching function for call to 'distance'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 3 were provided}}
 }
 
 float test_double_inputs(double p0, double p1) {
   return distance(p0, p1);
-  // expected-error at -1 {{no matching function for call to 'distance'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1 {{call to 'distance' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1) {
   return distance(p0, p1);
-  // expected-error at -1 {{no matching function for call to 'distance'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1 {{call to 'distance' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1) {
   return distance(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'distance'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 2 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0, float5 p1) {
   return distance(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'distance'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'distance' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/dot2add-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/dot2add-errors.hlsl
index 84333ba08b9b8..e576f73669002 100644
--- a/clang/test/SemaHLSL/BuiltIns/dot2add-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/dot2add-errors.hlsl
@@ -3,11 +3,11 @@
 float test_too_few_arg() {
   return dot2add();
   // expected-error at -1 {{no matching function for call to 'dot2add'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 3 arguments, but 0 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* {{candidate function not viable: requires 3 arguments, but 0 were provided}}
 }
 
 float test_too_many_arg(half2 p1, half2 p2, float p3) {
   return dot2add(p1, p2, p3, p1);
   // expected-error at -1 {{no matching function for call to 'dot2add'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl
index 01261a00295b1..658d1d3426c10 100644
--- a/clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl
@@ -2,38 +2,25 @@
 
 float test_double_inputs(double p0, double p1, double p2) {
   return faceforward(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'faceforward'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'faceforward' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1, int p2) {
   return faceforward(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'faceforward'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'faceforward' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
   return faceforward(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'faceforward'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 3 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0, float5 p1, float5 p2) {
   return faceforward(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'faceforward'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'faceforward' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl
index eceac9be8d7d1..5985105138e81 100644
--- a/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl
@@ -3,55 +3,36 @@
 float test_no_second_arg(float2 p0) {
   return fmod(p0);
   // expected-error at -1 {{no matching function for call to 'fmod'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
 }
 
 float test_too_many_arg(float2 p0) {
   return fmod(p0, p0, p0);
   // expected-error at -1 {{no matching function for call to 'fmod'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 3 were provided}}
 }
 
 float test_double_inputs(double p0, double p1) {
   return fmod(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'fmod'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'fmod' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1) {
   return fmod(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'fmod'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'fmod' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1) {
   return fmod(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'fmod'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 2 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0, float5 p1) {
   return fmod(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'fmod'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'fmod' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl
index fa146a5bce525..ce15550d7884b 100644
--- a/clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl
@@ -2,38 +2,25 @@
 
 float test_double_inputs(double p0, double p1) {
   return ldexp(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'ldexp'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'ldexp' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1, int p2) {
   return ldexp(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'ldexp'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'ldexp' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1) {
   return ldexp(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'ldexp'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 2 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0, float5 p1) {
   return ldexp(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'ldexp'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'ldexp' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
index 8c5c9a4a0d22a..e408e64c0dd4c 100644
--- a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
@@ -4,78 +4,53 @@ void test_too_few_arg()
 {
   return length();
   // expected-error at -1 {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but no arguments were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but no arguments were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but no arguments were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but no arguments were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires single argument 'X', but no arguments were provided}}
 }
 
 void test_too_many_arg(float2 p0)
 {
   return length(p0, p0);
   // expected-error at -1 {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but 2 arguments were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but 2 arguments were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but 2 arguments were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but 2 arguments were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires single argument 'X', but 2 arguments were provided}}
 }
 
 float double_to_float_type(double p0) {
   return length(p0);
-  // expected-error at -1  {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = double]: no type named 'Type' in 'hlsl::__detail::enable_if<false, double>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = double]: no type named 'Type' in 'hlsl::__detail::enable_if<false, double>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: could not match '__detail::HLSL_FIXED_VECTOR<half, N>' (aka 'vector<__detail::enable_if_t<(N > 1 && N <= 4), half>, N>') against 'double'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: could not match '__detail::HLSL_FIXED_VECTOR<float, N>' (aka 'vector<__detail::enable_if_t<(N > 1 && N <= 4), float>, N>') against 'double'}}
+  // expected-error at -1  {{call to 'length' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 
 float bool_to_float_type_promotion(bool p1)
 {
   return length(p1);
-  // expected-error at -1  {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{andidate template ignored: substitution failure [with T = bool]: no type named 'Type' in 'hlsl::__detail::enable_if<false, bool>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{andidate template ignored: substitution failure [with T = bool]: no type named 'Type' in 'hlsl::__detail::enable_if<false, bool>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: could not match '__detail::HLSL_FIXED_VECTOR<half, N>' (aka 'vector<__detail::enable_if_t<(N > 1 && N <= 4), half>, N>') against 'bool'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: could not match '__detail::HLSL_FIXED_VECTOR<float, N>' (aka 'vector<__detail::enable_if_t<(N > 1 && N <= 4), float>, N>') against 'bool'}}
+  // expected-error at -1  {{call to 'length' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float length_int_to_float_promotion(int p1)
 {
   return length(p1);
-  // expected-error at -1  {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = int]: no type named 'Type' in 'hlsl::__detail::enable_if<false, int>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = int]: no type named 'Type' in 'hlsl::__detail::enable_if<false, int>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: could not match '__detail::HLSL_FIXED_VECTOR<half, N>' (aka 'vector<__detail::enable_if_t<(N > 1 && N <= 4), half>, N>') against 'int'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: could not match '__detail::HLSL_FIXED_VECTOR<float, N>' (aka 'vector<__detail::enable_if_t<(N > 1 && N <= 4), float>, N>') against 'int'}}
+  // expected-error at -1  {{call to 'length' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float2 length_int2_to_float2_promotion(int2 p1)
 {
   return length(p1);
-  // expected-error at -1  {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = int2]}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = int2]}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{1st parameter does not match adjusted type 'vector<int, [...]>' of argument [with N = 2]}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{1st parameter does not match adjusted type 'vector<int, [...]>' of argument [with N = 2]}}
+  // expected-error at -1  {{call to 'length' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0) {
   return length(p0);
-  // expected-error at -1  {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0) {
   return length(p0);
-  // expected-error at -1  {{no matching function for call to 'length'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'length' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
index b0ae770f49f20..a60e4c403811c 100644
--- a/clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/reflect-errors.hlsl
@@ -3,55 +3,36 @@
 float test_no_second_arg(float2 p0) {
   return reflect(p0);
   // expected-error at -1 {{no matching function for call to 'reflect'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
 }
 
 float test_too_many_arg(float2 p0) {
   return reflect(p0, p0, p0);
   // expected-error at -1 {{no matching function for call to 'reflect'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 2 arguments, but 3 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 3 were provided}}
 }
 
 float test_double_inputs(double p0, double p1) {
   return reflect(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'reflect'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'reflect' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1) {
   return reflect(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'reflect'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'reflect' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1) {
   return reflect(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'reflect'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 2 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0, float5 p1) {
   return reflect(p0, p1);
-  // expected-error at -1  {{no matching function for call to 'reflect'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'reflect' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl
index fce41a4a46d38..8d9949f52aeb0 100644
--- a/clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl
@@ -3,64 +3,56 @@
 float test_no_second_arg(float3 p0) {
   return refract(p0);
   // expected-error at -1 {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 1 was provided}}
 }
 
 float test_no_third_arg(float3 p0) {
   return refract(p0, p0);
   // expected-error at -1 {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 2 were provided}}
 }
 
 float test_too_many_arg(float2 p0) {
   return refract(p0, p0, p0, p0);
   // expected-error at -1 {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 4 were provided}}
 }
 
 float test_double_inputs(double p0, double p1, double p2) {
   return refract(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'refract' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1, int p2) {
   return refract(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'refract' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
   return refract(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
+  // expected-warning at -2 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
+  // expected-warning at -3 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
-float5 test_vec5_inputs(float5 p0, float5 p1,  float p2) {
+float5 test_vec5_inputs(float5 p0, float5 p1, float p2) {
   return refract(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'refract'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: deduced conflicting types for parameter 'T' ('float5' (vector of 5 'float' values) vs. 'float')}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: deduced conflicting types for parameter 'T' ('float5' (vector of 5 'float' values) vs. 'float')}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with L = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'refract' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
+}
+
+half3 test_half_inputs_with_float(half3 p0, half3 p1, float p3) {
+  return refract(p0, p1, p3);
+  // expected-error at -1  {{call to 'refract' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 6 {{candidate function}}
+}
+
+half3 test_half_inputs_with_float_literal(half3 p0, half3 p1) {
+  return refract(p0, p1, 0.5);
+  // expected-error at -1  {{call to 'refract' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 6 {{candidate function}}
 }

diff  --git a/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl
index 4c6bea8f02411..2c56bd98035a1 100644
--- a/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl
@@ -3,64 +3,42 @@
 float test_no_second_arg(float2 p0) {
   return smoothstep(p0);
   // expected-error at -1 {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 1 was provided}}
 }
 
 float test_no_third_arg(float2 p0) {
   return smoothstep(p0, p0);
   // expected-error at -1 {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 2 were provided}}
 }
 
 float test_too_many_arg(float2 p0) {
   return smoothstep(p0, p0, p0, p0);
   // expected-error at -1 {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 4 were provided}}
 }
 
 float test_double_inputs(double p0, double p1, double p2) {
   return smoothstep(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'smoothstep' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float test_int_inputs(int p0, int p1, int p2) {
   return smoothstep(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored}}
+  // expected-error at -1  {{call to 'smoothstep' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function}}
 }
 
 float1 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
   return smoothstep(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 1>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 1]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-warning at -1 3 {{implicit conversion turns vector to scalar: 'float1' (aka 'vector<float, 1>') to 'float'}}
 }
 
 typedef float float5 __attribute__((ext_vector_type(5)));
 
 float5 test_vec5_inputs(float5 p0, float5 p1, float5 p2) {
   return smoothstep(p0, p1, p2);
-  // expected-error at -1  {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<float, 5>>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, half>'}}
-  // expected-note at hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with N = 5]: no type named 'Type' in 'hlsl::__detail::enable_if<false, float>'}}
+  // expected-error at -1  {{call to 'smoothstep' is ambiguous}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 4 {{candidate function}}
 }


        


More information about the cfe-commits mailing list