Author: Farzon Lotfi Date: 2024-02-29T10:40:38-08:00 New Revision: 489eadd142e858dc28e375320da774eba53d21bb
URL: https://github.com/llvm/llvm-project/commit/489eadd142e858dc28e375320da774eba53d21bb DIFF: https://github.com/llvm/llvm-project/commit/489eadd142e858dc28e375320da774eba53d21bb.diff LOG: [HLSL] Implementation of the frac intrinsic (#83315) This change implements the frontend for #70099 Builtins.td - add the frac builtin CGBuiltin.cpp - add the builtin to DirectX intrinsic mapping hlsl_intrinsics.h - add the frac api SemaChecking.cpp - add type checks for builtin IntrinsicsDirectX.td - add the frac intrinsic The backend changes for this are going to be very simple: https://github.com/llvm/llvm-project/commit/f309a0eb558b65dfaff0d1d23b7d07fb07e27121 They were not included because llvm/lib/Target/DirectX/DXIL.td is going through a major refactor. Added: clang/test/CodeGenHLSL/builtins/frac.hlsl clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl Modified: clang/include/clang/Basic/Builtins.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Headers/hlsl/hlsl_intrinsics.h clang/lib/Sema/SemaChecking.cpp clang/test/CodeGenHLSL/builtins/dot.hlsl clang/test/CodeGenHLSL/builtins/lerp.hlsl clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl clang/test/SemaHLSL/OverloadResolutionBugs.hlsl llvm/include/llvm/IR/IntrinsicsDirectX.td Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 36151b49d9363d..2c83dca248fb7d 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4536,6 +4536,12 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLFrac : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_elementwise_frac"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + def HLSLLerp : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_lerp"]; let Attributes = [NoThrow, Const]; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4ef3ac8c96cd26..4f8902e37bd3bb 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10270,7 +10270,7 @@ def err_vec_builtin_non_vector_all : Error< "all arguments to %0 must be vectors">; def err_vec_builtin_incompatible_vector_all : Error< "all arguments to %0 must have vectors of the same type">; - + def err_vec_builtin_non_vector : Error< "first two arguments to %0 must be vectors">; def err_vec_builtin_incompatible_vector : Error< diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 74ca96117793c4..98684448f4ff5c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18020,14 +18020,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, V = Builder.CreateFMul(S, V); return Builder.CreateFAdd(X, V, "dx.lerp"); } - // DXC does this via casting to float should we do the same thing? - if (Xty->isIntegerTy()) { - auto V = Builder.CreateSub(Y, X); - V = Builder.CreateMul(S, V); - return Builder.CreateAdd(X, V, "dx.lerp"); - } - // Bools should have been promoted - llvm_unreachable("Scalar Lerp is only supported on ints and floats."); + llvm_unreachable("Scalar Lerp is only supported on floats."); } // A VectorSplat should have happened assert(Xty->isVectorTy() && Yty->isVectorTy() && Sty->isVectorTy() && @@ -18041,12 +18034,24 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, E->getArg(2)->getType()->getAs<VectorType>(); // A HLSLVectorTruncation should have happend assert(XVecTy->getNumElements() == YVecTy->getNumElements() && - SVecTy->getNumElements() && + XVecTy->getNumElements() == SVecTy->getNumElements() && "Lerp requires vectors to be of the same size."); + assert(XVecTy->getElementType()->isRealFloatingType() && + XVecTy->getElementType() == YVecTy->getElementType() && + XVecTy->getElementType() == SVecTy->getElementType() && + "Lerp requires float vectors to be of the same type."); return Builder.CreateIntrinsic( /*ReturnType*/ Xty, Intrinsic::dx_lerp, ArrayRef<Value *>{X, Y, S}, nullptr, "dx.lerp"); } + case Builtin::BI__builtin_hlsl_elementwise_frac: { + Value *Op0 = EmitScalarExpr(E->getArg(0)); + if (!E->getArg(0)->getType()->hasFloatingRepresentation()) + llvm_unreachable("frac operand must have a float representation"); + return Builder.CreateIntrinsic( + /*ReturnType*/ Op0->getType(), Intrinsic::dx_frac, + ArrayRef<Value *>{Op0}, nullptr, "dx.frac"); + } } return nullptr; } diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index 1314bdefa37e7b..0aa8651ba80dc4 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -317,6 +317,38 @@ double3 floor(double3); _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor) double4 floor(double4); +//===----------------------------------------------------------------------===// +// frac builtins +//===----------------------------------------------------------------------===// + +/// \fn T frac(T x) +/// \brief Returns the fractional (or decimal) part of x. \a x parameter. +/// \param x The specified input value. +/// +/// If \a the return value is greater than or equal to 0 and less than 1. + +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +half frac(half); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +half2 frac(half2); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +half3 frac(half3); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +half4 frac(half4); + +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +float frac(float); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +float2 frac(float2); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +float3 frac(float3); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_frac) +float4 frac(float4); + //===----------------------------------------------------------------------===// // lerp builtins //===----------------------------------------------------------------------===// diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 016e9830662042..690bdaa63d058b 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5246,6 +5246,23 @@ bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) { return true; } +bool CheckAllArgsHaveFloatRepresentation(Sema *S, CallExpr *TheCall) { + QualType ExpectedType = S->Context.FloatTy; + for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) { + QualType PassedType = TheCall->getArg(i)->getType(); + if (!PassedType->hasFloatingRepresentation()) { + if (auto *VecTyA = PassedType->getAs<VectorType>()) + ExpectedType = S->Context.getVectorType( + ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind()); + S->Diag(TheCall->getArg(0)->getBeginLoc(), + diag::err_typecheck_convert_incompatible) + << PassedType << ExpectedType << 1 << 0 << 0; + return true; + } + } + return false; +} + // Note: returning true in this case results in CheckBuiltinFunctionCall // returning an ExprError bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { @@ -5259,6 +5276,13 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; break; } + case Builtin::BI__builtin_hlsl_elementwise_frac: { + if (PrepareBuiltinElementwiseMathOneArgCall(TheCall)) + return true; + if (CheckAllArgsHaveFloatRepresentation(this, TheCall)) + return true; + break; + } case Builtin::BI__builtin_hlsl_lerp: { if (checkArgCount(*this, TheCall, 3)) return true; @@ -5266,6 +5290,8 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; if (SemaBuiltinElementwiseTernaryMath(TheCall)) return true; + if (CheckAllArgsHaveFloatRepresentation(this, TheCall)) + return true; break; } } diff --git a/clang/test/CodeGenHLSL/builtins/dot.hlsl b/clang/test/CodeGenHLSL/builtins/dot.hlsl index b2c1bae31d13b1..c064d118caf3e7 100644 --- a/clang/test/CodeGenHLSL/builtins/dot.hlsl +++ b/clang/test/CodeGenHLSL/builtins/dot.hlsl @@ -9,230 +9,160 @@ #ifdef __HLSL_ENABLE_16_BIT // NATIVE_HALF: %dx.dot = mul i16 %0, %1 // NATIVE_HALF: ret i16 %dx.dot -int16_t test_dot_short ( int16_t p0, int16_t p1 ) { - return dot ( p0, p1 ); -} +int16_t test_dot_short(int16_t p0, int16_t p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call i16 @llvm.dx.dot.v2i16(<2 x i16> %0, <2 x i16> %1) // NATIVE_HALF: ret i16 %dx.dot -int16_t test_dot_short2 ( int16_t2 p0, int16_t2 p1 ) { - return dot ( p0, p1 ); -} +int16_t test_dot_short2(int16_t2 p0, int16_t2 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call i16 @llvm.dx.dot.v3i16(<3 x i16> %0, <3 x i16> %1) // NATIVE_HALF: ret i16 %dx.dot -int16_t test_dot_short3 ( int16_t3 p0, int16_t3 p1 ) { - return dot ( p0, p1 ); -} +int16_t test_dot_short3(int16_t3 p0, int16_t3 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call i16 @llvm.dx.dot.v4i16(<4 x i16> %0, <4 x i16> %1) // NATIVE_HALF: ret i16 %dx.dot -int16_t test_dot_short4 ( int16_t4 p0, int16_t4 p1 ) { - return dot ( p0, p1 ); -} +int16_t test_dot_short4(int16_t4 p0, int16_t4 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = mul i16 %0, %1 // NATIVE_HALF: ret i16 %dx.dot -uint16_t test_dot_ushort ( uint16_t p0, uint16_t p1 ) { - return dot ( p0, p1 ); -} +uint16_t test_dot_ushort(uint16_t p0, uint16_t p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call i16 @llvm.dx.dot.v2i16(<2 x i16> %0, <2 x i16> %1) // NATIVE_HALF: ret i16 %dx.dot -uint16_t test_dot_ushort2 ( uint16_t2 p0, uint16_t2 p1 ) { - return dot ( p0, p1 ); -} +uint16_t test_dot_ushort2(uint16_t2 p0, uint16_t2 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call i16 @llvm.dx.dot.v3i16(<3 x i16> %0, <3 x i16> %1) // NATIVE_HALF: ret i16 %dx.dot -uint16_t test_dot_ushort3 ( uint16_t3 p0, uint16_t3 p1 ) { - return dot ( p0, p1 ); -} +uint16_t test_dot_ushort3(uint16_t3 p0, uint16_t3 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call i16 @llvm.dx.dot.v4i16(<4 x i16> %0, <4 x i16> %1) // NATIVE_HALF: ret i16 %dx.dot -uint16_t test_dot_ushort4 ( uint16_t4 p0, uint16_t4 p1 ) { - return dot ( p0, p1 ); -} +uint16_t test_dot_ushort4(uint16_t4 p0, uint16_t4 p1) { return dot(p0, p1); } #endif // CHECK: %dx.dot = mul i32 %0, %1 // CHECK: ret i32 %dx.dot -int test_dot_int ( int p0, int p1 ) { - return dot ( p0, p1 ); -} +int test_dot_int(int p0, int p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i32 @llvm.dx.dot.v2i32(<2 x i32> %0, <2 x i32> %1) // CHECK: ret i32 %dx.dot -int test_dot_int2 ( int2 p0, int2 p1 ) { - return dot ( p0, p1 ); -} +int test_dot_int2(int2 p0, int2 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i32 @llvm.dx.dot.v3i32(<3 x i32> %0, <3 x i32> %1) // CHECK: ret i32 %dx.dot -int test_dot_int3 ( int3 p0, int3 p1 ) { - return dot ( p0, p1 ); -} +int test_dot_int3(int3 p0, int3 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i32 @llvm.dx.dot.v4i32(<4 x i32> %0, <4 x i32> %1) // CHECK: ret i32 %dx.dot -int test_dot_int4 ( int4 p0, int4 p1 ) { - return dot ( p0, p1 ); -} +int test_dot_int4(int4 p0, int4 p1) { return dot(p0, p1); } // CHECK: %dx.dot = mul i32 %0, %1 // CHECK: ret i32 %dx.dot -uint test_dot_uint ( uint p0, uint p1 ) { - return dot ( p0, p1 ); -} +uint test_dot_uint(uint p0, uint p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i32 @llvm.dx.dot.v2i32(<2 x i32> %0, <2 x i32> %1) // CHECK: ret i32 %dx.dot -uint test_dot_uint2 ( uint2 p0, uint2 p1 ) { - return dot ( p0, p1 ); -} +uint test_dot_uint2(uint2 p0, uint2 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i32 @llvm.dx.dot.v3i32(<3 x i32> %0, <3 x i32> %1) // CHECK: ret i32 %dx.dot -uint test_dot_uint3 ( uint3 p0, uint3 p1 ) { - return dot ( p0, p1 ); -} +uint test_dot_uint3(uint3 p0, uint3 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i32 @llvm.dx.dot.v4i32(<4 x i32> %0, <4 x i32> %1) // CHECK: ret i32 %dx.dot -uint test_dot_uint4 ( uint4 p0, uint4 p1 ) { - return dot ( p0, p1 ); -} +uint test_dot_uint4(uint4 p0, uint4 p1) { return dot(p0, p1); } // CHECK: %dx.dot = mul i64 %0, %1 // CHECK: ret i64 %dx.dot -int64_t test_dot_long ( int64_t p0, int64_t p1 ) { - return dot ( p0, p1 ); -} +int64_t test_dot_long(int64_t p0, int64_t p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i64 @llvm.dx.dot.v2i64(<2 x i64> %0, <2 x i64> %1) // CHECK: ret i64 %dx.dot -int64_t test_dot_long2 ( int64_t2 p0, int64_t2 p1 ) { - return dot ( p0, p1 ); -} +int64_t test_dot_long2(int64_t2 p0, int64_t2 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i64 @llvm.dx.dot.v3i64(<3 x i64> %0, <3 x i64> %1) // CHECK: ret i64 %dx.dot -int64_t test_dot_long3 ( int64_t3 p0, int64_t3 p1 ) { - return dot ( p0, p1 ); -} +int64_t test_dot_long3(int64_t3 p0, int64_t3 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i64 @llvm.dx.dot.v4i64(<4 x i64> %0, <4 x i64> %1) // CHECK: ret i64 %dx.dot -int64_t test_dot_long4 ( int64_t4 p0, int64_t4 p1 ) { - return dot ( p0, p1 ); -} +int64_t test_dot_long4(int64_t4 p0, int64_t4 p1) { return dot(p0, p1); } // CHECK: %dx.dot = mul i64 %0, %1 // CHECK: ret i64 %dx.dot -uint64_t test_dot_ulong ( uint64_t p0, uint64_t p1 ) { - return dot ( p0, p1 ); -} +uint64_t test_dot_ulong(uint64_t p0, uint64_t p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i64 @llvm.dx.dot.v2i64(<2 x i64> %0, <2 x i64> %1) // CHECK: ret i64 %dx.dot -uint64_t test_dot_ulong2 ( uint64_t2 p0, uint64_t2 p1 ) { - return dot ( p0, p1 ); -} +uint64_t test_dot_ulong2(uint64_t2 p0, uint64_t2 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i64 @llvm.dx.dot.v3i64(<3 x i64> %0, <3 x i64> %1) // CHECK: ret i64 %dx.dot -uint64_t test_dot_ulong3 ( uint64_t3 p0, uint64_t3 p1 ) { - return dot ( p0, p1 ); -} +uint64_t test_dot_ulong3(uint64_t3 p0, uint64_t3 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call i64 @llvm.dx.dot.v4i64(<4 x i64> %0, <4 x i64> %1) // CHECK: ret i64 %dx.dot -uint64_t test_dot_ulong4 ( uint64_t4 p0, uint64_t4 p1 ) { - return dot ( p0, p1 ); -} +uint64_t test_dot_ulong4(uint64_t4 p0, uint64_t4 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = fmul half %0, %1 // NATIVE_HALF: ret half %dx.dot // NO_HALF: %dx.dot = fmul float %0, %1 // NO_HALF: ret float %dx.dot -half test_dot_half ( half p0, half p1 ) { - return dot ( p0, p1 ); -} +half test_dot_half(half p0, half p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call half @llvm.dx.dot.v2f16(<2 x half> %0, <2 x half> %1) // NATIVE_HALF: ret half %dx.dot // NO_HALF: %dx.dot = call float @llvm.dx.dot.v2f32(<2 x float> %0, <2 x float> %1) // NO_HALF: ret float %dx.dot -half test_dot_half2 ( half2 p0, half2 p1 ) { - return dot ( p0, p1 ); -} +half test_dot_half2(half2 p0, half2 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call half @llvm.dx.dot.v3f16(<3 x half> %0, <3 x half> %1) // NATIVE_HALF: ret half %dx.dot // NO_HALF: %dx.dot = call float @llvm.dx.dot.v3f32(<3 x float> %0, <3 x float> %1) // NO_HALF: ret float %dx.dot -half test_dot_half3 ( half3 p0, half3 p1 ) { - return dot ( p0, p1 ); -} +half test_dot_half3(half3 p0, half3 p1) { return dot(p0, p1); } // NATIVE_HALF: %dx.dot = call half @llvm.dx.dot.v4f16(<4 x half> %0, <4 x half> %1) // NATIVE_HALF: ret half %dx.dot // NO_HALF: %dx.dot = call float @llvm.dx.dot.v4f32(<4 x float> %0, <4 x float> %1) // NO_HALF: ret float %dx.dot -half test_dot_half4 ( half4 p0, half4 p1 ) { - return dot ( p0, p1 ); -} +half test_dot_half4(half4 p0, half4 p1) { return dot(p0, p1); } // CHECK: %dx.dot = fmul float %0, %1 // CHECK: ret float %dx.dot -float test_dot_float ( float p0, float p1 ) { - return dot ( p0, p1 ); -} +float test_dot_float(float p0, float p1) { return dot(p0, p1); } // CHECK: %dx.dot = call float @llvm.dx.dot.v2f32(<2 x float> %0, <2 x float> %1) // CHECK: ret float %dx.dot -float test_dot_float2 ( float2 p0, float2 p1 ) { - return dot ( p0, p1 ); -} +float test_dot_float2(float2 p0, float2 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call float @llvm.dx.dot.v3f32(<3 x float> %0, <3 x float> %1) // CHECK: ret float %dx.dot -float test_dot_float3 ( float3 p0, float3 p1 ) { - return dot ( p0, p1 ); -} +float test_dot_float3(float3 p0, float3 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call float @llvm.dx.dot.v4f32(<4 x float> %0, <4 x float> %1) // CHECK: ret float %dx.dot -float test_dot_float4 ( float4 p0, float4 p1) { - return dot ( p0, p1 ); -} +float test_dot_float4(float4 p0, float4 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call float @llvm.dx.dot.v2f32(<2 x float> %splat.splat, <2 x float> %1) // CHECK: ret float %dx.dot -float test_dot_float2_splat ( float p0, float2 p1 ) { - return dot( p0, p1 ); -} +float test_dot_float2_splat(float p0, float2 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call float @llvm.dx.dot.v3f32(<3 x float> %splat.splat, <3 x float> %1) // CHECK: ret float %dx.dot -float test_dot_float3_splat ( float p0, float3 p1 ) { - return dot( p0, p1 ); -} +float test_dot_float3_splat(float p0, float3 p1) { return dot(p0, p1); } // CHECK: %dx.dot = call float @llvm.dx.dot.v4f32(<4 x float> %splat.splat, <4 x float> %1) // CHECK: ret float %dx.dot -float test_dot_float4_splat ( float p0, float4 p1 ) { - return dot( p0, p1 ); -} +float test_dot_float4_splat(float p0, float4 p1) { return dot(p0, p1); } // CHECK: %conv = sitofp i32 %1 to float // CHECK: %splat.splatinsert = insertelement <2 x float> poison, float %conv, i64 0 // CHECK: %splat.splat = shufflevector <2 x float> %splat.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer // CHECK: %dx.dot = call float @llvm.dx.dot.v2f32(<2 x float> %0, <2 x float> %splat.splat) // CHECK: ret float %dx.dot -float test_builtin_dot_float2_int_splat ( float2 p0, int p1 ) { - return dot ( p0, p1 ); +float test_builtin_dot_float2_int_splat(float2 p0, int p1) { + return dot(p0, p1); } // CHECK: %conv = sitofp i32 %1 to float @@ -240,26 +170,24 @@ float test_builtin_dot_float2_int_splat ( float2 p0, int p1 ) { // CHECK: %splat.splat = shufflevector <3 x float> %splat.splatinsert, <3 x float> poison, <3 x i32> zeroinitializer // CHECK: %dx.dot = call float @llvm.dx.dot.v3f32(<3 x float> %0, <3 x float> %splat.splat) // CHECK: ret float %dx.dot -float test_builtin_dot_float3_int_splat ( float3 p0, int p1 ) { - return dot ( p0, p1 ); +float test_builtin_dot_float3_int_splat(float3 p0, int p1) { + return dot(p0, p1); } // CHECK: %dx.dot = fmul double %0, %1 // CHECK: ret double %dx.dot -double test_dot_double ( double p0, double p1 ) { - return dot ( p0, p1 ); -} +double test_dot_double(double p0, double p1) { return dot(p0, p1); } // CHECK: %conv = zext i1 %tobool to i32 // CHECK: %dx.dot = mul i32 %conv, %1 // CHECK: ret i32 %dx.dot -int test_dot_bool_scalar_arg0_type_promotion ( bool p0, int p1 ) { - return dot ( p0, p1 ); +int test_dot_bool_scalar_arg0_type_promotion(bool p0, int p1) { + return dot(p0, p1); } // CHECK: %conv = zext i1 %tobool to i32 // CHECK: %dx.dot = mul i32 %0, %conv // CHECK: ret i32 %dx.dot -int test_dot_bool_scalar_arg1_type_promotion ( int p0, bool p1 ) { - return dot ( p0, p1 ); +int test_dot_bool_scalar_arg1_type_promotion(int p0, bool p1) { + return dot(p0, p1); } diff --git a/clang/test/CodeGenHLSL/builtins/frac.hlsl b/clang/test/CodeGenHLSL/builtins/frac.hlsl new file mode 100644 index 00000000000000..7c4d1468e96d27 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/frac.hlsl @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ +// RUN: --check-prefixes=CHECK,NATIVE_HALF +// 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 + +// NATIVE_HALF: define noundef half @ +// NATIVE_HALF: %dx.frac = call half @llvm.dx.frac.f16( +// NATIVE_HALF: ret half %dx.frac +// NO_HALF: define noundef float @"?test_frac_half@@YA$halff@$halff@@Z"( +// NO_HALF: %dx.frac = call float @llvm.dx.frac.f32( +// NO_HALF: ret float %dx.frac +half test_frac_half(half p0) { return frac(p0); } +// NATIVE_HALF: define noundef <2 x half> @ +// NATIVE_HALF: %dx.frac = call <2 x half> @llvm.dx.frac.v2f16 +// NATIVE_HALF: ret <2 x half> %dx.frac +// NO_HALF: define noundef <2 x float> @ +// NO_HALF: %dx.frac = call <2 x float> @llvm.dx.frac.v2f32( +// NO_HALF: ret <2 x float> %dx.frac +half2 test_frac_half2(half2 p0) { return frac(p0); } +// NATIVE_HALF: define noundef <3 x half> @ +// NATIVE_HALF: %dx.frac = call <3 x half> @llvm.dx.frac.v3f16 +// NATIVE_HALF: ret <3 x half> %dx.frac +// NO_HALF: define noundef <3 x float> @ +// NO_HALF: %dx.frac = call <3 x float> @llvm.dx.frac.v3f32( +// NO_HALF: ret <3 x float> %dx.frac +half3 test_frac_half3(half3 p0) { return frac(p0); } +// NATIVE_HALF: define noundef <4 x half> @ +// NATIVE_HALF: %dx.frac = call <4 x half> @llvm.dx.frac.v4f16 +// NATIVE_HALF: ret <4 x half> %dx.frac +// NO_HALF: define noundef <4 x float> @ +// NO_HALF: %dx.frac = call <4 x float> @llvm.dx.frac.v4f32( +// NO_HALF: ret <4 x float> %dx.frac +half4 test_frac_half4(half4 p0) { return frac(p0); } + +// CHECK: define noundef float @ +// CHECK: %dx.frac = call float @llvm.dx.frac.f32( +// CHECK: ret float %dx.frac +float test_frac_float(float p0) { return frac(p0); } +// CHECK: define noundef <2 x float> @ +// CHECK: %dx.frac = call <2 x float> @llvm.dx.frac.v2f32 +// CHECK: ret <2 x float> %dx.frac +float2 test_frac_float2(float2 p0) { return frac(p0); } +// CHECK: define noundef <3 x float> @ +// CHECK: %dx.frac = call <3 x float> @llvm.dx.frac.v3f32 +// CHECK: ret <3 x float> %dx.frac +float3 test_frac_float3(float3 p0) { return frac(p0); } +// CHECK: define noundef <4 x float> @ +// CHECK: %dx.frac = call <4 x float> @llvm.dx.frac.v4f32 +// CHECK: ret <4 x float> %dx.frac +float4 test_frac_float4(float4 p0) { return frac(p0); } diff --git a/clang/test/CodeGenHLSL/builtins/lerp.hlsl b/clang/test/CodeGenHLSL/builtins/lerp.hlsl index 1297f6b85bbd48..a6b3d9643d674c 100644 --- a/clang/test/CodeGenHLSL/builtins/lerp.hlsl +++ b/clang/test/CodeGenHLSL/builtins/lerp.hlsl @@ -14,85 +14,63 @@ // NO_HALF: %4 = fmul float %2, %3 // NO_HALF: %dx.lerp = fadd float %0, %4 // NO_HALF: ret float %dx.lerp -half test_lerp_half ( half p0) { - return lerp ( p0, p0, p0 ); -} +half test_lerp_half(half p0) { return lerp(p0, p0, p0); } // NATIVE_HALF: %dx.lerp = call <2 x half> @llvm.dx.lerp.v2f16(<2 x half> %0, <2 x half> %1, <2 x half> %2) // NATIVE_HALF: ret <2 x half> %dx.lerp // NO_HALF: %dx.lerp = call <2 x float> @llvm.dx.lerp.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %2) // NO_HALF: ret <2 x float> %dx.lerp -half2 test_lerp_half2 ( half2 p0, half2 p1 ) { - return lerp ( p0, p0, p0 ); -} +half2 test_lerp_half2(half2 p0, half2 p1) { return lerp(p0, p0, p0); } // NATIVE_HALF: %dx.lerp = call <3 x half> @llvm.dx.lerp.v3f16(<3 x half> %0, <3 x half> %1, <3 x half> %2) // NATIVE_HALF: ret <3 x half> %dx.lerp // NO_HALF: %dx.lerp = call <3 x float> @llvm.dx.lerp.v3f32(<3 x float> %0, <3 x float> %1, <3 x float> %2) // NO_HALF: ret <3 x float> %dx.lerp -half3 test_lerp_half3 ( half3 p0, half3 p1 ) { - return lerp ( p0, p0, p0 ); -} +half3 test_lerp_half3(half3 p0, half3 p1) { return lerp(p0, p0, p0); } // NATIVE_HALF: %dx.lerp = call <4 x half> @llvm.dx.lerp.v4f16(<4 x half> %0, <4 x half> %1, <4 x half> %2) // NATIVE_HALF: ret <4 x half> %dx.lerp // NO_HALF: %dx.lerp = call <4 x float> @llvm.dx.lerp.v4f32(<4 x float> %0, <4 x float> %1, <4 x float> %2) // NO_HALF: ret <4 x float> %dx.lerp -half4 test_lerp_half4 ( half4 p0, half4 p1 ) { - return lerp ( p0, p0, p0 ); -} +half4 test_lerp_half4(half4 p0, half4 p1) { return lerp(p0, p0, p0); } // CHECK: %3 = fsub float %1, %0 // CHECK: %4 = fmul float %2, %3 // CHECK: %dx.lerp = fadd float %0, %4 // CHECK: ret float %dx.lerp -float test_lerp_float ( float p0, float p1 ) { - return lerp ( p0, p0, p0 ); -} +float test_lerp_float(float p0, float p1) { return lerp(p0, p0, p0); } // CHECK: %dx.lerp = call <2 x float> @llvm.dx.lerp.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %2) // CHECK: ret <2 x float> %dx.lerp -float2 test_lerp_float2 ( float2 p0, float2 p1 ) { - return lerp ( p0, p0, p0 ); -} +float2 test_lerp_float2(float2 p0, float2 p1) { return lerp(p0, p0, p0); } // CHECK: %dx.lerp = call <3 x float> @llvm.dx.lerp.v3f32(<3 x float> %0, <3 x float> %1, <3 x float> %2) // CHECK: ret <3 x float> %dx.lerp -float3 test_lerp_float3 ( float3 p0, float3 p1 ) { - return lerp ( p0, p0, p0 ); -} +float3 test_lerp_float3(float3 p0, float3 p1) { return lerp(p0, p0, p0); } // CHECK: %dx.lerp = call <4 x float> @llvm.dx.lerp.v4f32(<4 x float> %0, <4 x float> %1, <4 x float> %2) // CHECK: ret <4 x float> %dx.lerp -float4 test_lerp_float4 ( float4 p0, float4 p1) { - return lerp ( p0, p0, p0 ); -} +float4 test_lerp_float4(float4 p0, float4 p1) { return lerp(p0, p0, p0); } // CHECK: %dx.lerp = call <2 x float> @llvm.dx.lerp.v2f32(<2 x float> %splat.splat, <2 x float> %1, <2 x float> %2) // CHECK: ret <2 x float> %dx.lerp -float2 test_lerp_float2_splat ( float p0, float2 p1 ) { - return lerp( p0, p1, p1 ); -} +float2 test_lerp_float2_splat(float p0, float2 p1) { return lerp(p0, p1, p1); } // CHECK: %dx.lerp = call <3 x float> @llvm.dx.lerp.v3f32(<3 x float> %splat.splat, <3 x float> %1, <3 x float> %2) // CHECK: ret <3 x float> %dx.lerp -float3 test_lerp_float3_splat ( float p0, float3 p1 ) { - return lerp( p0, p1, p1 ); -} +float3 test_lerp_float3_splat(float p0, float3 p1) { return lerp(p0, p1, p1); } // CHECK: %dx.lerp = call <4 x float> @llvm.dx.lerp.v4f32(<4 x float> %splat.splat, <4 x float> %1, <4 x float> %2) // CHECK: ret <4 x float> %dx.lerp -float4 test_lerp_float4_splat ( float p0, float4 p1 ) { - return lerp( p0, p1, p1 ); -} +float4 test_lerp_float4_splat(float p0, float4 p1) { return lerp(p0, p1, p1); } // CHECK: %conv = sitofp i32 %2 to float // CHECK: %splat.splatinsert = insertelement <2 x float> poison, float %conv, i64 0 // CHECK: %splat.splat = shufflevector <2 x float> %splat.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer // CHECK: %dx.lerp = call <2 x float> @llvm.dx.lerp.v2f32(<2 x float> %0, <2 x float> %1, <2 x float> %splat.splat) // CHECK: ret <2 x float> %dx.lerp -float2 test_lerp_float2_int_splat ( float2 p0, int p1 ) { - return lerp ( p0, p0, p1 ); +float2 test_lerp_float2_int_splat(float2 p0, int p1) { + return lerp(p0, p0, p1); } // CHECK: %conv = sitofp i32 %2 to float @@ -100,6 +78,6 @@ float2 test_lerp_float2_int_splat ( float2 p0, int p1 ) { // CHECK: %splat.splat = shufflevector <3 x float> %splat.splatinsert, <3 x float> poison, <3 x i32> zeroinitializer // CHECK: %dx.lerp = call <3 x float> @llvm.dx.lerp.v3f32(<3 x float> %0, <3 x float> %1, <3 x float> %splat.splat) // CHECK: ret <3 x float> %dx.lerp -float3 test_lerp_float3_int_splat ( float3 p0, int p1 ) { - return lerp ( p0, p0, p1 ); +float3 test_lerp_float3_int_splat(float3 p0, int p1) { + return lerp(p0, p0, p1); } diff --git a/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl index 5dbb52a80c6bd0..8de8f86d7eb260 100644 --- a/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl @@ -1,109 +1,110 @@ // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected -float test_no_second_arg ( float2 p0) { - return __builtin_hlsl_dot ( p0 ); +float test_no_second_arg(float2 p0) { + return __builtin_hlsl_dot(p0); // expected-error@-1 {{too few arguments to function call, expected 2, have 1}} } -float test_too_many_arg ( float2 p0) { - return __builtin_hlsl_dot ( p0, p0, p0 ); +float test_too_many_arg(float2 p0) { + return __builtin_hlsl_dot(p0, p0, p0); // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} } -float test_dot_no_second_arg ( float2 p0) { - return dot ( p0 ); +float test_dot_no_second_arg(float2 p0) { + return dot(p0); // expected-error@-1 {{no matching function for call to 'dot'}} } -float test_dot_vector_size_mismatch ( float3 p0, float2 p1 ) { - return dot ( p0, p1 ); +float test_dot_vector_size_mismatch(float3 p0, float2 p1) { + return dot(p0, p1); // expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'float __attribute__((ext_vector_type(2)))' (vector of 2 'float' values)}} } -float test_dot_builtin_vector_size_mismatch ( float3 p0, float2 p1 ) { - return __builtin_hlsl_dot ( p0, p1 ); +float test_dot_builtin_vector_size_mismatch(float3 p0, float2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } -float test_dot_scalar_mismatch ( float p0, int p1 ) { - return dot ( p0, p1 ); +float test_dot_scalar_mismatch(float p0, int p1) { + return dot(p0, p1); // expected-error@-1 {{call to 'dot' is ambiguous}} } -float test_dot_element_type_mismatch ( int2 p0, float2 p1 ) { - return dot ( p0, p1 ); +float test_dot_element_type_mismatch(int2 p0, float2 p1) { + return dot(p0, p1); // expected-error@-1 {{call to 'dot' is ambiguous}} } //NOTE: for all the *_promotion we are intentionally not handling type promotion in builtins -float test_builtin_dot_vec_int_to_float_promotion ( int2 p0, float2 p1 ) { - return __builtin_hlsl_dot ( p0, p1 ); +float test_builtin_dot_vec_int_to_float_promotion(int2 p0, float2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } -int64_t test_builtin_dot_vec_int_to_int64_promotion( int64_t2 p0, int2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +int64_t test_builtin_dot_vec_int_to_int64_promotion(int64_t2 p0, int2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } -float test_builtin_dot_vec_half_to_float_promotion( float2 p0, half2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +float test_builtin_dot_vec_half_to_float_promotion(float2 p0, half2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } #ifdef __HLSL_ENABLE_16_BIT -float test_builtin_dot_vec_int16_to_float_promotion( float2 p0, int16_t2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +float test_builtin_dot_vec_int16_to_float_promotion(float2 p0, int16_t2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } -half test_builtin_dot_vec_int16_to_half_promotion( half2 p0, int16_t2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +half test_builtin_dot_vec_int16_to_half_promotion(half2 p0, int16_t2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } -int test_builtin_dot_vec_int16_to_int_promotion( int2 p0, int16_t2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +int test_builtin_dot_vec_int16_to_int_promotion(int2 p0, int16_t2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } -int64_t test_builtin_dot_vec_int16_to_int64_promotion( int64_t2 p0, int16_t2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +int64_t test_builtin_dot_vec_int16_to_int64_promotion(int64_t2 p0, + int16_t2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have vectors of the same type}} } #endif -float test_builtin_dot_float2_splat ( float p0, float2 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +float test_builtin_dot_float2_splat(float p0, float2 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} } -float test_builtin_dot_float3_splat ( float p0, float3 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +float test_builtin_dot_float3_splat(float p0, float3 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} } -float test_builtin_dot_float4_splat ( float p0, float4 p1 ) { - return __builtin_hlsl_dot( p0, p1 ); +float test_builtin_dot_float4_splat(float p0, float4 p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} } -float test_dot_float2_int_splat ( float2 p0, int p1 ) { - return __builtin_hlsl_dot ( p0, p1 ); +float test_dot_float2_int_splat(float2 p0, int p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} } -float test_dot_float3_int_splat ( float3 p0, int p1 ) { - return __builtin_hlsl_dot ( p0, p1 ); +float test_dot_float3_int_splat(float3 p0, int p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} } -float test_builtin_dot_int_vect_to_float_vec_promotion ( int2 p0, float p1 ) { - return __builtin_hlsl_dot ( p0, p1 ); +float test_builtin_dot_int_vect_to_float_vec_promotion(int2 p0, float p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must be vectors}} } -int test_builtin_dot_bool_type_promotion ( bool p0, bool p1 ) { - return __builtin_hlsl_dot ( p0, p1 ); +int test_builtin_dot_bool_type_promotion(bool p0, bool p1) { + return __builtin_hlsl_dot(p0, p1); // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'bool')}} } diff --git a/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl new file mode 100644 index 00000000000000..06dbdf0a68dfc1 --- /dev/null +++ b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl @@ -0,0 +1,27 @@ + +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected + +float test_too_few_arg() { + return __builtin_hlsl_elementwise_frac(); + // expected-error@-1 {{too few arguments to function call, expected 1, have 0}} +} + +float2 test_too_many_arg(float2 p0) { + return __builtin_hlsl_elementwise_frac(p0, p0); + // expected-error@-1 {{too many arguments to function call, expected 1, have 2}} +} + +float builtin_bool_to_float_type_promotion(bool p1) { + return __builtin_hlsl_elementwise_frac(p1); + // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'bool')}} +} + +float builtin_frac_int_to_float_promotion(int p1) { + return __builtin_hlsl_elementwise_frac(p1); + // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} +} + +float2 builtin_frac_int2_to_float2_promotion(int2 p1) { + return __builtin_hlsl_elementwise_frac(p1); + // expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} +} diff --git a/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl index c062aa60a8df45..4ec5a4cdd26a30 100644 --- a/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/lerp-errors.hlsl @@ -1,91 +1,96 @@ // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected -float2 test_no_second_arg ( float2 p0) { - return __builtin_hlsl_lerp ( p0 ); +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 ); +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 ); +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 ); +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_size_mismatch ( float3 p0, float2 p1 ) { - return lerp ( p0, p0, p1 ); +float2 test_lerp_vector_size_mismatch(float3 p0, float2 p1) { + return lerp(p0, p0, p1); // expected-warning@-1 {{implicit conversion truncates vector: 'float3' (aka 'vector<float, 3>') to 'float __attribute__((ext_vector_type(2)))' (vector of 2 'float' values)}} } -float test_lerp_builtin_vector_size_mismatch ( float3 p0, float2 p1 ) { - return __builtin_hlsl_lerp ( p0, p1, p1 ); +float2 test_lerp_builtin_vector_size_mismatch(float3 p0, float2 p1) { + return __builtin_hlsl_lerp(p0, p1, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must have vectors of the same type}} } -float test_lerp_scalar_mismatch ( float p0, half p1 ) { - return lerp ( p1, p0, p1 ); +float test_lerp_scalar_mismatch(float p0, half p1) { + return lerp(p1, p0, p1); // expected-error@-1 {{call to 'lerp' is ambiguous}} } -float test_lerp_element_type_mismatch ( half2 p0, float2 p1 ) { - return lerp ( p1, p0, p1 ); +float2 test_lerp_element_type_mismatch(half2 p0, float2 p1) { + return lerp(p1, p0, p1); // expected-error@-1 {{call to 'lerp' is ambiguous}} } -float test_builtin_lerp_float2_splat ( float p0, float2 p1 ) { - return __builtin_hlsl_lerp( p0, p1, p1 ); +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 be vectors}} } -float test_builtin_lerp_float3_splat ( float p0, float3 p1 ) { - return __builtin_hlsl_lerp( p0, p1, p1 ); +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 be vectors}} } -float test_builtin_lerp_float4_splat ( float p0, float4 p1 ) { - return __builtin_hlsl_lerp( p0, p1, p1 ); +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 be vectors}} } -float test_lerp_float2_int_splat ( float2 p0, int p1 ) { - return __builtin_hlsl_lerp( p0, p1, p1 ); +float2 test_lerp_float2_int_splat(float2 p0, int p1) { + return __builtin_hlsl_lerp(p0, p1, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must be vectors}} } -float test_lerp_float3_int_splat ( float3 p0, int p1 ) { - return __builtin_hlsl_lerp( p0, p1, p1 ); +float3 test_lerp_float3_int_splat(float3 p0, int p1) { + return __builtin_hlsl_lerp(p0, p1, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must be vectors}} } -float test_builtin_lerp_int_vect_to_float_vec_promotion ( int2 p0, float p1 ) { - return __builtin_hlsl_lerp( p0, p1, p1 ); +float2 test_builtin_lerp_int_vect_to_float_vec_promotion(int2 p0, float p1) { + return __builtin_hlsl_lerp(p0, p1, p1); // expected-error@-1 {{all arguments to '__builtin_hlsl_lerp' must be vectors}} } -int test_builtin_lerp_bool_type_promotion (bool p0) { - return __builtin_hlsl_lerp( p0, p0, p0 ); +float test_builtin_lerp_bool_type_promotion(bool p0) { + return __builtin_hlsl_lerp(p0, p0, p0); // expected-error@-1 {{1st argument must be a floating point type (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 floating point type (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 floating point type (was 'bool')}} } -float builtin_bool_to_float_type_promotion2 ( bool p0, float p1 ) { - return __builtin_hlsl_lerp ( p1, p0, p1 ); +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 floating point type (was 'bool')}} } -float builtin_lerp_int_to_float_promotion ( float p0, int p1 ) { - return __builtin_hlsl_lerp ( p0, p0, p1 ); +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 floating point type (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 floating point type (was 'int4' (aka 'vector<int, 4>'))}} } \ No newline at end of file diff --git a/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl b/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl index 8464f1c1a7c2cd..c13cb299127aac 100644 --- a/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl +++ b/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl @@ -7,73 +7,67 @@ void Fn3(double2 D); void Fn3(float2 F); -void Call3(half2 H) { - Fn3(H); -} +void Call3(half2 H) { Fn3(H); } void Fn5(double2 D); -void Call5(half2 H) { - Fn5(H); -} +void Call5(half2 H) { Fn5(H); } void Fn4(int64_t2 L); void Fn4(int2 I); -void Call4(int16_t H) { - Fn4(H); -} +void Call4(int16_t H) { Fn4(H); } -int test_builtin_dot_bool_type_promotion ( bool p0, bool p1 ) { - return dot ( p0, p1 ); +int test_builtin_dot_bool_type_promotion(bool p0, bool p1) { + return dot(p0, p1); } -float test_dot_scalar_mismatch ( float p0, int p1 ) { - return dot ( p0, p1 ); -} +float test_dot_scalar_mismatch(float p0, int p1) { return dot(p0, p1); } -float test_dot_element_type_mismatch ( int2 p0, float2 p1 ) { - return dot ( p0, p1 ); -} +float test_dot_element_type_mismatch(int2 p0, float2 p1) { return dot(p0, p1); } -float test_builtin_dot_vec_int_to_float_promotion ( int2 p0, float2 p1 ) { - return dot ( p0, p1 ); +float test_builtin_dot_vec_int_to_float_promotion(int2 p0, float2 p1) { + return dot(p0, p1); } -int64_t test_builtin_dot_vec_int_to_int64_promotion( int64_t2 p0, int2 p1 ) { - return dot ( p0, p1 ); +int64_t test_builtin_dot_vec_int_to_int64_promotion(int64_t2 p0, int2 p1) { + return dot(p0, p1); } -float test_builtin_dot_vec_half_to_float_promotion( float2 p0, half2 p1 ) { - return dot( p0, p1 ); +float test_builtin_dot_vec_half_to_float_promotion(float2 p0, half2 p1) { + return dot(p0, p1); } -float test_builtin_dot_vec_int16_to_float_promotion( float2 p0, int16_t2 p1 ) { - return dot( p0, p1 ); +float test_builtin_dot_vec_int16_to_float_promotion(float2 p0, int16_t2 p1) { + return dot(p0, p1); } -half test_builtin_dot_vec_int16_to_half_promotion( half2 p0, int16_t2 p1 ) { - return dot( p0, p1 ); +half test_builtin_dot_vec_int16_to_half_promotion(half2 p0, int16_t2 p1) { + return dot(p0, p1); } -int test_builtin_dot_vec_int16_to_int_promotion( int2 p0, int16_t2 p1 ) { - return dot( p0, p1 ); +int test_builtin_dot_vec_int16_to_int_promotion(int2 p0, int16_t2 p1) { + return dot(p0, p1); } -int64_t test_builtin_dot_vec_int16_to_int64_promotion( int64_t2 p0, int16_t2 p1 ) { - return dot( p0, p1 ); +int64_t test_builtin_dot_vec_int16_to_int64_promotion(int64_t2 p0, + int16_t2 p1) { + return dot(p0, p1); } +float4 test_frac_int4(int4 p0) { return frac(p0); } + +float test_frac_int(int p0) { return frac(p0); } + +float test_frac_bool(bool p0) { return frac(p0); } + // https://github.com/llvm/llvm-project/issues/81049 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \ // RUN: -o - | FileCheck %s --check-prefix=NO_HALF -half sqrt_h(half x) -{ - return sqrt(x); -} +half sqrt_h(half x) { return sqrt(x); } // NO_HALF: define noundef float @"?sqrt_h@@YA$halff@$halff@@Z"( // NO_HALF: call float @llvm.sqrt.f32(float %0) diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td b/llvm/include/llvm/IR/IntrinsicsDirectX.td index 48332b917693a0..b44d1c6d3d2f06 100644 --- a/llvm/include/llvm/IR/IntrinsicsDirectX.td +++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td @@ -25,8 +25,10 @@ def int_dx_dot : [llvm_anyvector_ty, LLVMScalarOrSameVectorWidth<0, LLVMVectorElementType<0>>], [IntrNoMem, IntrWillReturn, Commutative] >; +def int_dx_frac : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>; + def int_dx_lerp : - Intrinsic<[LLVMMatchType<0>], - [llvm_anyvector_ty, LLVMMatchType<0>, LLVMMatchType<0>], - [IntrNoMem, IntrWillReturn, Commutative] >; + Intrinsic<[LLVMScalarOrSameVectorWidth<0, LLVMVectorElementType<0>>], + [llvm_anyvector_ty, LLVMScalarOrSameVectorWidth<0, LLVMVectorElementType<0>>,LLVMScalarOrSameVectorWidth<0, LLVMVectorElementType<0>>], + [IntrNoMem, IntrWillReturn] >; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits