[clang] c4d9323 - [Matrix] Implement matrix support for the `smoothstep` intrinsic (#246131)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 10:50:49 PST 2026


Author: Kaitlin Peng
Date: 2026-12-03T10:50:43-08:00
New Revision: c4d932328bbec05dfc9ca7369e8b7b00e46cca55

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

LOG: [Matrix] Implement matrix support for the `smoothstep` intrinsic (#246131)

Closes #184489.

This PR implements the matrix api for `smoothstep` and adds matrix
codegen tests. Matrix sema tests were not added because `smoothstep` has
no HLSL builtin. Matrix backend tests were not added because no DirectX
or SPIRV backend changes were made.

Assisted-by: Claude Opus 5.5

Added: 
    clang/test/CodeGenHLSL/builtins/smoothstep_mat.hlsl

Modified: 
    clang/include/clang/Basic/HLSLIntrinsics.td
    clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td
index ddac44bf93c20f..bc36b292e4f720 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -1641,7 +1641,6 @@ between 0 and 1.
   let ParamNames = ["Min", "Max", "X"];
   let VaryingTypes = [HalfTy, FloatTy];
   let VaryingLongVector = 1;
-  let VaryingMatDims = [];
 }
 
 // Returns the square root of the input value, Val.

diff  --git a/clang/test/CodeGenHLSL/builtins/smoothstep_mat.hlsl b/clang/test/CodeGenHLSL/builtins/smoothstep_mat.hlsl
new file mode 100644
index 00000000000000..089889a7cd666c
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/smoothstep_mat.hlsl
@@ -0,0 +1,74 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,DXCHECK
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple spirv-unknown-vulkan-library %s -fnative-half-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,SPVCHECK
+
+// CHECK-LABEL: test_smoothstep_half2x3
+// DXCHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <6 x half> %{{.*}}, %{{.*}}
+// DXCHECK: [[SUB1:%.*]] = fsub reassoc nnan ninf nsz arcp afn <6 x half> %{{.*}}, %{{.*}}
+// DXCHECK: [[DIV:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <6 x half> [[SUB]], [[SUB1]]
+// DXCHECK: call reassoc nnan ninf nsz arcp afn <6 x half> @llvm.dx.saturate.v6f16(<6 x half> [[DIV]])
+// DXCHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <6 x half> splat (half 2.000000e+00), %{{.*}}
+// DXCHECK: [[SUB2:%.*]] = fsub reassoc nnan ninf nsz arcp afn <6 x half> splat (half 3.000000e+00), [[MUL]]
+// DXCHECK: [[MUL1:%.*]] = fmul reassoc nnan ninf nsz arcp afn <6 x half> [[SUB2]], %{{.*}}
+// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> [[MUL1]], %{{.*}}
+// SPVCHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <6 x half> @llvm.spv.smoothstep.v6f16(<6 x half> %{{.*}}, <6 x half> %{{.*}}, <6 x half> %{{.*}})
+half2x3 test_smoothstep_half2x3(half2x3 p0, half2x3 p1, half2x3 p2) { return smoothstep(p0, p1, p2); }
+
+// CHECK-LABEL: test_smoothstep_half3x4
+// DXCHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <12 x half> %{{.*}}, %{{.*}}
+// DXCHECK: [[SUB1:%.*]] = fsub reassoc nnan ninf nsz arcp afn <12 x half> %{{.*}}, %{{.*}}
+// DXCHECK: [[DIV:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <12 x half> [[SUB]], [[SUB1]]
+// DXCHECK: call reassoc nnan ninf nsz arcp afn <12 x half> @llvm.dx.saturate.v12f16(<12 x half> [[DIV]])
+// DXCHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <12 x half> splat (half 2.000000e+00), %{{.*}}
+// DXCHECK: [[SUB2:%.*]] = fsub reassoc nnan ninf nsz arcp afn <12 x half> splat (half 3.000000e+00), [[MUL]]
+// DXCHECK: [[MUL1:%.*]] = fmul reassoc nnan ninf nsz arcp afn <12 x half> [[SUB2]], %{{.*}}
+// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> [[MUL1]], %{{.*}}
+// SPVCHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <12 x half> @llvm.spv.smoothstep.v12f16(<12 x half> %{{.*}}, <12 x half> %{{.*}}, <12 x half> %{{.*}})
+half3x4 test_smoothstep_half3x4(half3x4 p0, half3x4 p1, half3x4 p2) { return smoothstep(p0, p1, p2); }
+
+// CHECK-LABEL: test_smoothstep_half4x4
+// DXCHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <16 x half> %{{.*}}, %{{.*}}
+// DXCHECK: [[SUB1:%.*]] = fsub reassoc nnan ninf nsz arcp afn <16 x half> %{{.*}}, %{{.*}}
+// DXCHECK: [[DIV:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <16 x half> [[SUB]], [[SUB1]]
+// DXCHECK: call reassoc nnan ninf nsz arcp afn <16 x half> @llvm.dx.saturate.v16f16(<16 x half> [[DIV]])
+// DXCHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <16 x half> splat (half 2.000000e+00), %{{.*}}
+// DXCHECK: [[SUB2:%.*]] = fsub reassoc nnan ninf nsz arcp afn <16 x half> splat (half 3.000000e+00), [[MUL]]
+// DXCHECK: [[MUL1:%.*]] = fmul reassoc nnan ninf nsz arcp afn <16 x half> [[SUB2]], %{{.*}}
+// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <16 x half> [[MUL1]], %{{.*}}
+// SPVCHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <16 x half> @llvm.spv.smoothstep.v16f16(<16 x half> %{{.*}}, <16 x half> %{{.*}}, <16 x half> %{{.*}})
+half4x4 test_smoothstep_half4x4(half4x4 p0, half4x4 p1, half4x4 p2) { return smoothstep(p0, p1, p2); }
+
+// CHECK-LABEL: test_smoothstep_float2x3
+// DXCHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <6 x float> %{{.*}}, %{{.*}}
+// DXCHECK: [[SUB1:%.*]] = fsub reassoc nnan ninf nsz arcp afn <6 x float> %{{.*}}, %{{.*}}
+// DXCHECK: [[DIV:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <6 x float> [[SUB]], [[SUB1]]
+// DXCHECK: call reassoc nnan ninf nsz arcp afn <6 x float> @llvm.dx.saturate.v6f32(<6 x float> [[DIV]])
+// DXCHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <6 x float> splat (float 2.000000e+00), %{{.*}}
+// DXCHECK: [[SUB2:%.*]] = fsub reassoc nnan ninf nsz arcp afn <6 x float> splat (float 3.000000e+00), [[MUL]]
+// DXCHECK: [[MUL1:%.*]] = fmul reassoc nnan ninf nsz arcp afn <6 x float> [[SUB2]], %{{.*}}
+// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> [[MUL1]], %{{.*}}
+// SPVCHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <6 x float> @llvm.spv.smoothstep.v6f32(<6 x float> %{{.*}}, <6 x float> %{{.*}}, <6 x float> %{{.*}})
+float2x3 test_smoothstep_float2x3(float2x3 p0, float2x3 p1, float2x3 p2) { return smoothstep(p0, p1, p2); }
+
+// CHECK-LABEL: test_smoothstep_float3x4
+// DXCHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <12 x float> %{{.*}}, %{{.*}}
+// DXCHECK: [[SUB1:%.*]] = fsub reassoc nnan ninf nsz arcp afn <12 x float> %{{.*}}, %{{.*}}
+// DXCHECK: [[DIV:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <12 x float> [[SUB]], [[SUB1]]
+// DXCHECK: call reassoc nnan ninf nsz arcp afn <12 x float> @llvm.dx.saturate.v12f32(<12 x float> [[DIV]])
+// DXCHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <12 x float> splat (float 2.000000e+00), %{{.*}}
+// DXCHECK: [[SUB2:%.*]] = fsub reassoc nnan ninf nsz arcp afn <12 x float> splat (float 3.000000e+00), [[MUL]]
+// DXCHECK: [[MUL1:%.*]] = fmul reassoc nnan ninf nsz arcp afn <12 x float> [[SUB2]], %{{.*}}
+// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> [[MUL1]], %{{.*}}
+// SPVCHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <12 x float> @llvm.spv.smoothstep.v12f32(<12 x float> %{{.*}}, <12 x float> %{{.*}}, <12 x float> %{{.*}})
+float3x4 test_smoothstep_float3x4(float3x4 p0, float3x4 p1, float3x4 p2) { return smoothstep(p0, p1, p2); }
+
+// CHECK-LABEL: test_smoothstep_float4x4
+// DXCHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <16 x float> %{{.*}}, %{{.*}}
+// DXCHECK: [[SUB1:%.*]] = fsub reassoc nnan ninf nsz arcp afn <16 x float> %{{.*}}, %{{.*}}
+// DXCHECK: [[DIV:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <16 x float> [[SUB]], [[SUB1]]
+// DXCHECK: call reassoc nnan ninf nsz arcp afn <16 x float> @llvm.dx.saturate.v16f32(<16 x float> [[DIV]])
+// DXCHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <16 x float> splat (float 2.000000e+00), %{{.*}}
+// DXCHECK: [[SUB2:%.*]] = fsub reassoc nnan ninf nsz arcp afn <16 x float> splat (float 3.000000e+00), [[MUL]]
+// DXCHECK: [[MUL1:%.*]] = fmul reassoc nnan ninf nsz arcp afn <16 x float> [[SUB2]], %{{.*}}
+// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <16 x float> [[MUL1]], %{{.*}}
+// SPVCHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <16 x float> @llvm.spv.smoothstep.v16f32(<16 x float> %{{.*}}, <16 x float> %{{.*}}, <16 x float> %{{.*}})
+float4x4 test_smoothstep_float4x4(float4x4 p0, float4x4 p1, float4x4 p2) { return smoothstep(p0, p1, p2); }

diff  --git a/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl
index 42f5f188570b61..096501006d5595 100644
--- a/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/smoothstep-errors.hlsl
@@ -3,21 +3,21 @@
 float test_no_second_arg(float2 p0) {
   return smoothstep(p0);
   // expected-error at -1 {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 1 was provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 38 {{candidate function not viable: requires 3 arguments, but 1 was provided}}
   // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
 }
 
 float test_no_third_arg(float2 p0) {
   return smoothstep(p0, p0);
   // expected-error at -1 {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 2 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 38 {{candidate function not viable: requires 3 arguments, but 2 were provided}}
   // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
 }
 
 float test_too_many_arg(float2 p0) {
   return smoothstep(p0, p0, p0, p0);
   // expected-error at -1 {{no matching function for call to 'smoothstep'}}
-  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 3 arguments, but 4 were provided}}
+  // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 38 {{candidate function not viable: requires 3 arguments, but 4 were provided}}
   // expected-note at hlsl/hlsl_inline_intrinsics_gen.inc:* 2 {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
 }
 


        


More information about the cfe-commits mailing list