https://github.com/kmpeng created https://github.com/llvm/llvm-project/pull/243653
Closes #184484. This PR implements the matrix api for `ldexp` and adds matrix codegen tests. Matrix sema tests were not added because `ldexp` has no builtin. Matrix backend tests were not added because no DirectX or SPIRV backend changes were made. Assisted-by: Claude Opus 5.5 >From 3f0429a6a9f93fdaea28bdfde71cd3ec6426534a Mon Sep 17 00:00:00 2001 From: kmpeng <[email protected]> Date: Tue, 17 Nov 2026 15:26:12 -0800 Subject: [PATCH] ldexp matrix implementation and test --- clang/include/clang/Basic/HLSLIntrinsics.td | 2 +- .../test/CodeGenHLSL/builtins/ldexp_mat.hlsl | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenHLSL/builtins/ldexp_mat.hlsl diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td index 1ef0227e70240f..c0cb6606b395f7 100644 --- a/clang/include/clang/Basic/HLSLIntrinsics.td +++ b/clang/include/clang/Basic/HLSLIntrinsics.td @@ -1190,7 +1190,7 @@ This function uses the following formula: X * 2^Exp let VaryingScalar = 1; let VaryingVecSizes = [2, 3, 4]; let VaryingLongVector = 1; - let VaryingMatDims = []; + let VaryingMatDims = AllMatDims; } // Returns the length of the specified floating-point vector. diff --git a/clang/test/CodeGenHLSL/builtins/ldexp_mat.hlsl b/clang/test/CodeGenHLSL/builtins/ldexp_mat.hlsl new file mode 100644 index 00000000000000..d810da4b883e57 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/ldexp_mat.hlsl @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s + +// CHECK-LABEL: test_ldexp_half2x3 +// CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <6 x half> @llvm.exp2.v6f16(<6 x half> %{{.*}}) +// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x half> [[EXP2]], %{{.*}} +half2x3 test_ldexp_half2x3(half2x3 p0, half2x3 p1) { return ldexp(p0, p1); } + +// CHECK-LABEL: test_ldexp_half3x4 +// CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <12 x half> @llvm.exp2.v12f16(<12 x half> %{{.*}}) +// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x half> [[EXP2]], %{{.*}} +half3x4 test_ldexp_half3x4(half3x4 p0, half3x4 p1) { return ldexp(p0, p1); } + +// CHECK-LABEL: test_ldexp_half4x4 +// CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <16 x half> @llvm.exp2.v16f16(<16 x half> %{{.*}}) +// CHECK: fmul reassoc nnan ninf nsz arcp afn <16 x half> [[EXP2]], %{{.*}} +half4x4 test_ldexp_half4x4(half4x4 p0, half4x4 p1) { return ldexp(p0, p1); } + +// CHECK-LABEL: test_ldexp_float2x3 +// CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <6 x float> @llvm.exp2.v6f32(<6 x float> %{{.*}}) +// CHECK: fmul reassoc nnan ninf nsz arcp afn <6 x float> [[EXP2]], %{{.*}} +float2x3 test_ldexp_float2x3(float2x3 p0, float2x3 p1) { return ldexp(p0, p1); } + +// CHECK-LABEL: test_ldexp_float3x4 +// CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <12 x float> @llvm.exp2.v12f32(<12 x float> %{{.*}}) +// CHECK: fmul reassoc nnan ninf nsz arcp afn <12 x float> [[EXP2]], %{{.*}} +float3x4 test_ldexp_float3x4(float3x4 p0, float3x4 p1) { return ldexp(p0, p1); } + +// CHECK-LABEL: test_ldexp_float4x4 +// CHECK: [[EXP2:%.*]] = call reassoc nnan ninf nsz arcp afn <16 x float> @llvm.exp2.v16f32(<16 x float> %{{.*}}) +// CHECK: fmul reassoc nnan ninf nsz arcp afn <16 x float> [[EXP2]], %{{.*}} +float4x4 test_ldexp_float4x4(float4x4 p0, float4x4 p1) { return ldexp(p0, p1); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
