https://github.com/kmpeng updated 
https://github.com/llvm/llvm-project/pull/134171

>From d87804880ceee63329761178e780bd301b3e50f6 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Thu, 27 Mar 2025 14:39:27 -0700
Subject: [PATCH 01/12] finished lit implementation, added codegen and sema
 tests

---
 .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 12 +++++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h      | 31 ++++++++++++
 clang/test/CodeGenHLSL/builtins/lit.hlsl      | 36 +++++++++++++
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  | 50 +++++++++++++++++++
 4 files changed, 129 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/lit.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index a8f025b1b5f5f..e05017f5f69c2 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -109,6 +109,18 @@ constexpr vector<T, N> smoothstep_vec_impl(vector<T, N> 
Min, vector<T, N> Max,
 #endif
 }
 
+template <typename T>
+constexpr vector<T, 4> lit_impl(T N_dot_l, T N_dot_h, T M) {
+  bool Cond1 = N_dot_l < 0;
+  T ClampedP1 = select<T>(Cond1, 0, N_dot_l);
+  vector<T, 4> Result = {1, ClampedP1, 0, 1};
+  bool CombinedCond = or (Cond1, (N_dot_h < 0));
+  T LogP2 = log(N_dot_h);
+  T Exp = exp(LogP2 * M);
+  Result[2] = select<T>(CombinedCond, 0, Exp);
+  return Result;
+}
+
 } // namespace __detail
 } // namespace hlsl
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 1a61fdba4fc19..6f8f2e4fbf475 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -268,6 +268,37 @@ 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 x, T y)
+/// \brief Returns a lighting coefficient vector.
+/// \param N_dot_l The dot product of the normalized surface normal and the
+/// light vector.
+/// \param N_dot_h 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, diffuse,
+/// specular, 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,
+                                 vector<T, 4>> lit(T N_dot_l, T N_dot_h, T M) {
+  return __detail::lit_impl(N_dot_l, N_dot_h, M);
+}
+
+template <typename T>
+const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
+                                       __detail::is_same<float, T>::value,
+                                   vector<T, 4>>
+lit(T N_dot_l, T N_dot_h, T M) {
+  return __detail::lit_impl(N_dot_l, N_dot_h, M);
+}
+
 
//===----------------------------------------------------------------------===//
 // D3DCOLORtoUBYTE4 builtin
 
//===----------------------------------------------------------------------===//
diff --git a/clang/test/CodeGenHLSL/builtins/lit.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit.hlsl
new file mode 100644
index 0000000000000..3fb0a2c5b5d6f
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/lit.hlsl
@@ -0,0 +1,36 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x half> 
@_Z13test_lit_halfDhDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[N_DOT_L:%.*]], half noundef 
nofpclass(nan inf) [[N_DOT_H:%.*]], half noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt half 
[[N_DOT_L]], 0xH0000
+// CHECK-NEXT:    [[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn half @llvm.maxnum.f16(half [[N_DOT_L]], half 0xH0000)
+// CHECK-NEXT:    [[VECINIT2_I:%.*]] = insertelement <4 x half> <half 0xH3C00, 
half poison, half poison, half 0xH3C00>, half [[HLSL_SELECT_I]], i64 1
+// CHECK-NEXT:    [[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
half [[N_DOT_H]], 0xH0000
+// CHECK-NEXT:    [[HLSL_OR_I:%.*]] = or i1 [[CMP_I]], [[CMP4_I]]
+// CHECK-NEXT:    [[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.log.f16(half [[N_DOT_H]])
+// CHECK-NEXT:    [[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[ELT_LOG_I]], [[M]]
+// CHECK-NEXT:    [[ELT_EXP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.exp.f16(half [[MUL_I]])
+// CHECK-NEXT:    [[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], half 0xH0000, half [[ELT_EXP_I]]
+// CHECK-NEXT:    [[VECINS_I:%.*]] = insertelement <4 x half> [[VECINIT2_I]], 
half [[HLSL_SELECT7_I]], i64 2
+// CHECK-NEXT:    ret <4 x half> [[VECINS_I]]
+//
+half4 test_lit_half(half N_dot_l, half N_dot_h, half M) { return lit(N_dot_l, 
N_dot_h, M); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x float> 
@_Z14test_lit_floatfff(
+// CHECK-SAME: float noundef nofpclass(nan inf) [[N_DOT_L:%.*]], float noundef 
nofpclass(nan inf) [[N_DOT_H:%.*]], float noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[N_DOT_L]], 0.000000e+00
+// CHECK-NEXT:    [[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn float @llvm.maxnum.f32(float [[N_DOT_L]], float 0.000000e+00)
+// CHECK-NEXT:    [[VECINIT2_I:%.*]] = insertelement <4 x float> <float 
1.000000e+00, float poison, float poison, float 1.000000e+00>, float 
[[HLSL_SELECT_I]], i64 1
+// CHECK-NEXT:    [[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[N_DOT_H]], 0.000000e+00
+// CHECK-NEXT:    [[HLSL_OR_I:%.*]] = or i1 [[CMP_I]], [[CMP4_I]]
+// CHECK-NEXT:    [[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
float @llvm.log.f32(float [[N_DOT_H]])
+// CHECK-NEXT:    [[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn float 
[[ELT_LOG_I]], [[M]]
+// CHECK-NEXT:    [[ELT_EXP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
float @llvm.exp.f32(float [[MUL_I]])
+// CHECK-NEXT:    [[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], float 0.000000e+00, float [[ELT_EXP_I]]
+// CHECK-NEXT:    [[VECINS_I:%.*]] = insertelement <4 x float> [[VECINIT2_I]], 
float [[HLSL_SELECT7_I]], i64 2
+// CHECK-NEXT:    ret <4 x float> [[VECINS_I]]
+//
+float4 test_lit_float(float N_dot_l, float N_dot_h, float M) { return 
lit(N_dot_l, N_dot_h, M); }
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
new file mode 100644
index 0000000000000..33fb33ca3204d
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+float4 test_no_second_arg(float p0) {
+  return lit(p0);
+  // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
+}
+
+float4 test_no_third_arg(float p0) {
+  return lit(p0, p0);
+  // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
+}
+
+float4 test_too_many_arg(float p0) {
+  return lit(p0, p0, p0, p0);
+  // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
+}
+
+float4 test_double_inputs(double p0, double p1, double p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1  {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = double]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<double, 4>>'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = double]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<double, 4>>'}}
+}
+
+float4 test_int_inputs(int p0, int p1, int p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1  {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = int]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<int, 4>>'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = int]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<int, 4>>'}}
+}
+
+float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1  {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+}
+
+float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1  {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+}
\ No newline at end of file

>From 282dd496cadd69a1881b955a645bbdd707d07080 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Mon, 31 Mar 2025 12:39:39 -0700
Subject: [PATCH 02/12] rename variables

---
 .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 16 ++++++-------
 clang/lib/Headers/hlsl/hlsl_intrinsics.h      | 16 ++++++-------
 clang/test/CodeGenHLSL/builtins/lit.hlsl      | 24 +++++++++----------
 3 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index e05017f5f69c2..ae53e1309a404 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -109,15 +109,13 @@ constexpr vector<T, N> smoothstep_vec_impl(vector<T, N> 
Min, vector<T, N> Max,
 #endif
 }
 
-template <typename T>
-constexpr vector<T, 4> lit_impl(T N_dot_l, T N_dot_h, T M) {
-  bool Cond1 = N_dot_l < 0;
-  T ClampedP1 = select<T>(Cond1, 0, N_dot_l);
-  vector<T, 4> Result = {1, ClampedP1, 0, 1};
-  bool CombinedCond = or (Cond1, (N_dot_h < 0));
-  T LogP2 = log(N_dot_h);
-  T Exp = exp(LogP2 * M);
-  Result[2] = select<T>(CombinedCond, 0, Exp);
+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);
+  vector<T, 4> Result = {1, Diffuse, 0, 1};
+  bool SpecularCond = or (DiffuseCond, (NDotH < 0));
+  T SpecularExp = exp(log(NDotH) * M);
+  Result[2] = select<T>(SpecularCond, 0, SpecularExp);
   return Result;
 }
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 6f8f2e4fbf475..c59ca0b10c81a 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -272,11 +272,11 @@ const inline float 
length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
 // lit builtins
 
//===----------------------------------------------------------------------===//
 
-/// \fn vector<T, 4> lit(T x, T y)
+/// \fn vector<T, 4> lit(T NDotL, T NDotH, T M)
 /// \brief Returns a lighting coefficient vector.
-/// \param N_dot_l The dot product of the normalized surface normal and the
+/// \param NDotL The dot product of the normalized surface normal and the
 /// light vector.
-/// \param N_dot_h The dot product of the half-angle vector and the surface
+/// \param NDotH The dot product of the half-angle vector and the surface
 /// normal.
 /// \param M A specular exponent.
 ///
@@ -286,17 +286,17 @@ const inline float 
length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
 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,
-                                 vector<T, 4>> lit(T N_dot_l, T N_dot_h, T M) {
-  return __detail::lit_impl(N_dot_l, N_dot_h, M);
+                                       __detail::is_same<half, T>::value,
+                                   vector<T, 4>> lit(T NDotL, T NDotH, T M) {
+  return __detail::lit_impl(NDotL, NDotH, M);
 }
 
 template <typename T>
 const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
                                        __detail::is_same<float, T>::value,
                                    vector<T, 4>>
-lit(T N_dot_l, T N_dot_h, T M) {
-  return __detail::lit_impl(N_dot_l, N_dot_h, M);
+lit(T NDotL, T NDotH, T M) {
+  return __detail::lit_impl(NDotL, NDotH, M);
 }
 
 
//===----------------------------------------------------------------------===//
diff --git a/clang/test/CodeGenHLSL/builtins/lit.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit.hlsl
index 3fb0a2c5b5d6f..484a85779a375 100644
--- a/clang/test/CodeGenHLSL/builtins/lit.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit.hlsl
@@ -2,35 +2,35 @@
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
 
 // CHECK-LABEL: define noundef nofpclass(nan inf) <4 x half> 
@_Z13test_lit_halfDhDhDh(
-// CHECK-SAME: half noundef nofpclass(nan inf) [[N_DOT_L:%.*]], half noundef 
nofpclass(nan inf) [[N_DOT_H:%.*]], half noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-SAME: half noundef nofpclass(nan inf) [[NDOTL:%.*]], half noundef 
nofpclass(nan inf) [[NDOTH:%.*]], half noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt half 
[[N_DOT_L]], 0xH0000
-// CHECK-NEXT:    [[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn half @llvm.maxnum.f16(half [[N_DOT_L]], half 0xH0000)
+// CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt half 
[[NDOTL]], 0xH0000
+// CHECK-NEXT:    [[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn half @llvm.maxnum.f16(half [[NDOTL]], half 0xH0000)
 // CHECK-NEXT:    [[VECINIT2_I:%.*]] = insertelement <4 x half> <half 0xH3C00, 
half poison, half poison, half 0xH3C00>, half [[HLSL_SELECT_I]], i64 1
-// CHECK-NEXT:    [[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
half [[N_DOT_H]], 0xH0000
+// CHECK-NEXT:    [[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
half [[NDOTH]], 0xH0000
 // CHECK-NEXT:    [[HLSL_OR_I:%.*]] = or i1 [[CMP_I]], [[CMP4_I]]
-// CHECK-NEXT:    [[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.log.f16(half [[N_DOT_H]])
+// CHECK-NEXT:    [[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.log.f16(half [[NDOTH]])
 // CHECK-NEXT:    [[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[ELT_LOG_I]], [[M]]
 // CHECK-NEXT:    [[ELT_EXP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
half @llvm.exp.f16(half [[MUL_I]])
 // CHECK-NEXT:    [[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], half 0xH0000, half [[ELT_EXP_I]]
 // CHECK-NEXT:    [[VECINS_I:%.*]] = insertelement <4 x half> [[VECINIT2_I]], 
half [[HLSL_SELECT7_I]], i64 2
 // CHECK-NEXT:    ret <4 x half> [[VECINS_I]]
 //
-half4 test_lit_half(half N_dot_l, half N_dot_h, half M) { return lit(N_dot_l, 
N_dot_h, M); }
+half4 test_lit_half(half NDotL, half NDotH, half M) { return lit(NDotL, NDotH, 
M); }
 
 // CHECK-LABEL: define noundef nofpclass(nan inf) <4 x float> 
@_Z14test_lit_floatfff(
-// CHECK-SAME: float noundef nofpclass(nan inf) [[N_DOT_L:%.*]], float noundef 
nofpclass(nan inf) [[N_DOT_H:%.*]], float noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-SAME: float noundef nofpclass(nan inf) [[NDOTL:%.*]], float noundef 
nofpclass(nan inf) [[NDOTH:%.*]], float noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[N_DOT_L]], 0.000000e+00
-// CHECK-NEXT:    [[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn float @llvm.maxnum.f32(float [[N_DOT_L]], float 0.000000e+00)
+// CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[NDOTL]], 0.000000e+00
+// CHECK-NEXT:    [[HLSL_SELECT_I:%.*]] = tail call reassoc nnan ninf nsz arcp 
afn float @llvm.maxnum.f32(float [[NDOTL]], float 0.000000e+00)
 // CHECK-NEXT:    [[VECINIT2_I:%.*]] = insertelement <4 x float> <float 
1.000000e+00, float poison, float poison, float 1.000000e+00>, float 
[[HLSL_SELECT_I]], i64 1
-// CHECK-NEXT:    [[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[N_DOT_H]], 0.000000e+00
+// CHECK-NEXT:    [[CMP4_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[NDOTH]], 0.000000e+00
 // CHECK-NEXT:    [[HLSL_OR_I:%.*]] = or i1 [[CMP_I]], [[CMP4_I]]
-// CHECK-NEXT:    [[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
float @llvm.log.f32(float [[N_DOT_H]])
+// CHECK-NEXT:    [[ELT_LOG_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
float @llvm.log.f32(float [[NDOTH]])
 // CHECK-NEXT:    [[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn float 
[[ELT_LOG_I]], [[M]]
 // CHECK-NEXT:    [[ELT_EXP_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn 
float @llvm.exp.f32(float [[MUL_I]])
 // CHECK-NEXT:    [[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], float 0.000000e+00, float [[ELT_EXP_I]]
 // CHECK-NEXT:    [[VECINS_I:%.*]] = insertelement <4 x float> [[VECINIT2_I]], 
float [[HLSL_SELECT7_I]], i64 2
 // CHECK-NEXT:    ret <4 x float> [[VECINS_I]]
 //
-float4 test_lit_float(float N_dot_l, float N_dot_h, float M) { return 
lit(N_dot_l, N_dot_h, M); }
+float4 test_lit_float(float NDotL, float NDotH, float M) { return lit(NDotL, 
NDotH, M); }

>From 9905d25a61389b28b871294f4a3c38f3ec0ff1a2 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Tue, 1 Apr 2025 12:17:15 -0700
Subject: [PATCH 03/12] WIP accept double/int inputs and downcast to floats

---
 .../lib/Headers/hlsl/hlsl_compat_overloads.h  |  9 ++++++++
 .../CodeGenHLSL/builtins/lit-overloads.hlsl   | 23 +++++++++++++++++++
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  | 14 -----------
 3 files changed, 32 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index 47ae34adfe541..47c4a15b6fef9 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -280,6 +280,15 @@ constexpr bool4 isinf(double4 V) { return 
isinf((float4)V); }
 _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
 _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
+//===----------------------------------------------------------------------===//
+// lit builtins overloads
+//===----------------------------------------------------------------------===//
+constexpr float4 lit(double V1, double V2, double V3) { return lit((float)V1, 
(float)V2, (float)V3); }
+constexpr float4 lit(int V1, int V2, int V3) { return lit((float)V1, 
(float)V2, (float)V3); }
+constexpr float4 lit(uint V1, uint V2, uint V3) { return lit((float)V1, 
(float)V2, (float)V3); }
+constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) { return 
lit((float)V1, (float)V2, (float)V3); }
+constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) { return 
lit((float)V1, (float)V2, (float)V3); }
+
 
//===----------------------------------------------------------------------===//
 // log builtins overloads
 
//===----------------------------------------------------------------------===//
diff --git a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
new file mode 100644
index 0000000000000..9d2bca2efd05c
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s \
+// RUN:  -emit-llvm -disable-llvm-passes -o - | \
+// RUN:  FileCheck %s --check-prefixes=CHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_double
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+float4 test_lit_double(double NDotL, double NDotH, double M) { return 
lit(NDotL, NDotH, M); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_int
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+float4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, 
M); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_uint
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+float4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, 
NDotH, M); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) float 
{{.*}}test_floor_int64_t
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+float4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return 
lit(NDotL, NDotH, M); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) float 
{{.*}}test_floor_uint64_t
+// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+float4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { return 
lit(NDotL, NDotH, M); }
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
index 33fb33ca3204d..de93d1d0a64ad 100644
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -21,20 +21,6 @@ float4 test_too_many_arg(float p0) {
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
 }
 
-float4 test_double_inputs(double p0, double p1, double p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = double]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<double, 4>>'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = double]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<double, 4>>'}}
-}
-
-float4 test_int_inputs(int p0, int p1, int p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = int]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<int, 4>>'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = int]: no type named 'Type' in 
'hlsl::__detail::enable_if<false, vector<int, 4>>'}}
-}
-
 float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
   return lit(p0, p1, p2);
   // expected-error@-1  {{no matching function for call to 'lit'}}

>From d9d1731fba4d22ed7f95ac637038a5f15bcd5ecf Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Tue, 1 Apr 2025 15:28:11 -0700
Subject: [PATCH 04/12] WIP double/int overloads

---
 .../lib/Headers/hlsl/hlsl_compat_overloads.h  | 24 +++++++++---
 .../CodeGenHLSL/builtins/lit-overloads.hlsl   | 20 +++++-----
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  | 39 +++++++++++++------
 3 files changed, 56 insertions(+), 27 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index 47c4a15b6fef9..86e81123caffc 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -9,6 +9,8 @@
 #ifndef _HLSL_COMPAT_OVERLOADS_H_
 #define _HLSl_COMPAT_OVERLOADS_H_
 
+#include "hlsl/hlsl_intrinsic_helpers.h"
+
 namespace hlsl {
 
 // Note: Functions in this file are sorted alphabetically, then grouped by base
@@ -283,11 +285,23 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
//===----------------------------------------------------------------------===//
 // lit builtins overloads
 
//===----------------------------------------------------------------------===//
-constexpr float4 lit(double V1, double V2, double V3) { return lit((float)V1, 
(float)V2, (float)V3); }
-constexpr float4 lit(int V1, int V2, int V3) { return lit((float)V1, 
(float)V2, (float)V3); }
-constexpr float4 lit(uint V1, uint V2, uint V3) { return lit((float)V1, 
(float)V2, (float)V3); }
-constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) { return 
lit((float)V1, (float)V2, (float)V3); }
-constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) { return 
lit((float)V1, (float)V2, (float)V3); }
+
+// Note: calling lit_impl because calling lit directly causes infinite 
recursion
+constexpr float4 lit(double V1, double V2, double V3) {
+  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+}
+constexpr float4 lit(int V1, int V2, int V3) {
+  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+}
+constexpr float4 lit(uint V1, uint V2, uint V3) {
+  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+}
+constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) {
+  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+}
+constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) {
+  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+}
 
 
//===----------------------------------------------------------------------===//
 // log builtins overloads
diff --git a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
index 9d2bca2efd05c..8a9b31bf6ae8b 100644
--- a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
@@ -2,22 +2,22 @@
 // RUN:  -emit-llvm -disable-llvm-passes -o - | \
 // RUN:  FileCheck %s --check-prefixes=CHECK
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_double
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEddd(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
 float4 test_lit_double(double NDotL, double NDotH, double M) { return 
lit(NDotL, NDotH, M); }
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_int
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEiii(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
 float4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, 
M); }
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_uint
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEjjj(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
 float4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, 
NDotH, M); }
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) float 
{{.*}}test_floor_int64_t
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litElll(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
 float4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return 
lit(NDotL, NDotH, M); }
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) float 
{{.*}}test_floor_uint64_t
-// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
+// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEmmm(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
 float4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { return 
lit(NDotL, NDotH, M); }
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
index de93d1d0a64ad..b14d3e840fa0e 100644
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -3,6 +3,11 @@
 float4 test_no_second_arg(float p0) {
   return lit(p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
 }
@@ -10,6 +15,11 @@ float4 test_no_second_arg(float p0) {
 float4 test_no_third_arg(float p0) {
   return lit(p0, p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
 }
@@ -17,20 +27,25 @@ float4 test_no_third_arg(float p0) {
 float4 test_too_many_arg(float p0) {
   return lit(p0, p0, p0, p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
 }
 
-float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
-}
+// float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
+//   return lit(p0, p1, p2);
+//   // expected-error@-1  {{no matching function for call to 'lit'}}
+//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+// }
 
-float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
-}
\ No newline at end of file
+// float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
+//   return lit(p0, p1, p2);
+//   // expected-error@-1  {{no matching function for call to 'lit'}}
+//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+// }

>From 9064f10d3b497e6df64ceadfbe2e781f3dba57ac Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Wed, 2 Apr 2025 09:43:08 -0700
Subject: [PATCH 05/12] WIP fix double/int overloads

---
 clang/lib/Headers/hlsl.h                      |  2 +-
 .../lib/Headers/hlsl/hlsl_compat_overloads.h  | 10 ++++----
 .../CodeGenHLSL/builtins/lit-overloads.hlsl   | 10 ++++----
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  | 24 +++++++++----------
 4 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/clang/lib/Headers/hlsl.h b/clang/lib/Headers/hlsl.h
index b494b4d0f78bb..2bc1973f6eb2b 100644
--- a/clang/lib/Headers/hlsl.h
+++ b/clang/lib/Headers/hlsl.h
@@ -22,10 +22,10 @@
 
 // HLSL standard library function declarations/definitions.
 #include "hlsl/hlsl_alias_intrinsics.h"
+#include "hlsl/hlsl_intrinsics.h"
 #if __HLSL_VERSION <= __HLSL_202x
 #include "hlsl/hlsl_compat_overloads.h"
 #endif
-#include "hlsl/hlsl_intrinsics.h"
 
 #if defined(__clang__)
 #pragma clang diagnostic pop
diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index 86e81123caffc..f463a530c266c 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -288,19 +288,19 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
 // Note: calling lit_impl because calling lit directly causes infinite 
recursion
 constexpr float4 lit(double V1, double V2, double V3) {
-  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+  return lit((float)V1, (float)V2, (float)V3);
 }
 constexpr float4 lit(int V1, int V2, int V3) {
-  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+  return lit((float)V1, (float)V2, (float)V3);
 }
 constexpr float4 lit(uint V1, uint V2, uint V3) {
-  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+  return lit((float)V1, (float)V2, (float)V3);
 }
 constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) {
-  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+  return lit((float)V1, (float)V2, (float)V3);
 }
 constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) {
-  return __detail::lit_impl((float)V1, (float)V2, (float)V3);
+  return lit((float)V1, (float)V2, (float)V3);
 }
 
 
//===----------------------------------------------------------------------===//
diff --git a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
index 8a9b31bf6ae8b..734f0452900e6 100644
--- a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
@@ -3,21 +3,21 @@
 // RUN:  FileCheck %s --check-prefixes=CHECK
 
 // CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEddd(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
 float4 test_lit_double(double NDotL, double NDotH, double M) { return 
lit(NDotL, NDotH, M); }
 
 // CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEiii(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
 float4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, 
M); }
 
 // CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEjjj(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
 float4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, 
NDotH, M); }
 
 // CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litElll(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
 float4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return 
lit(NDotL, NDotH, M); }
 
 // CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEmmm(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
+// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
 float4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { return 
lit(NDotL, NDotH, M); }
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
index b14d3e840fa0e..9ac6fa0157be8 100644
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -36,16 +36,16 @@ float4 test_too_many_arg(float p0) {
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
 }
 
-// float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
-//   return lit(p0, p1, p2);
-//   // expected-error@-1  {{no matching function for call to 'lit'}}
-//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
-//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
-// }
+float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1  {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+}
 
-// float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
-//   return lit(p0, p1, p2);
-//   // expected-error@-1  {{no matching function for call to 'lit'}}
-//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
-//   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
-// }
+float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1  {{no matching function for call to 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+}

>From 6026d8fa02068b0f97554950689a4bfcbd0fc770 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Wed, 2 Apr 2025 15:52:28 -0700
Subject: [PATCH 06/12] finished double/int overloads and overload tests

---
 .../lib/Headers/hlsl/hlsl_compat_overloads.h  |  27 ++---
 .../CodeGenHLSL/builtins/lit-overloads.hlsl   | 102 +++++++++++++++---
 clang/test/CodeGenHLSL/builtins/lit.hlsl      |   4 +-
 .../SemaHLSL/BuiltIns/lit-errors-16bit.hlsl   |   9 ++
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  |  20 +---
 5 files changed, 112 insertions(+), 50 deletions(-)
 create mode 100644 clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index f463a530c266c..cbf5364c0b29c 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -9,8 +9,6 @@
 #ifndef _HLSL_COMPAT_OVERLOADS_H_
 #define _HLSl_COMPAT_OVERLOADS_H_
 
-#include "hlsl/hlsl_intrinsic_helpers.h"
-
 namespace hlsl {
 
 // Note: Functions in this file are sorted alphabetically, then grouped by base
@@ -286,21 +284,16 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 // lit builtins overloads
 
//===----------------------------------------------------------------------===//
 
-// Note: calling lit_impl because calling lit directly causes infinite 
recursion
-constexpr float4 lit(double V1, double V2, double V3) {
-  return lit((float)V1, (float)V2, (float)V3);
-}
-constexpr float4 lit(int V1, int V2, int V3) {
-  return lit((float)V1, (float)V2, (float)V3);
-}
-constexpr float4 lit(uint V1, uint V2, uint V3) {
-  return lit((float)V1, (float)V2, (float)V3);
-}
-constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) {
-  return lit((float)V1, (float)V2, (float)V3);
-}
-constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) {
-  return lit((float)V1, (float)V2, (float)V3);
+template <typename T>
+constexpr __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
+                                    (__detail::is_same<double, T>::value ||
+                                     __detail::is_same<int, T>::value ||
+                                     __detail::is_same<uint, T>::value ||
+                                     __detail::is_same<int64_t, T>::value ||
+                                     __detail::is_same<uint64_t, T>::value),
+                                vector<T, 4>>
+lit(T NDotL, T NDotH, T M) {
+  return lit((float)NDotL, (float)NDotH, (float)M);
 }
 
 
//===----------------------------------------------------------------------===//
diff --git a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
index 734f0452900e6..676889ecf16b0 100644
--- a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
@@ -1,23 +1,93 @@
 // RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s \
-// RUN:  -emit-llvm -disable-llvm-passes -o - | \
+// RUN:  -emit-llvm -o - | \
 // RUN:  FileCheck %s --check-prefixes=CHECK
 
-// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEddd(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
-float4 test_lit_double(double NDotL, double NDotH, double M) { return 
lit(NDotL, NDotH, M); }
+// CHECK-LABEL: test_lit_double
+// CHECK: %conv.i = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to 
float
+// CHECK: %conv1.i = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to 
float
+// CHECK: %conv2.i = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to 
float
+// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
+// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
+// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
+// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
+// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
+// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
+// CHECK: %conv3.i = fpext reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}} 
to <4 x double>
+// CHECK: ret <4 x double> %conv3.i
+double4 test_lit_double(double NDotL, double NDotH, double M) { return 
lit(NDotL, NDotH, M); }
 
-// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEiii(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
-float4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, 
M); }
+// CHECK-LABEL: test_lit_int
+// CHECK: %conv.i = sitofp i32 %{{.*}} to float
+// CHECK: %conv1.i = sitofp i32 %{{.*}} to float
+// CHECK: %conv2.i = sitofp i32 %{{.*}} to float
+// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
+// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
+// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
+// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
+// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
+// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
+// CHECK: %conv3.i = fptosi <4 x float> %{{.*}} to <4 x i32>
+// CHECK: ret <4 x i32> %conv3.i
+int4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, M); }
 
-// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEjjj(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
-float4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, 
NDotH, M); }
+// CHECK-LABEL: test_lit_uint
+// CHECK: %conv.i = uitofp i32 %{{.*}} to float
+// CHECK: %conv1.i = uitofp i32 %{{.*}} to float
+// CHECK: %conv2.i = uitofp i32 %{{.*}} to float
+// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
+// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
+// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
+// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
+// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
+// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
+// CHECK: %conv3.i = fptoui <4 x float> %{{.*}} to <4 x i32>
+// CHECK: ret <4 x i32> %conv3.i
+uint4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, NDotH, 
M); }
 
-// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litElll(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
-float4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return 
lit(NDotL, NDotH, M); }
+// CHECK-LABEL: test_lit_int64_t
+// CHECK: %conv.i = sitofp i64 %{{.*}} to float
+// CHECK: %conv1.i = sitofp i64 %{{.*}} to float
+// CHECK: %conv2.i = sitofp i64 %{{.*}} to float
+// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
+// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
+// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
+// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
+// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
+// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
+// CHECK: %conv3.i = fptosi <4 x float> %{{.*}} to <4 x i64>
+// CHECK: ret <4 x i64> %conv3.i
+int64_t4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return 
lit(NDotL, NDotH, M); }
 
-// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> 
@_ZN4hlsl3litEmmm(
-// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x 
float> 
@_ZN4hlsl3litIfEEKNS_8__detail9enable_ifIXaasr8__detail13is_arithmeticIT_EE5Valuesr8__detail7is_sameIfS3_EE5valueEDv4_S3_E4TypeES3_S3_S3_(
-float4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { return 
lit(NDotL, NDotH, M); }
+// CHECK-LABEL: test_lit_uint64_t
+// CHECK: %conv.i = uitofp i64 %{{.*}} to float
+// CHECK: %conv1.i = uitofp i64 %{{.*}} to float
+// CHECK: %conv2.i = uitofp i64 %{{.*}} to float
+// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
+// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
+// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
+// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
+// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
+// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
+// CHECK: %conv3.i = fptoui <4 x float> %{{.*}} to <4 x i64>
+// CHECK: ret <4 x i64> %conv3.i
+uint64_t4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { 
return lit(NDotL, NDotH, M); }
diff --git a/clang/test/CodeGenHLSL/builtins/lit.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit.hlsl
index 484a85779a375..1737a460e020f 100644
--- a/clang/test/CodeGenHLSL/builtins/lit.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit.hlsl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x half> 
@_Z13test_lit_halfDhDhDh(
+// CHECK-LABEL: test_lit_half
 // CHECK-SAME: half noundef nofpclass(nan inf) [[NDOTL:%.*]], half noundef 
nofpclass(nan inf) [[NDOTH:%.*]], half noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt half 
[[NDOTL]], 0xH0000
@@ -18,7 +18,7 @@
 //
 half4 test_lit_half(half NDotL, half NDotH, half M) { return lit(NDotL, NDotH, 
M); }
 
-// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x float> 
@_Z14test_lit_floatfff(
+// CHECK-LABEL: test_lit_float
 // CHECK-SAME: float noundef nofpclass(nan inf) [[NDOTL:%.*]], float noundef 
nofpclass(nan inf) [[NDOTH:%.*]], float noundef nofpclass(nan inf) [[M:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[CMP_I:%.*]] = fcmp reassoc nnan ninf nsz arcp afn olt 
float [[NDOTL]], 0.000000e+00
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl
new file mode 100644
index 0000000000000..311bad9a0ef79
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl
@@ -0,0 +1,9 @@
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=half
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=int16_t
+// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=uint16_t
+
+// check we error on 16 bit type if shader model is too old
+// CHECK: '-enable-16bit-types' option requires target HLSL Version >= 2018 
and shader model >= 6.2, but HLSL Version is 'hlsl202x' and shader model is 
'6.0'
+vector<TEST_TYPE,4> test_error(TEST_TYPE p0) {
+  return lit(p0, p0, p0);
+}
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
index 9ac6fa0157be8..799fb62a9560d 100644
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -3,37 +3,25 @@
 float4 test_no_second_arg(float p0) {
   return lit(p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 1 was provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 1 was provided}}
 }
 
 float4 test_no_third_arg(float p0) {
   return lit(p0, p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 2 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 2 were provided}}
 }
 
 float4 test_too_many_arg(float p0) {
   return lit(p0, p0, p0, p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not 
viable: requires 3 arguments, but 4 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 4 were provided}}
 }
 
 float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
@@ -41,6 +29,7 @@ float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
   // expected-error@-1  {{no matching function for call to 'lit'}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template 
ignored: substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
 }
 
 float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
@@ -48,4 +37,5 @@ float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
   // expected-error@-1  {{no matching function for call to 'lit'}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
   // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template 
ignored: substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
 }

>From 0f6d9bf885e040e42a644e1d2976c0de355d1f55 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Thu, 3 Apr 2025 15:09:38 -0700
Subject: [PATCH 07/12] address PR comments - formatting changes

---
 clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 2 +-
 clang/test/CodeGenHLSL/builtins/lit.hlsl        | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index ae53e1309a404..d4f0f46f89111 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -113,7 +113,7 @@ 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);
   vector<T, 4> Result = {1, Diffuse, 0, 1};
-  bool SpecularCond = or (DiffuseCond, (NDotH < 0));
+  bool SpecularCond = or(DiffuseCond, (NDotH < 0));
   T SpecularExp = exp(log(NDotH) * M);
   Result[2] = select<T>(SpecularCond, 0, SpecularExp);
   return Result;
diff --git a/clang/test/CodeGenHLSL/builtins/lit.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit.hlsl
index 1737a460e020f..114cbd0066844 100644
--- a/clang/test/CodeGenHLSL/builtins/lit.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit.hlsl
@@ -15,7 +15,6 @@
 // CHECK-NEXT:    [[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], half 0xH0000, half [[ELT_EXP_I]]
 // CHECK-NEXT:    [[VECINS_I:%.*]] = insertelement <4 x half> [[VECINIT2_I]], 
half [[HLSL_SELECT7_I]], i64 2
 // CHECK-NEXT:    ret <4 x half> [[VECINS_I]]
-//
 half4 test_lit_half(half NDotL, half NDotH, half M) { return lit(NDotL, NDotH, 
M); }
 
 // CHECK-LABEL: test_lit_float
@@ -32,5 +31,4 @@ half4 test_lit_half(half NDotL, half NDotH, half M) { return 
lit(NDotL, NDotH, M
 // CHECK-NEXT:    [[HLSL_SELECT7_I:%.*]] = select reassoc nnan ninf nsz arcp 
afn i1 [[HLSL_OR_I]], float 0.000000e+00, float [[ELT_EXP_I]]
 // CHECK-NEXT:    [[VECINS_I:%.*]] = insertelement <4 x float> [[VECINIT2_I]], 
float [[HLSL_SELECT7_I]], i64 2
 // CHECK-NEXT:    ret <4 x float> [[VECINS_I]]
-//
 float4 test_lit_float(float NDotL, float NDotH, float M) { return lit(NDotL, 
NDotH, M); }

>From 409fd4c2b75bc151732dab3d0af3d7530ee87693 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Thu, 3 Apr 2025 15:28:14 -0700
Subject: [PATCH 08/12] address PR comments - turn clang-format off for `or`
 line in `lit_impl`

---
 clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index d4f0f46f89111..f452480709235 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -113,7 +113,9 @@ 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);
   vector<T, 4> Result = {1, Diffuse, 0, 1};
+  // clang-format off
   bool SpecularCond = or(DiffuseCond, (NDotH < 0));
+  // clang-format on
   T SpecularExp = exp(log(NDotH) * M);
   Result[2] = select<T>(SpecularCond, 0, SpecularExp);
   return Result;

>From 199e9b139dd85400a2695815f4581a467341c688 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Thu, 3 Apr 2025 16:28:25 -0700
Subject: [PATCH 09/12] allow bool overload, add bool test

---
 clang/lib/Headers/hlsl/hlsl_compat_overloads.h |  7 ++-----
 .../CodeGenHLSL/builtins/lit-overloads.hlsl    | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index cbf5364c0b29c..226ace905e051 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -286,11 +286,8 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
 template <typename T>
 constexpr __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                    (__detail::is_same<double, T>::value ||
-                                     __detail::is_same<int, T>::value ||
-                                     __detail::is_same<uint, T>::value ||
-                                     __detail::is_same<int64_t, T>::value ||
-                                     __detail::is_same<uint64_t, T>::value),
+                                    !__detail::is_same<half, T>::value &&
+                                    !__detail::is_same<float, T>::value,
                                 vector<T, 4>>
 lit(T NDotL, T NDotH, T M) {
   return lit((float)NDotL, (float)NDotH, (float)M);
diff --git a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
index 676889ecf16b0..425d0aa1f868a 100644
--- a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
@@ -91,3 +91,21 @@ int64_t4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, 
int64_t M) { return lit(
 // CHECK: %conv3.i = fptoui <4 x float> %{{.*}} to <4 x i64>
 // CHECK: ret <4 x i64> %conv3.i
 uint64_t4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { 
return lit(NDotL, NDotH, M); }
+
+// CHECK-LABEL: test_lit_bool
+// CHECK: %conv.i = uitofp i1 %{{.*}} to float
+// CHECK: %conv4.i = uitofp i1 %{{.*}} to float
+// CHECK: %conv6.i = uitofp i1 %{{.*}} to float
+// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
+// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
+// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
+// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
+// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
+// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
+// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
+// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
+// CHECK: %tobool.i = fcmp reassoc nnan ninf nsz arcp afn une <4 x float> 
%{{.*}}, zeroinitializer
+// CHECK: ret <4 x i1> %tobool.i
+bool4 test_lit_bool(bool NDotL, bool NDotH, bool M) { return lit(NDotL, NDotH, 
M); }

>From 3f8e6a52c40133b1a6cc9a429e7ff18715497fbc Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Thu, 3 Apr 2025 17:42:38 -0700
Subject: [PATCH 10/12] template specialization

---
 clang/lib/Headers/hlsl.h                       |  2 +-
 clang/lib/Headers/hlsl/hlsl_compat_overloads.h |  8 +++-----
 clang/lib/Headers/hlsl/hlsl_intrinsics.h       | 13 ++++---------
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl   | 10 ----------
 4 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Headers/hlsl.h b/clang/lib/Headers/hlsl.h
index 2bc1973f6eb2b..b494b4d0f78bb 100644
--- a/clang/lib/Headers/hlsl.h
+++ b/clang/lib/Headers/hlsl.h
@@ -22,10 +22,10 @@
 
 // HLSL standard library function declarations/definitions.
 #include "hlsl/hlsl_alias_intrinsics.h"
-#include "hlsl/hlsl_intrinsics.h"
 #if __HLSL_VERSION <= __HLSL_202x
 #include "hlsl/hlsl_compat_overloads.h"
 #endif
+#include "hlsl/hlsl_intrinsics.h"
 
 #if defined(__clang__)
 #pragma clang diagnostic pop
diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index 226ace905e051..a552af7cf8a36 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -285,12 +285,10 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
//===----------------------------------------------------------------------===//
 
 template <typename T>
-constexpr __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                    !__detail::is_same<half, T>::value &&
-                                    !__detail::is_same<float, T>::value,
-                                vector<T, 4>>
+const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value,
+                                   vector<T, 4>>
 lit(T NDotL, T NDotH, T M) {
-  return lit((float)NDotL, (float)NDotH, (float)M);
+  return lit<float>((float)NDotL, (float)NDotH, (float)M);
 }
 
 
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index c59ca0b10c81a..e4d04f193b70f 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -283,19 +283,14 @@ const inline float 
length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
 /// This function returns a lighting coefficient vector (ambient, diffuse,
 /// specular, 1).
 
-template <typename T>
+template <>
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<half, T>::value,
-                                   vector<T, 4>> lit(T NDotL, T NDotH, T M) {
+const inline vector<half, 4> lit<half>(half NDotL, half NDotH, half M) {
   return __detail::lit_impl(NDotL, NDotH, M);
 }
 
-template <typename T>
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
-                                       __detail::is_same<float, T>::value,
-                                   vector<T, 4>>
-lit(T NDotL, T NDotH, T M) {
+template <>
+const inline vector<float, 4> lit<float>(float NDotL, float NDotH, float M) {
   return __detail::lit_impl(NDotL, NDotH, M);
 }
 
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
index 799fb62a9560d..8b9b721ae4f03 100644
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -3,39 +3,29 @@
 float4 test_no_second_arg(float p0) {
   return lit(p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 1 was provided}}
   // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 1 was provided}}
 }
 
 float4 test_no_third_arg(float p0) {
   return lit(p0, p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 2 were provided}}
   // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 2 were provided}}
 }
 
 float4 test_too_many_arg(float p0) {
   return lit(p0, p0, p0, p0);
   // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires 3 arguments, but 4 were provided}}
   // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 4 were provided}}
 }
 
 float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
   return lit(p0, p1, p2);
   // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
   // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template 
ignored: substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
 }
 
 float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
   return lit(p0, p1, p2);
   // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: 
substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
   // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template 
ignored: substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
 }

>From 321e54ed3479c9bde0427985ff521d5e10b11174 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Mon, 7 Apr 2025 11:32:47 -0700
Subject: [PATCH 11/12] add >= hlsl202y primary template definition, add
 hlsl202y sema tests

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h      |  4 ++
 .../BuiltIns/lit-errors-hlsl202y.hlsl         | 37 +++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index e4d04f193b70f..cde205f026702 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -283,6 +283,10 @@ const inline float 
length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
 /// This function returns a lighting coefficient vector (ambient, diffuse,
 /// specular, 1).
 
+#if __HLSL_VERSION >= __HLSL_202y
+template <typename T> const inline vector<T, 4> lit(T, T, T) = delete;
+#endif
+
 template <>
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline vector<half, 4> lit<half>(half NDotL, half NDotH, half M) {
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl
new file mode 100644
index 0000000000000..b55b0aa4cc522
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=hlsl202y -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+
+double4 test_double_inputs(double p0, double p1, double p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to deleted function 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
double] has been explicitly deleted}}
+}
+
+int4 test_int_inputs(int p0, int p1, int p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to deleted function 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
int] has been explicitly deleted}}
+}
+
+uint4 test_uint_inputs(uint p0, uint p1, uint p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to deleted function 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
unsigned int] has been explicitly deleted}}
+}
+
+int64_t4 test_int64_t_inputs(int64_t p0, int64_t p1, int64_t p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to deleted function 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
long] has been explicitly deleted}}
+}
+
+uint64_t4 test_uint64_t_inputs(uint64_t p0, uint64_t p1, uint64_t p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to deleted function 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
unsigned long] has been explicitly deleted}}
+}
+
+bool4 test_bool_inputs(bool p0, bool p1, bool p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to deleted function 'lit'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
bool] has been explicitly deleted}}
+}

>From df05a3da14d1d8c8772bb66b8becdc29acd82c84 Mon Sep 17 00:00:00 2001
From: kmpeng <kaitlinp...@microsoft.com>
Date: Tue, 8 Apr 2025 11:12:50 -0700
Subject: [PATCH 12/12] remove compat overloads and corresponding tests, remove
 templates in `hlsl_intrinsics.h`

---
 .../lib/Headers/hlsl/hlsl_compat_overloads.h  |  11 --
 clang/lib/Headers/hlsl/hlsl_intrinsics.h      |  10 +-
 .../CodeGenHLSL/builtins/lit-overloads.hlsl   | 111 ------------------
 .../SemaHLSL/BuiltIns/lit-errors-16bit.hlsl   |   9 --
 .../BuiltIns/lit-errors-hlsl202y.hlsl         |  37 ------
 clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl  |  31 ++---
 6 files changed, 10 insertions(+), 199 deletions(-)
 delete mode 100644 clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
 delete mode 100644 clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl
 delete mode 100644 clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index a552af7cf8a36..47ae34adfe541 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -280,17 +280,6 @@ constexpr bool4 isinf(double4 V) { return 
isinf((float4)V); }
 _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
 _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
-//===----------------------------------------------------------------------===//
-// lit builtins overloads
-//===----------------------------------------------------------------------===//
-
-template <typename T>
-const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value,
-                                   vector<T, 4>>
-lit(T NDotL, T NDotH, T M) {
-  return lit<float>((float)NDotL, (float)NDotH, (float)M);
-}
-
 
//===----------------------------------------------------------------------===//
 // log builtins overloads
 
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index cde205f026702..026e5695d1387 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -283,18 +283,12 @@ const inline float 
length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
 /// This function returns a lighting coefficient vector (ambient, diffuse,
 /// specular, 1).
 
-#if __HLSL_VERSION >= __HLSL_202y
-template <typename T> const inline vector<T, 4> lit(T, T, T) = delete;
-#endif
-
-template <>
 _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
-const inline vector<half, 4> lit<half>(half NDotL, half NDotH, half M) {
+const inline half4 lit(half NDotL, half NDotH, half M) {
   return __detail::lit_impl(NDotL, NDotH, M);
 }
 
-template <>
-const inline vector<float, 4> lit<float>(float NDotL, float NDotH, float M) {
+const inline float4 lit(float NDotL, float NDotH, float M) {
   return __detail::lit_impl(NDotL, NDotH, M);
 }
 
diff --git a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl 
b/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
deleted file mode 100644
index 425d0aa1f868a..0000000000000
--- a/clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl
+++ /dev/null
@@ -1,111 +0,0 @@
-// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.3-library %s \
-// RUN:  -emit-llvm -o - | \
-// RUN:  FileCheck %s --check-prefixes=CHECK
-
-// CHECK-LABEL: test_lit_double
-// CHECK: %conv.i = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to 
float
-// CHECK: %conv1.i = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to 
float
-// CHECK: %conv2.i = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to 
float
-// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
-// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
-// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
-// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
-// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
-// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
-// CHECK: %conv3.i = fpext reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}} 
to <4 x double>
-// CHECK: ret <4 x double> %conv3.i
-double4 test_lit_double(double NDotL, double NDotH, double M) { return 
lit(NDotL, NDotH, M); }
-
-// CHECK-LABEL: test_lit_int
-// CHECK: %conv.i = sitofp i32 %{{.*}} to float
-// CHECK: %conv1.i = sitofp i32 %{{.*}} to float
-// CHECK: %conv2.i = sitofp i32 %{{.*}} to float
-// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
-// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
-// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
-// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
-// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
-// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
-// CHECK: %conv3.i = fptosi <4 x float> %{{.*}} to <4 x i32>
-// CHECK: ret <4 x i32> %conv3.i
-int4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, M); }
-
-// CHECK-LABEL: test_lit_uint
-// CHECK: %conv.i = uitofp i32 %{{.*}} to float
-// CHECK: %conv1.i = uitofp i32 %{{.*}} to float
-// CHECK: %conv2.i = uitofp i32 %{{.*}} to float
-// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
-// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
-// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
-// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
-// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
-// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
-// CHECK: %conv3.i = fptoui <4 x float> %{{.*}} to <4 x i32>
-// CHECK: ret <4 x i32> %conv3.i
-uint4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, NDotH, 
M); }
-
-// CHECK-LABEL: test_lit_int64_t
-// CHECK: %conv.i = sitofp i64 %{{.*}} to float
-// CHECK: %conv1.i = sitofp i64 %{{.*}} to float
-// CHECK: %conv2.i = sitofp i64 %{{.*}} to float
-// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
-// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
-// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
-// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
-// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
-// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
-// CHECK: %conv3.i = fptosi <4 x float> %{{.*}} to <4 x i64>
-// CHECK: ret <4 x i64> %conv3.i
-int64_t4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return 
lit(NDotL, NDotH, M); }
-
-// CHECK-LABEL: test_lit_uint64_t
-// CHECK: %conv.i = uitofp i64 %{{.*}} to float
-// CHECK: %conv1.i = uitofp i64 %{{.*}} to float
-// CHECK: %conv2.i = uitofp i64 %{{.*}} to float
-// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
-// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
-// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
-// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
-// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
-// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
-// CHECK: %conv3.i = fptoui <4 x float> %{{.*}} to <4 x i64>
-// CHECK: ret <4 x i64> %conv3.i
-uint64_t4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { 
return lit(NDotL, NDotH, M); }
-
-// CHECK-LABEL: test_lit_bool
-// CHECK: %conv.i = uitofp i1 %{{.*}} to float
-// CHECK: %conv4.i = uitofp i1 %{{.*}} to float
-// CHECK: %conv6.i = uitofp i1 %{{.*}} to float
-// CHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecinit.i = insertelement <4 x float> <float 1.000000e+00, float 
poison, float poison, float poison>, float %{{.*}}, i32 1
-// CHECK: %cmp4.i = fcmp reassoc nnan ninf nsz arcp afn olt float %{{.*}}, 
0.000000e+00
-// CHECK: %hlsl.or.i = or i1 %{{.*}}, %cmp4.i
-// CHECK: %elt.log.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.log.f32(float %{{.*}})
-// CHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn float %elt.log.i, 
%{{.*}}
-// CHECK: %elt.exp.i = call reassoc nnan ninf nsz arcp afn float 
@llvm.exp.f32(float %mul.i)
-// CHECK: %hlsl.select7.i = select reassoc nnan ninf nsz arcp afn i1 %{{.*}}, 
float 0.000000e+00, float %{{.*}}
-// CHECK: %vecins.i = insertelement <4 x float> %{{.*}}, float 
%hlsl.select7.i, i32 2
-// CHECK: %tobool.i = fcmp reassoc nnan ninf nsz arcp afn une <4 x float> 
%{{.*}}, zeroinitializer
-// CHECK: ret <4 x i1> %tobool.i
-bool4 test_lit_bool(bool NDotL, bool NDotH, bool M) { return lit(NDotL, NDotH, 
M); }
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl
deleted file mode 100644
index 311bad9a0ef79..0000000000000
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors-16bit.hlsl
+++ /dev/null
@@ -1,9 +0,0 @@
-// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=half
-// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=int16_t
-// RUN: not %clang_dxc -enable-16bit-types -T cs_6_0 -HV 202x %s 2>&1  | 
FileCheck %s -DTEST_TYPE=uint16_t
-
-// check we error on 16 bit type if shader model is too old
-// CHECK: '-enable-16bit-types' option requires target HLSL Version >= 2018 
and shader model >= 6.2, but HLSL Version is 'hlsl202x' and shader model is 
'6.0'
-vector<TEST_TYPE,4> test_error(TEST_TYPE p0) {
-  return lit(p0, p0, p0);
-}
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl
deleted file mode 100644
index b55b0aa4cc522..0000000000000
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors-hlsl202y.hlsl
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: %clang_cc1 -std=hlsl202y -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
-
-double4 test_double_inputs(double p0, double p1, double p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1 {{call to deleted function 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
double] has been explicitly deleted}}
-}
-
-int4 test_int_inputs(int p0, int p1, int p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1 {{call to deleted function 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
int] has been explicitly deleted}}
-}
-
-uint4 test_uint_inputs(uint p0, uint p1, uint p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1 {{call to deleted function 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
unsigned int] has been explicitly deleted}}
-}
-
-int64_t4 test_int64_t_inputs(int64_t p0, int64_t p1, int64_t p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1 {{call to deleted function 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
long] has been explicitly deleted}}
-}
-
-uint64_t4 test_uint64_t_inputs(uint64_t p0, uint64_t p1, uint64_t p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1 {{call to deleted function 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
unsigned long] has been explicitly deleted}}
-}
-
-bool4 test_bool_inputs(bool p0, bool p1, bool p2) {
-  return lit(p0, p1, p2);
-  // expected-error@-1 {{call to deleted function 'lit'}}
-  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function [with T = 
bool] has been explicitly deleted}}
-}
diff --git a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
index 8b9b721ae4f03..2746a118d33c5 100644
--- a/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/lit-errors.hlsl
@@ -1,31 +1,16 @@
-// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only 
-disable-llvm-passes -verify -verify-ignore-unexpected=note
 
-float4 test_no_second_arg(float p0) {
-  return lit(p0);
-  // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 1 was provided}}
-}
-
-float4 test_no_third_arg(float p0) {
-  return lit(p0, p0);
-  // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 2 were provided}}
-}
-
-float4 test_too_many_arg(float p0) {
-  return lit(p0, p0, p0, p0);
-  // expected-error@-1 {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function 
template not viable: requires 3 arguments, but 4 were provided}}
+float4 test_double_inputs(double p0, double p1, double p2) {
+  return lit(p0, p1, p2);
+  // expected-error@-1 {{call to 'lit' is ambiguous}}
 }
 
-float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
+float4 test_int_inputs(int p0, int p1, int p2) {
   return lit(p0, p1, p2);
-  // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template 
ignored: substitution failure [with T = float2]: invalid vector element type 
'vector<float, 2>' (vector of 2 'float' values)}}
+  // expected-error@-1 {{call to 'lit' is ambiguous}}
 }
 
-float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
+float4 test_bool_inputs(bool p0, bool p1, bool p2) {
   return lit(p0, p1, p2);
-  // expected-error@-1  {{no matching function for call to 'lit'}}
-  // expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template 
ignored: substitution failure [with T = float1]: invalid vector element type 
'vector<float, 1>' (vector of 1 'float' value)}}
+  // expected-error@-1 {{call to 'lit' is ambiguous}}
 }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to