https://github.com/kmpeng created https://github.com/llvm/llvm-project/pull/215692
Closes #213097. This PR replaces the previous implementation of `lerp` with a new one inside the header files. It also cleans up the tests to use 3 distinct parameters (x, y, s) for consistency with other similar tests. The SPIRV intrinsic (`int_spv_lerp`) and its lowering are intentionally kept, since a follow-up will pattern match `X + S * (Y - X)` back to the extended instruction and needs the SPIRV intrinsic to do so. Assisted-by: Claude Opus 4.8 >From e768703296a2ed4e0a81ef50ae728da3e17dc35f Mon Sep 17 00:00:00 2001 From: kmpeng <[email protected]> Date: Tue, 11 Aug 2026 15:46:13 -0700 Subject: [PATCH] move `lerp` implementation --- clang/include/clang/Basic/Builtins.td | 6 - clang/include/clang/Basic/HLSLIntrinsics.td | 3 +- clang/lib/CodeGen/CGHLSLBuiltins.cpp | 10 - clang/lib/CodeGen/CGHLSLRuntime.h | 1 - .../lib/Headers/hlsl/hlsl_intrinsic_helpers.h | 4 + clang/lib/Sema/SemaHLSL.cpp | 12 - .../CodeGenHLSL/builtins/lerp-builtin.hlsl | 12 - .../CodeGenHLSL/builtins/lerp-overloads.hlsl | 296 +++++++++++------- clang/test/CodeGenHLSL/builtins/lerp.hlsl | 113 +++---- clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl | 130 -------- llvm/include/llvm/IR/IntrinsicsDirectX.td | 3 - .../Target/DirectX/DXILIntrinsicExpansion.cpp | 14 - llvm/test/CodeGen/DirectX/lerp.ll | 56 ---- 13 files changed, 243 insertions(+), 417 deletions(-) delete mode 100644 clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl delete mode 100644 clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl delete mode 100644 llvm/test/CodeGen/DirectX/lerp.ll diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index a54f91069acd0..ab39f535edd8b 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -5707,12 +5707,6 @@ def HLSLIsnan : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } -def HLSLLerp : LangBuiltin<"HLSL_LANG"> { - let Spellings = ["__builtin_hlsl_lerp"]; - let Attributes = [NoThrow, Const, CustomTypeChecking]; - let Prototype = "void(...)"; -} - def HLSLMad : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_mad"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td index 4373d04ab2f22..6027fba17e15f 100644 --- a/clang/include/clang/Basic/HLSLIntrinsics.td +++ b/clang/include/clang/Basic/HLSLIntrinsics.td @@ -1143,7 +1143,7 @@ Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...). } // Returns the linear interpolation of x to y by s. -def hlsl_lerp : HLSLThreeArgBuiltin<"lerp", "__builtin_hlsl_lerp"> { +def hlsl_lerp : HLSLThreeArgDetail<"lerp", "lerp_impl"> { let Doc = [{ \fn T lerp(T x, T y, T s) \brief Returns the linear interpolation of x to y by s. @@ -1155,6 +1155,7 @@ the y parameter. Linear interpolation is based on the following formula: x*(1-s) + y*s which can equivalently be written as x + s(y-x). }]; + let ParamNames = ["x", "y", "s"]; let VaryingTypes = [HalfTy, FloatTy]; let VaryingMatDims = []; } diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index 8df92da988f65..137fba2cff1bc 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -1137,16 +1137,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, CGM.getHLSLRuntime().getFirstBitLowIntrinsic(), ArrayRef<Value *>{X}, nullptr, "hlsl.firstbitlow"); } - case Builtin::BI__builtin_hlsl_lerp: { - Value *X = EmitScalarExpr(E->getArg(0)); - Value *Y = EmitScalarExpr(E->getArg(1)); - Value *S = EmitScalarExpr(E->getArg(2)); - if (!E->getArg(0)->getType()->hasFloatingRepresentation()) - llvm_unreachable("lerp operand must have a float representation"); - return Builder.CreateIntrinsic( - /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(), - ArrayRef<Value *>{X, Y, S}, nullptr, "hlsl.lerp"); - } case Builtin::BI__builtin_hlsl_normalize: { Value *X = EmitScalarExpr(E->getArg(0)); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index f5674b64d0041..28e8798202807 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -129,7 +129,6 @@ class CGHLSLRuntime { flattened_thread_id_in_group) GENERATE_HLSL_INTRINSIC_FUNCTION(IsInf, isinf) GENERATE_HLSL_INTRINSIC_FUNCTION(IsNaN, isnan) - GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp) GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize) GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt) GENERATE_HLSL_INTRINSIC_FUNCTION(Saturate, saturate) diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h index 0b6adc66c672a..d96199f206504 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h @@ -120,6 +120,10 @@ template <typename T> constexpr T step_impl(T Y, T X) { return select(X < Y, (T)0, (T)1); } +template <typename T> constexpr T lerp_impl(T X, T Y, T S) { + return X + S * (Y - X); +} + 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); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 4c9ef04da609b..89ff1061d65a5 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -4466,18 +4466,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { SetElementTypeAsReturnType(&SemaRef, TheCall, getASTContext().BoolTy); break; } - case Builtin::BI__builtin_hlsl_lerp: { - if (SemaRef.checkArgCount(TheCall, 3)) - return true; - if (CheckAllArgTypesAreCorrect(&SemaRef, TheCall, - CheckFloatOrHalfRepresentation)) - return true; - if (CheckAllArgsHaveSameType(&SemaRef, TheCall)) - return true; - if (SemaRef.BuiltinElementwiseTernaryMath(TheCall)) - return true; - break; - } case Builtin::BI__builtin_hlsl_mad: { if (SemaRef.BuiltinElementwiseTernaryMath( TheCall, /*ArgTyRestr=*/ diff --git a/clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl b/clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl deleted file mode 100644 index cb8634c9234e3..0000000000000 --- a/clang/test/CodeGenHLSL/builtins/lerp-builtin.hlsl +++ /dev/null @@ -1,12 +0,0 @@ -// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s - - -// CHECK-LABEL: builtin_lerp_half -// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn half @llvm.dx.lerp.f16(half %{{.*}}, half %{{.*}}, half %{{.*}}) -// CHECK: ret half %hlsl.lerp -half builtin_lerp_half(half p0) { return __builtin_hlsl_lerp(p0, p0, p0); } - -// CHECK-LABEL: builtin_lerp_float -// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn float @llvm.dx.lerp.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}) -// CHECK: ret float %hlsl.lerp -float builtin_lerp_float(float p0) { return __builtin_hlsl_lerp(p0, p0, p0); } diff --git a/clang/test/CodeGenHLSL/builtins/lerp-overloads.hlsl b/clang/test/CodeGenHLSL/builtins/lerp-overloads.hlsl index 19a0cf46dfcdd..2e915141fac9a 100644 --- a/clang/test/CodeGenHLSL/builtins/lerp-overloads.hlsl +++ b/clang/test/CodeGenHLSL/builtins/lerp-overloads.hlsl @@ -1,181 +1,245 @@ -// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF -DFNATTRS="hidden noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF -DFNATTRS="hidden noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple spirv-unknown-vulkan-library %s -fnative-half-type -fnative-int16-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF -DFNATTRS="hidden spir_func noundef nofpclass(nan inf)" -DTARGET=spv -// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple spirv-unknown-vulkan-library %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF -DFNATTRS="hidden spir_func noundef nofpclass(nan inf)" -DTARGET=spv +// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm \ +// RUN: -Wdeprecated-declarations -o - | FileCheck %s +// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s \ +// RUN: -verify -verify-ignore-unexpected=note -// CHECK: define [[FNATTRS]] float @_Z16test_lerp_doubled( +// CHECK-LABEL: test_lerp_double // CHECK: [[CONV0:%.*]] = fptrunc {{.*}} double %{{.*}} to float // CHECK: [[CONV1:%.*]] = fptrunc {{.*}} double %{{.*}} to float // CHECK: [[CONV2:%.*]] = fptrunc {{.*}} double %{{.*}} to float -// CHECK: [[LERP:%.*]] = call {{.*}} float @llvm.[[TARGET]].lerp.f32(float [[CONV0]], float [[CONV1]], float [[CONV2]]) -// CHECK: ret float [[LERP]] -float test_lerp_double(double p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <2 x float> @_Z17test_lerp_double2Dv2_d( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn float %{{.*}}, [[MUL]] +// CHECK: ret float [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x 64 bit API lowering for lerp is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} +float test_lerp_double(double x, double y, double s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_double2 // CHECK: [[CONV0:%.*]] = fptrunc {{.*}} <2 x double> %{{.*}} to <2 x float> // CHECK: [[CONV1:%.*]] = fptrunc {{.*}} <2 x double> %{{.*}} to <2 x float> // CHECK: [[CONV2:%.*]] = fptrunc {{.*}} <2 x double> %{{.*}} to <2 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> [[CONV0]], <2 x float> [[CONV1]], <2 x float> [[CONV2]]) -// CHECK: ret <2 x float> [[LERP]] -float2 test_lerp_double2(double2 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <3 x float> @_Z17test_lerp_double3Dv3_d( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[MUL]] +// CHECK: ret <2 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x 64 bit API lowering for lerp is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} +float2 test_lerp_double2(double2 x, double2 y, double2 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_double3 // CHECK: [[CONV0:%.*]] = fptrunc {{.*}} <3 x double> %{{.*}} to <3 x float> // CHECK: [[CONV1:%.*]] = fptrunc {{.*}} <3 x double> %{{.*}} to <3 x float> // CHECK: [[CONV2:%.*]] = fptrunc {{.*}} <3 x double> %{{.*}} to <3 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> [[CONV0]], <3 x float> [[CONV1]], <3 x float> [[CONV2]]) -// CHECK: ret <3 x float> [[LERP]] -float3 test_lerp_double3(double3 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <4 x float> @_Z17test_lerp_double4Dv4_d( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[MUL]] +// CHECK: ret <3 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x 64 bit API lowering for lerp is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} +float3 test_lerp_double3(double3 x, double3 y, double3 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_double4 // CHECK: [[CONV0:%.*]] = fptrunc {{.*}} <4 x double> %{{.*}} to <4 x float> // CHECK: [[CONV1:%.*]] = fptrunc {{.*}} <4 x double> %{{.*}} to <4 x float> // CHECK: [[CONV2:%.*]] = fptrunc {{.*}} <4 x double> %{{.*}} to <4 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> [[CONV0]], <4 x float> [[CONV1]], <4 x float> [[CONV2]]) -// CHECK: ret <4 x float> [[LERP]] -float4 test_lerp_double4(double4 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] float @_Z13test_lerp_inti( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[MUL]] +// CHECK: ret <4 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x 64 bit API lowering for lerp is deprecated. Explicitly cast parameters to 32 or 16 bit types.}} +float4 test_lerp_double4(double4 x, double4 y, double4 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int // CHECK: [[CONV0:%.*]] = sitofp {{.*}} i32 %{{.*}} to float // CHECK: [[CONV1:%.*]] = sitofp {{.*}} i32 %{{.*}} to float // CHECK: [[CONV2:%.*]] = sitofp {{.*}} i32 %{{.*}} to float -// CHECK: [[LERP:%.*]] = call {{.*}} float @llvm.[[TARGET]].lerp.f32(float [[CONV0]], float [[CONV1]], float [[CONV2]]) -// CHECK: ret float [[LERP]] -float test_lerp_int(int p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <2 x float> @_Z14test_lerp_int2Dv2_i( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn float %{{.*}}, [[MUL]] +// CHECK: ret float [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float test_lerp_int(int x, int y, int s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int2 // CHECK: [[CONV0:%.*]] = sitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> // CHECK: [[CONV1:%.*]] = sitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> // CHECK: [[CONV2:%.*]] = sitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> [[CONV0]], <2 x float> [[CONV1]], <2 x float> [[CONV2]]) -// CHECK: ret <2 x float> [[LERP]] -float2 test_lerp_int2(int2 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <3 x float> @_Z14test_lerp_int3Dv3_i( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[MUL]] +// CHECK: ret <2 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float2 test_lerp_int2(int2 x, int2 y, int2 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int3 // CHECK: [[CONV0:%.*]] = sitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> // CHECK: [[CONV1:%.*]] = sitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> // CHECK: [[CONV2:%.*]] = sitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> [[CONV0]], <3 x float> [[CONV1]], <3 x float> [[CONV2]]) -// CHECK: ret <3 x float> [[LERP]] -float3 test_lerp_int3(int3 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <4 x float> @_Z14test_lerp_int4Dv4_i( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[MUL]] +// CHECK: ret <3 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float3 test_lerp_int3(int3 x, int3 y, int3 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int4 // CHECK: [[CONV0:%.*]] = sitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> // CHECK: [[CONV1:%.*]] = sitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> // CHECK: [[CONV2:%.*]] = sitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> [[CONV0]], <4 x float> [[CONV1]], <4 x float> [[CONV2]]) -// CHECK: ret <4 x float> [[LERP]] -float4 test_lerp_int4(int4 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] float @_Z14test_lerp_uintj( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[MUL]] +// CHECK: ret <4 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float4 test_lerp_int4(int4 x, int4 y, int4 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint // CHECK: [[CONV0:%.*]] = uitofp {{.*}} i32 %{{.*}} to float // CHECK: [[CONV1:%.*]] = uitofp {{.*}} i32 %{{.*}} to float // CHECK: [[CONV2:%.*]] = uitofp {{.*}} i32 %{{.*}} to float -// CHECK: [[LERP:%.*]] = call {{.*}} float @llvm.[[TARGET]].lerp.f32(float [[CONV0]], float [[CONV1]], float [[CONV2]]) -// CHECK: ret float [[LERP]] -float test_lerp_uint(uint p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <2 x float> @_Z15test_lerp_uint2Dv2_j( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn float %{{.*}}, [[MUL]] +// CHECK: ret float [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float test_lerp_uint(uint x, uint y, uint s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint2 // CHECK: [[CONV0:%.*]] = uitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> // CHECK: [[CONV1:%.*]] = uitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> // CHECK: [[CONV2:%.*]] = uitofp {{.*}} <2 x i32> %{{.*}} to <2 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> [[CONV0]], <2 x float> [[CONV1]], <2 x float> [[CONV2]]) -// CHECK: ret <2 x float> [[LERP]] -float2 test_lerp_uint2(uint2 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <3 x float> @_Z15test_lerp_uint3Dv3_j( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[MUL]] +// CHECK: ret <2 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float2 test_lerp_uint2(uint2 x, uint2 y, uint2 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint3 // CHECK: [[CONV0:%.*]] = uitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> // CHECK: [[CONV1:%.*]] = uitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> // CHECK: [[CONV2:%.*]] = uitofp {{.*}} <3 x i32> %{{.*}} to <3 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> [[CONV0]], <3 x float> [[CONV1]], <3 x float> [[CONV2]]) -// CHECK: ret <3 x float> [[LERP]] -float3 test_lerp_uint3(uint3 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <4 x float> @_Z15test_lerp_uint4Dv4_j( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[MUL]] +// CHECK: ret <3 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float3 test_lerp_uint3(uint3 x, uint3 y, uint3 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint4 // CHECK: [[CONV0:%.*]] = uitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> // CHECK: [[CONV1:%.*]] = uitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> // CHECK: [[CONV2:%.*]] = uitofp {{.*}} <4 x i32> %{{.*}} to <4 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> [[CONV0]], <4 x float> [[CONV1]], <4 x float> [[CONV2]]) -// CHECK: ret <4 x float> [[LERP]] -float4 test_lerp_uint4(uint4 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] float @_Z17test_lerp_int64_tl( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[MUL]] +// CHECK: ret <4 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float4 test_lerp_uint4(uint4 x, uint4 y, uint4 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int64_t // CHECK: [[CONV0:%.*]] = sitofp {{.*}} i64 %{{.*}} to float // CHECK: [[CONV1:%.*]] = sitofp {{.*}} i64 %{{.*}} to float // CHECK: [[CONV2:%.*]] = sitofp {{.*}} i64 %{{.*}} to float -// CHECK: [[LERP:%.*]] = call {{.*}} float @llvm.[[TARGET]].lerp.f32(float [[CONV0]], float [[CONV1]], float [[CONV2]]) -// CHECK: ret float [[LERP]] -float test_lerp_int64_t(int64_t p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <2 x float> @_Z18test_lerp_int64_t2Dv2_l( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn float %{{.*}}, [[MUL]] +// CHECK: ret float [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float test_lerp_int64_t(int64_t x, int64_t y, int64_t s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int64_t2 // CHECK: [[CONV0:%.*]] = sitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> // CHECK: [[CONV1:%.*]] = sitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> // CHECK: [[CONV2:%.*]] = sitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> [[CONV0]], <2 x float> [[CONV1]], <2 x float> [[CONV2]]) -// CHECK: ret <2 x float> [[LERP]] -float2 test_lerp_int64_t2(int64_t2 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <3 x float> @_Z18test_lerp_int64_t3Dv3_l( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[MUL]] +// CHECK: ret <2 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float2 test_lerp_int64_t2(int64_t2 x, int64_t2 y, int64_t2 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int64_t3 // CHECK: [[CONV0:%.*]] = sitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> // CHECK: [[CONV1:%.*]] = sitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> // CHECK: [[CONV2:%.*]] = sitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> [[CONV0]], <3 x float> [[CONV1]], <3 x float> [[CONV2]]) -// CHECK: ret <3 x float> [[LERP]] -float3 test_lerp_int64_t3(int64_t3 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <4 x float> @_Z18test_lerp_int64_t4Dv4_l( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[MUL]] +// CHECK: ret <3 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float3 test_lerp_int64_t3(int64_t3 x, int64_t3 y, int64_t3 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_int64_t4 // CHECK: [[CONV0:%.*]] = sitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> // CHECK: [[CONV1:%.*]] = sitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> // CHECK: [[CONV2:%.*]] = sitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> [[CONV0]], <4 x float> [[CONV1]], <4 x float> [[CONV2]]) -// CHECK: ret <4 x float> [[LERP]] -float4 test_lerp_int64_t4(int64_t4 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] float @_Z18test_lerp_uint64_tm( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[MUL]] +// CHECK: ret <4 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float4 test_lerp_int64_t4(int64_t4 x, int64_t4 y, int64_t4 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint64_t // CHECK: [[CONV0:%.*]] = uitofp {{.*}} i64 %{{.*}} to float // CHECK: [[CONV1:%.*]] = uitofp {{.*}} i64 %{{.*}} to float // CHECK: [[CONV2:%.*]] = uitofp {{.*}} i64 %{{.*}} to float -// CHECK: [[LERP:%.*]] = call {{.*}} float @llvm.[[TARGET]].lerp.f32(float [[CONV0]], float [[CONV1]], float [[CONV2]]) -// CHECK: ret float [[LERP]] -float test_lerp_uint64_t(uint64_t p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <2 x float> @_Z19test_lerp_uint64_t2Dv2_m( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn float %{{.*}}, [[MUL]] +// CHECK: ret float [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float test_lerp_uint64_t(uint64_t x, uint64_t y, uint64_t s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint64_t2 // CHECK: [[CONV0:%.*]] = uitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> // CHECK: [[CONV1:%.*]] = uitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> // CHECK: [[CONV2:%.*]] = uitofp {{.*}} <2 x i64> %{{.*}} to <2 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> [[CONV0]], <2 x float> [[CONV1]], <2 x float> [[CONV2]]) -// CHECK: ret <2 x float> [[LERP]] -float2 test_lerp_uint64_t2(uint64_t2 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <3 x float> @_Z19test_lerp_uint64_t3Dv3_m( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[MUL]] +// CHECK: ret <2 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float2 test_lerp_uint64_t2(uint64_t2 x, uint64_t2 y, uint64_t2 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint64_t3 // CHECK: [[CONV0:%.*]] = uitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> // CHECK: [[CONV1:%.*]] = uitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> // CHECK: [[CONV2:%.*]] = uitofp {{.*}} <3 x i64> %{{.*}} to <3 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> [[CONV0]], <3 x float> [[CONV1]], <3 x float> [[CONV2]]) -// CHECK: ret <3 x float> [[LERP]] -float3 test_lerp_uint64_t3(uint64_t3 p0) { return lerp(p0, p0, p0); } - -// CHECK: define [[FNATTRS]] <4 x float> @_Z19test_lerp_uint64_t4Dv4_m( +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[MUL]] +// CHECK: ret <3 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float3 test_lerp_uint64_t3(uint64_t3 x, uint64_t3 y, uint64_t3 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_uint64_t4 // CHECK: [[CONV0:%.*]] = uitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> // CHECK: [[CONV1:%.*]] = uitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> // CHECK: [[CONV2:%.*]] = uitofp {{.*}} <4 x i64> %{{.*}} to <4 x float> -// CHECK: [[LERP:%.*]] = call {{.*}} <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> [[CONV0]], <4 x float> [[CONV1]], <4 x float> [[CONV2]]) -// CHECK: ret <4 x float> [[LERP]] -float4 test_lerp_uint64_t4(uint64_t4 p0) { return lerp(p0, p0, p0); } - -// NATIVE_HALF: define [[FNATTRS]] <3 x [[TY:half]]> @_Z21test_lerp_half_scalarDv3_DhS_Dh{{.*}}( -// NO_HALF: define [[FNATTRS]] <3 x [[TY:float]]> @_Z21test_lerp_half_scalarDv3_DhS_Dh( -// CHECK: [[SPLATINSERT:%.*]] = insertelement <3 x [[TY]]> poison, [[TY]] %{{.*}}, i64 0 -// CHECK: [[SPLAT:%.*]] = shufflevector <3 x [[TY]]> [[SPLATINSERT]], <3 x [[TY]]> poison, <3 x i32> zeroinitializer -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x [[TY]]> @llvm.[[TARGET]].lerp.{{.*}}(<3 x [[TY]]> {{.*}}, <3 x [[TY]]> {{.*}}, <3 x [[TY]]> [[SPLAT]]) -// CHECK: ret <3 x [[TY]]> [[LERP]] +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[MUL]] +// CHECK: ret <4 x float> [[ADD]] +// expected-warning@+1 {{'lerp' is deprecated: In 202x int lowering for lerp is deprecated. Explicitly cast parameters to float types.}} +float4 test_lerp_uint64_t4(uint64_t4 x, uint64_t4 y, uint64_t4 s) { return lerp(x, y, s); } + +// CHECK-LABEL: test_lerp_half_scalar +// CHECK: [[SPLATINSERT:%.*]] = insertelement <3 x half> poison, half %{{.*}}, i64 0 +// CHECK: [[SPLAT:%.*]] = shufflevector <3 x half> [[SPLATINSERT]], <3 x half> poison, <3 x i32> zeroinitializer +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x half> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x half> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x half> %{{.*}}, [[MUL]] +// CHECK: ret <3 x half> [[ADD]] +// expected-warning@+1 {{'lerp<half, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for lerp is deprecated. Explicitly cast parameters.}} half3 test_lerp_half_scalar(half3 x, half3 y, half s) { return lerp(x, y, s); } -// CHECK: define [[FNATTRS]] <3 x float> @_Z22test_lerp_float_scalarDv3_fS_f( +// CHECK-LABEL: test_lerp_float_scalar // CHECK: [[SPLATINSERT:%.*]] = insertelement <3 x float> poison, float %{{.*}}, i64 0 // CHECK: [[SPLAT:%.*]] = shufflevector <3 x float> [[SPLATINSERT]], <3 x float> poison, <3 x i32> zeroinitializer -// CHECK: [[LERP:%.*]] = call {{.*}} <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> {{.*}}, <3 x float> {{.*}}, <3 x float> [[SPLAT]]) -// CHECK: ret <3 x float> [[LERP]] -float3 test_lerp_float_scalar(float3 x, float3 y, float s) { - return lerp(x, y, s); -} +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[MUL]] +// CHECK: ret <3 x float> [[ADD]] +// expected-warning@+1 {{'lerp<float, 3U>' is deprecated: In 202x mismatched vector/scalar lowering for lerp is deprecated. Explicitly cast parameters.}} +float3 test_lerp_float_scalar(float3 x, float3 y, float s) { return lerp(x, y, s); } diff --git a/clang/test/CodeGenHLSL/builtins/lerp.hlsl b/clang/test/CodeGenHLSL/builtins/lerp.hlsl index 5c370f9d4921e..14594439faf75 100644 --- a/clang/test/CodeGenHLSL/builtins/lerp.hlsl +++ b/clang/test/CodeGenHLSL/builtins/lerp.hlsl @@ -1,58 +1,59 @@ // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type -fnative-int16-type \ -// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ -// RUN: --check-prefixes=CHECK,NATIVE_HALF \ -// RUN: -DFNATTRS="noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ -// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ -// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \ -// RUN: -DFNATTRS="noundef nofpclass(nan inf)" -DTARGET=dx -// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ -// RUN: spirv-unknown-vulkan-library %s -fnative-half-type -fnative-int16-type \ -// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ -// RUN: --check-prefixes=CHECK,NATIVE_HALF \ -// RUN: -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTARGET=spv -// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ -// RUN: spirv-unknown-vulkan-library %s -emit-llvm -disable-llvm-passes \ -// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \ -// RUN: -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTARGET=spv - -// NATIVE_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn half @llvm.[[TARGET]].lerp.f16(half %{{.*}}, half %{{.*}}, half %{{.*}}) -// NATIVE_HALF: ret half %hlsl.lerp -// NO_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].lerp.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}) -// NO_HALF: ret float %hlsl.lerp -half test_lerp_half(half p0) { return lerp(p0, p0, p0); } - -// NATIVE_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.[[TARGET]].lerp.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, <2 x half> %{{.*}}) -// NATIVE_HALF: ret <2 x half> %hlsl.lerp -// NO_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> %{{.*}}, <2 x float> %{{.*}}, <2 x float> %{{.*}}) -// NO_HALF: ret <2 x float> %hlsl.lerp -half2 test_lerp_half2(half2 p0) { return lerp(p0, p0, p0); } - -// NATIVE_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.[[TARGET]].lerp.v3f16(<3 x half> %{{.*}}, <3 x half> %{{.*}}, <3 x half> %{{.*}}) -// NATIVE_HALF: ret <3 x half> %hlsl.lerp -// NO_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> %{{.*}}, <3 x float> %{{.*}}, <3 x float> %{{.*}}) -// NO_HALF: ret <3 x float> %hlsl.lerp -half3 test_lerp_half3(half3 p0) { return lerp(p0, p0, p0); } - -// NATIVE_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.[[TARGET]].lerp.v4f16(<4 x half> %{{.*}}, <4 x half> %{{.*}}, <4 x half> %{{.*}}) -// NATIVE_HALF: ret <4 x half> %hlsl.lerp -// NO_HALF: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}) -// NO_HALF: ret <4 x float> %hlsl.lerp -half4 test_lerp_half4(half4 p0) { return lerp(p0, p0, p0); } - -// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].lerp.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}) -// CHECK: ret float %hlsl.lerp -float test_lerp_float(float p0) { return lerp(p0, p0, p0); } - -// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.[[TARGET]].lerp.v2f32(<2 x float> %{{.*}}, <2 x float> %{{.*}}, <2 x float> %{{.*}}) -// CHECK: ret <2 x float> %hlsl.lerp -float2 test_lerp_float2(float2 p0) { return lerp(p0, p0, p0); } - -// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.[[TARGET]].lerp.v3f32(<3 x float> %{{.*}}, <3 x float> %{{.*}}, <3 x float> %{{.*}}) -// CHECK: ret <3 x float> %hlsl.lerp -float3 test_lerp_float3(float3 p0) { return lerp(p0, p0, p0); } - -// CHECK: %hlsl.lerp = call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.[[TARGET]].lerp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}) -// CHECK: ret <4 x float> %hlsl.lerp -float4 test_lerp_float4(float4 p0) { return lerp(p0, p0, p0); } +// RUN: -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: test_lerp_half +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn half %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn half %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn half [[MUL]], %{{.*}} +// CHECK-NEXT: ret half [[ADD]] +half test_lerp_half(half p0, half p1, half p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_half2 +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x half> %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x half> %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x half> [[MUL]], %{{.*}} +// CHECK-NEXT: ret <2 x half> [[ADD]] +half2 test_lerp_half2(half2 p0, half2 p1, half2 p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_half3 +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x half> %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x half> %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x half> [[MUL]], %{{.*}} +// CHECK-NEXT: ret <3 x half> [[ADD]] +half3 test_lerp_half3(half3 p0, half3 p1, half3 p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_half4 +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x half> %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x half> %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x half> [[MUL]], %{{.*}} +// CHECK-NEXT: ret <4 x half> [[ADD]] +half4 test_lerp_half4(half4 p0, half4 p1, half4 p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_float +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn float %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn float [[MUL]], %{{.*}} +// CHECK-NEXT: ret float [[ADD]] +float test_lerp_float(float p0, float p1, float p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_float2 +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <2 x float> [[MUL]], %{{.*}} +// CHECK-NEXT: ret <2 x float> [[ADD]] +float2 test_lerp_float2(float2 p0, float2 p1, float2 p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_float3 +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <3 x float> %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <3 x float> [[MUL]], %{{.*}} +// CHECK-NEXT: ret <3 x float> [[ADD]] +float3 test_lerp_float3(float3 p0, float3 p1, float3 p2) { return lerp(p0, p1, p2); } + +// CHECK-LABEL: test_lerp_float4 +// CHECK: [[SUB:%.*]] = fsub reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, %{{.*}} +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn <4 x float> %{{.*}}, [[SUB]] +// CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nnan ninf nsz arcp afn <4 x float> [[MUL]], %{{.*}} +// CHECK-NEXT: ret <4 x float> [[ADD]] +float4 test_lerp_float4(float4 p0, float4 p1, float4 p2) { return lerp(p0, p1, p2); } diff --git a/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl deleted file mode 100644 index bc82991eb3e6b..0000000000000 --- a/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl +++ /dev/null @@ -1,130 +0,0 @@ -// 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 -verify-ignore-unexpected=note - -float2 test_no_second_arg(float2 p0) { - return __builtin_hlsl_lerp(p0); - // expected-error@-1 {{too few arguments to function call, expected 3, have 1}} -} - -float2 test_no_third_arg(float2 p0) { - return __builtin_hlsl_lerp(p0, p0); - // expected-error@-1 {{too few arguments to function call, expected 3, have 2}} -} - -float2 test_too_many_arg(float2 p0) { - return __builtin_hlsl_lerp(p0, p0, p0, p0); - // expected-error@-1 {{too many arguments to function call, expected 3, have 4}} -} - -float2 test_lerp_no_second_arg(float2 p0) { - return lerp(p0); - // expected-error@-1 {{no matching function for call to 'lerp'}} -} - -float2 test_lerp_vector_trunc_warn1(float3 p0) { - return lerp(p0, p0, p0); - // expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}} -} - -// With implicit conversions, the float2 overload is selected and float3 args -// are implicitly truncated to float2 (warnings instead of type-mismatch error). -float2 test_lerp_vector_size_mismatch1(float3 p0, float2 p1) { - return lerp(p0, p0, p1); - // expected-warning@-1 2{{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}} -} - -// With implicit conversions, the float2 overload is selected and float3 args -// are implicitly truncated to float2 (warnings instead of type-mismatch error). -float2 test_lerp_vector_size_mismatch2(float3 p0, float2 p1) { - return lerp(p0, p1, p0); - // expected-warning@-1 2{{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'vector<float, 2>' (vector of 2 'float' values)}} -} - -float2 test_lerp_builtin_vector_size_mismatch_Arg1(float3 p0, float2 p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} -} - -float2 test_lerp_builtin_vector_size_mismatch_Arg2(float3 p0, float2 p1) { - return __builtin_hlsl_lerp(p1, p0, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} -} - -float2 test_lerp_builtin_vector_size_mismatch_Arg3(float3 p0, float2 p1) { - return __builtin_hlsl_lerp(p1, p1, p0); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} -} - -float test_lerp_scalar_mismatch(float p0, half p1) { - return lerp(p1, p0, p1); - // expected-error@-1 {{call to 'lerp' is ambiguous}} -} - -float2 test_lerp_element_type_mismatch(half2 p0, float2 p1) { - return lerp(p1, p0, p1); - // expected-error@-1 {{call to 'lerp' is ambiguous}} -} - -float2 test_builtin_lerp_float2_splat(float p0, float2 p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} -} - -float2 test_builtin_lerp_float2_splat2(double p0, double2 p1) { - return __builtin_hlsl_lerp(p1, p0, p1); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double2' (aka 'vector<double, 2>'))}} -} - -float2 test_builtin_lerp_float2_splat3(double p0, double2 p1) { - return __builtin_hlsl_lerp(p1, p1, p0); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double2' (aka 'vector<double, 2>'))}} -} - -float3 test_builtin_lerp_float3_splat(float p0, float3 p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} -} - -float4 test_builtin_lerp_float4_splat(float p0, float4 p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have the same type}} -} - -float2 test_lerp_float2_int_splat(float2 p0, int p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{2nd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} -} - -float3 test_lerp_float3_int_splat(float3 p0, int p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{2nd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} -} - -float2 test_builtin_lerp_int_vect_to_float_vec_promotion(int2 p0, float p1) { - return __builtin_hlsl_lerp(p0, p1, p1); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} -} - -float test_builtin_lerp_bool_type_promotion(bool p0) { - return __builtin_hlsl_lerp(p0, p0, p0); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} -} - -float builtin_bool_to_float_type_promotion(float p0, bool p1) { - return __builtin_hlsl_lerp(p0, p0, p1); - // expected-error@-1 {{3rd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} -} - -float builtin_bool_to_float_type_promotion2(bool p0, float p1) { - return __builtin_hlsl_lerp(p1, p0, p1); - // expected-error@-1 {{2nd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} -} - -float builtin_lerp_int_to_float_promotion(float p0, int p1) { - return __builtin_hlsl_lerp(p0, p0, p1); - // expected-error@-1 {{3rd argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} -} - -float4 test_lerp_int4(int4 p0, int4 p1, int4 p2) { - return __builtin_hlsl_lerp(p0, p1, p2); - // expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int4' (aka 'vector<int, 4>'))}} -} diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td b/llvm/include/llvm/IR/IntrinsicsDirectX.td index 266f80a60b5cb..d51e8476896e1 100644 --- a/llvm/include/llvm/IR/IntrinsicsDirectX.td +++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td @@ -250,9 +250,6 @@ def int_dx_legacyf16tof32 : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0 def int_dx_legacyf32tof16 : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyfloat_ty], [IntrNoMem, IntrTriviallyScalarizable]>; -def int_dx_lerp : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>,LLVMMatchType<0>], - [IntrNoMem]>; - def int_dx_imad : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem, IntrTriviallyScalarizable]>; def int_dx_umad : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem, IntrTriviallyScalarizable]>; def int_dx_normalize : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>; diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp index c03ff3936f56b..8f03d8d82932a 100644 --- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp +++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp @@ -219,7 +219,6 @@ static bool isIntrinsicExpansion(Function &F) { case Intrinsic::dx_degrees: case Intrinsic::dx_isinf: case Intrinsic::dx_isnan: - case Intrinsic::dx_lerp: case Intrinsic::dx_normalize: case Intrinsic::dx_fdot: case Intrinsic::dx_sdot: @@ -606,16 +605,6 @@ static Value *expandAnyOrAllIntrinsic(CallInst *Orig, return Result; } -static Value *expandLerpIntrinsic(CallInst *Orig) { - Value *X = Orig->getOperand(0); - Value *Y = Orig->getOperand(1); - Value *S = Orig->getOperand(2); - IRBuilder<> Builder(Orig); - auto *V = Builder.CreateFSub(Y, X); - V = Builder.CreateFMul(S, V); - return Builder.CreateFAdd(X, V, "dx.lerp"); -} - static Value *expandLogIntrinsic(CallInst *Orig, float LogConstVal = numbers::ln2f) { Value *X = Orig->getOperand(0); @@ -1318,9 +1307,6 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) { case Intrinsic::dx_isnan: Result = expand16BitIsNaN(Orig); break; - case Intrinsic::dx_lerp: - Result = expandLerpIntrinsic(Orig); - break; case Intrinsic::dx_normalize: Result = expandNormalizeIntrinsic(Orig); break; diff --git a/llvm/test/CodeGen/DirectX/lerp.ll b/llvm/test/CodeGen/DirectX/lerp.ll deleted file mode 100644 index 9ea0861cff265..0000000000000 --- a/llvm/test/CodeGen/DirectX/lerp.ll +++ /dev/null @@ -1,56 +0,0 @@ -; RUN: opt -S -dxil-intrinsic-expansion -dxil-op-lower -mtriple=dxil-pc-shadermodel6.0-library < %s | FileCheck %s - -; Make sure dxil operation function calls for lerp are generated for float and half. - -; CHECK-LABEL: lerp_half -; CHECK: fsub half %{{.*}}, %{{.*}} -; CHECK: fmul half %{{.*}}, %{{.*}} -; CHECK: fadd half %{{.*}}, %{{.*}} -define noundef half @lerp_half(half noundef %p0) { -entry: - %p0.addr = alloca half, align 2 - store half %p0, ptr %p0.addr, align 2 - %0 = load half, ptr %p0.addr, align 2 - %1 = load half, ptr %p0.addr, align 2 - %2 = load half, ptr %p0.addr, align 2 - %dx.lerp = call half @llvm.dx.lerp.f16(half %0, half %1, half %2) - ret half %dx.lerp -} - -; CHECK-LABEL: lerp_float -; CHECK: fsub float %{{.*}}, %{{.*}} -; CHECK: fmul float %{{.*}}, %{{.*}} -; CHECK: fadd float %{{.*}}, %{{.*}} -define noundef float @lerp_float(float noundef %p0, float noundef %p1) { -entry: - %p1.addr = alloca float, align 4 - %p0.addr = alloca float, align 4 - store float %p1, ptr %p1.addr, align 4 - store float %p0, ptr %p0.addr, align 4 - %0 = load float, ptr %p0.addr, align 4 - %1 = load float, ptr %p0.addr, align 4 - %2 = load float, ptr %p0.addr, align 4 - %dx.lerp = call float @llvm.dx.lerp.f32(float %0, float %1, float %2) - ret float %dx.lerp -} - -; CHECK-LABEL: lerp_float4 -; CHECK: fsub <4 x float> %{{.*}}, %{{.*}} -; CHECK: fmul <4 x float> %{{.*}}, %{{.*}} -; CHECK: fadd <4 x float> %{{.*}}, %{{.*}} -define noundef <4 x float> @lerp_float4(<4 x float> noundef %p0, <4 x float> noundef %p1) { -entry: - %p1.addr = alloca <4 x float>, align 16 - %p0.addr = alloca <4 x float>, align 16 - store <4 x float> %p1, ptr %p1.addr, align 16 - store <4 x float> %p0, ptr %p0.addr, align 16 - %0 = load <4 x float>, ptr %p0.addr, align 16 - %1 = load <4 x float>, ptr %p0.addr, align 16 - %2 = load <4 x float>, ptr %p0.addr, align 16 - %dx.lerp = call <4 x float> @llvm.dx.lerp.v4f32(<4 x float> %0, <4 x float> %1, <4 x float> %2) - ret <4 x float> %dx.lerp -} - -declare half @llvm.dx.lerp.f16(half, half, half) -declare float @llvm.dx.lerp.f32(float, float, float) -declare <4 x float> @llvm.dx.lerp.v4f32(<4 x float>, <4 x float>, <4 x float>) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
