Author: Kaitlin Peng Date: 2026-11-20T14:26:29-08:00 New Revision: cfb864f4099ce43c60ff81034411a408f934dda9
URL: https://github.com/llvm/llvm-project/commit/cfb864f4099ce43c60ff81034411a408f934dda9 DIFF: https://github.com/llvm/llvm-project/commit/cfb864f4099ce43c60ff81034411a408f934dda9.diff LOG: [Matrix] Implement matrix support for the `fmod` intrinsic (#244440) Closes #184481. This PR implements the matrix api for `fmod` and adds matrix codegen tests and matrix sema tests. 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/fmod_mat.hlsl clang/test/SemaHLSL/BuiltIns/fmod_mat-errors.hlsl Modified: clang/include/clang/Basic/HLSLIntrinsics.td clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl Removed: ################################################################################ diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td index 44ba16f899dff6..a76d11f7b0768f 100644 --- a/clang/include/clang/Basic/HLSLIntrinsics.td +++ b/clang/include/clang/Basic/HLSLIntrinsics.td @@ -1003,7 +1003,7 @@ parameter. let VaryingScalar = 1; let VaryingVecSizes = [2, 3, 4]; let VaryingLongVector = 1; - let VaryingMatDims = []; + let VaryingMatDims = AllMatDims; } // Returns the fractional (or decimal) part of x. diff --git a/clang/test/CodeGenHLSL/builtins/fmod_mat.hlsl b/clang/test/CodeGenHLSL/builtins/fmod_mat.hlsl new file mode 100644 index 00000000000000..dfd9173027201d --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/fmod_mat.hlsl @@ -0,0 +1,68 @@ +// 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_fmod_half2x3 +// DXCHECK: fdiv reassoc nnan ninf nsz arcp afn <6 x half> %{{.*}}, %{{.*}} +// DXCHECK: [[ABS:%.*]] = call reassoc nnan ninf nsz arcp afn <6 x half> @llvm.fabs.v6f16(<6 x half> %{{.*}}) +// DXCHECK: call reassoc nnan ninf nsz arcp afn <6 x half> @llvm.dx.frac.v6f16(<6 x half> [[ABS]]) +// DXCHECK: [[CMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn oge <6 x half> %{{.*}}, zeroinitializer +// DXCHECK: [[NEG:%.*]] = fneg reassoc nnan ninf nsz arcp afn <6 x half> %{{.*}} +// DXCHECK: [[SEL:%.*]] = select reassoc nnan ninf nsz arcp afn <6 x i1> [[CMP]], <6 x half> %{{.*}}, <6 x half> [[NEG]] +// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> [[SEL]], %{{.*}} +// SPVCHECK: frem reassoc nnan ninf nsz arcp afn <6 x half> %{{.*}}, %{{.*}} +half2x3 test_fmod_half2x3(half2x3 p0, half2x3 p1) { return fmod(p0, p1); } + +// CHECK-LABEL: test_fmod_half3x4 +// DXCHECK: fdiv reassoc nnan ninf nsz arcp afn <12 x half> %{{.*}}, %{{.*}} +// DXCHECK: [[ABS:%.*]] = call reassoc nnan ninf nsz arcp afn <12 x half> @llvm.fabs.v12f16(<12 x half> %{{.*}}) +// DXCHECK: call reassoc nnan ninf nsz arcp afn <12 x half> @llvm.dx.frac.v12f16(<12 x half> [[ABS]]) +// DXCHECK: [[CMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn oge <12 x half> %{{.*}}, zeroinitializer +// DXCHECK: [[NEG:%.*]] = fneg reassoc nnan ninf nsz arcp afn <12 x half> %{{.*}} +// DXCHECK: [[SEL:%.*]] = select reassoc nnan ninf nsz arcp afn <12 x i1> [[CMP]], <12 x half> %{{.*}}, <12 x half> [[NEG]] +// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> [[SEL]], %{{.*}} +// SPVCHECK: frem reassoc nnan ninf nsz arcp afn <12 x half> %{{.*}}, %{{.*}} +half3x4 test_fmod_half3x4(half3x4 p0, half3x4 p1) { return fmod(p0, p1); } + +// CHECK-LABEL: test_fmod_half4x4 +// DXCHECK: fdiv reassoc nnan ninf nsz arcp afn <16 x half> %{{.*}}, %{{.*}} +// DXCHECK: [[ABS:%.*]] = call reassoc nnan ninf nsz arcp afn <16 x half> @llvm.fabs.v16f16(<16 x half> %{{.*}}) +// DXCHECK: call reassoc nnan ninf nsz arcp afn <16 x half> @llvm.dx.frac.v16f16(<16 x half> [[ABS]]) +// DXCHECK: [[CMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn oge <16 x half> %{{.*}}, zeroinitializer +// DXCHECK: [[NEG:%.*]] = fneg reassoc nnan ninf nsz arcp afn <16 x half> %{{.*}} +// DXCHECK: [[SEL:%.*]] = select reassoc nnan ninf nsz arcp afn <16 x i1> [[CMP]], <16 x half> %{{.*}}, <16 x half> [[NEG]] +// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <16 x half> [[SEL]], %{{.*}} +// SPVCHECK: frem reassoc nnan ninf nsz arcp afn <16 x half> %{{.*}}, %{{.*}} +half4x4 test_fmod_half4x4(half4x4 p0, half4x4 p1) { return fmod(p0, p1); } + +// CHECK-LABEL: test_fmod_float2x3 +// DXCHECK: fdiv reassoc nnan ninf nsz arcp afn <6 x float> %{{.*}}, %{{.*}} +// DXCHECK: [[ABS:%.*]] = call reassoc nnan ninf nsz arcp afn <6 x float> @llvm.fabs.v6f32(<6 x float> %{{.*}}) +// DXCHECK: call reassoc nnan ninf nsz arcp afn <6 x float> @llvm.dx.frac.v6f32(<6 x float> [[ABS]]) +// DXCHECK: [[CMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn oge <6 x float> %{{.*}}, zeroinitializer +// DXCHECK: [[NEG:%.*]] = fneg reassoc nnan ninf nsz arcp afn <6 x float> %{{.*}} +// DXCHECK: [[SEL:%.*]] = select reassoc nnan ninf nsz arcp afn <6 x i1> [[CMP]], <6 x float> %{{.*}}, <6 x float> [[NEG]] +// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> [[SEL]], %{{.*}} +// SPVCHECK: frem reassoc nnan ninf nsz arcp afn <6 x float> %{{.*}}, %{{.*}} +float2x3 test_fmod_float2x3(float2x3 p0, float2x3 p1) { return fmod(p0, p1); } + +// CHECK-LABEL: test_fmod_float3x4 +// DXCHECK: fdiv reassoc nnan ninf nsz arcp afn <12 x float> %{{.*}}, %{{.*}} +// DXCHECK: [[ABS:%.*]] = call reassoc nnan ninf nsz arcp afn <12 x float> @llvm.fabs.v12f32(<12 x float> %{{.*}}) +// DXCHECK: call reassoc nnan ninf nsz arcp afn <12 x float> @llvm.dx.frac.v12f32(<12 x float> [[ABS]]) +// DXCHECK: [[CMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn oge <12 x float> %{{.*}}, zeroinitializer +// DXCHECK: [[NEG:%.*]] = fneg reassoc nnan ninf nsz arcp afn <12 x float> %{{.*}} +// DXCHECK: [[SEL:%.*]] = select reassoc nnan ninf nsz arcp afn <12 x i1> [[CMP]], <12 x float> %{{.*}}, <12 x float> [[NEG]] +// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> [[SEL]], %{{.*}} +// SPVCHECK: frem reassoc nnan ninf nsz arcp afn <12 x float> %{{.*}}, %{{.*}} +float3x4 test_fmod_float3x4(float3x4 p0, float3x4 p1) { return fmod(p0, p1); } + +// CHECK-LABEL: test_fmod_float4x4 +// DXCHECK: fdiv reassoc nnan ninf nsz arcp afn <16 x float> %{{.*}}, %{{.*}} +// DXCHECK: [[ABS:%.*]] = call reassoc nnan ninf nsz arcp afn <16 x float> @llvm.fabs.v16f32(<16 x float> %{{.*}}) +// DXCHECK: call reassoc nnan ninf nsz arcp afn <16 x float> @llvm.dx.frac.v16f32(<16 x float> [[ABS]]) +// DXCHECK: [[CMP:%.*]] = fcmp reassoc nnan ninf nsz arcp afn oge <16 x float> %{{.*}}, zeroinitializer +// DXCHECK: [[NEG:%.*]] = fneg reassoc nnan ninf nsz arcp afn <16 x float> %{{.*}} +// DXCHECK: [[SEL:%.*]] = select reassoc nnan ninf nsz arcp afn <16 x i1> [[CMP]], <16 x float> %{{.*}}, <16 x float> [[NEG]] +// DXCHECK: fmul reassoc nnan ninf nsz arcp afn <16 x float> [[SEL]], %{{.*}} +// SPVCHECK: frem reassoc nnan ninf nsz arcp afn <16 x float> %{{.*}}, %{{.*}} +float4x4 test_fmod_float4x4(float4x4 p0, float4x4 p1) { return fmod(p0, p1); } diff --git a/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl index dc1039b1cd831f..e4b80935d8bca6 100644 --- a/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl @@ -3,13 +3,13 @@ float test_no_second_arg(float2 p0) { return fmod(p0); // expected-error@-1 {{no matching function for call to 'fmod'}} - // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 1 was provided}} + // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 38 {{candidate function not viable: requires 2 arguments, but 1 was provided}} } float test_too_many_arg(float2 p0) { return fmod(p0, p0, p0); // expected-error@-1 {{no matching function for call to 'fmod'}} - // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 8 {{candidate function not viable: requires 2 arguments, but 3 were provided}} + // expected-note@hlsl/hlsl_inline_intrinsics_gen.inc:* 38 {{candidate function not viable: requires 2 arguments, but 3 were provided}} } float test_double_inputs(double p0, double p1) { diff --git a/clang/test/SemaHLSL/BuiltIns/fmod_mat-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/fmod_mat-errors.hlsl new file mode 100644 index 00000000000000..4089a08dba8b64 --- /dev/null +++ b/clang/test/SemaHLSL/BuiltIns/fmod_mat-errors.hlsl @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -fnative-int16-type -emit-llvm-only -disable-llvm-passes -verify + +float2x2 test_too_few_arg(float2x2 p0) { + return __builtin_elementwise_fmod(p0); + // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} +} + +float2x2 test_too_many_arg(float2x2 p0) { + return __builtin_elementwise_fmod(p0, p0, p0); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +int2x2 test_int_mat(int2x2 p0) { + return __builtin_elementwise_fmod(p0, p0); + // expected-error@-1 {{1st argument must be a scalar or vector of floating-point types (was 'int2x2' (aka 'matrix<int, 2, 2>'))}} +} + +float2x2 test_mismatched_dims(float2x2 p0, float3x3 p1) { + return __builtin_elementwise_fmod(p0, p1); + // expected-error@-1 {{arguments are of diff erent types ('matrix<[...], 2, 2>' vs 'matrix<[...], 3, 3>')}} +} + +float2x2 test_mismatched_element_types(float2x2 p0, half2x2 p1) { + return __builtin_elementwise_fmod(p0, p1); + // expected-error@-1 {{arguments are of diff erent types ('matrix<float, [2 * ...]>' vs 'matrix<half, [2 * ...]>')}} +} + +float2x2 test_scalar_and_matrix(float p0, float2x2 p1) { + return __builtin_elementwise_fmod(p0, p1); + // expected-error@-1 {{arguments are of diff erent types ('float' vs 'float2x2' (aka 'matrix<float, 2, 2>'))}} +} + +float2x2 test_vector_and_matrix(float2 p0, float2x2 p1) { + return __builtin_elementwise_fmod(p0, p1); + // expected-error@-1 {{arguments are of diff erent types ('float2' (aka 'vector<float, 2>') vs 'float2x2' (aka 'matrix<float, 2, 2>'))}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
