[clang] [llvm] [HLSL] Implementation of the frac intrinsic (PR #83315)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 29 07:42:12 PST 2024
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/83315
>From 2ec582be1c361c212ea846c8433a9cebfeb7b4ba Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzon at farzon.org>
Date: Thu, 29 Feb 2024 10:23:31 -0500
Subject: [PATCH 1/3] address merge conflicts
---
clang/include/clang/Basic/Builtins.td | 7 +-
.../clang/Basic/DiagnosticSemaKinds.td | 2 +-
clang/lib/CodeGen/CGBuiltin.cpp | 23 ++++---
clang/lib/Headers/hlsl/hlsl_intrinsics.h | 32 +++++++++
clang/lib/Sema/SemaChecking.cpp | 25 +++++++
clang/test/CodeGenHLSL/builtins/frac.hlsl | 69 +++++++++++++++++++
clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl | 27 ++++++++
.../test/SemaHLSL/OverloadResolutionBugs.hlsl | 12 ++++
llvm/include/llvm/IR/IntrinsicsDirectX.td | 8 ++-
9 files changed, 191 insertions(+), 14 deletions(-)
create mode 100644 clang/test/CodeGenHLSL/builtins/frac.hlsl
create mode 100644 clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 36151b49d9363d..9af07e16e1b3cf 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4535,9 +4535,14 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
let Attributes = [NoThrow, Const];
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 Spellings = ["__builtin_hlsl_elementwise_frac"];
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
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..bee794f66367f9 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5246,6 +5246,14 @@ bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
return true;
}
+bool checkAllArgsAreFloatRepresentation(CallExpr *TheCall) {
+ for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) {
+ if (!TheCall->getArg(0)->getType()->hasFloatingRepresentation())
+ 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 +5267,21 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return true;
break;
}
+ case Builtin::BI__builtin_hlsl_elementwise_frac: {
+ if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+ return true;
+ QualType PassedType = TheCall->getArg(0)->getType();
+ if (!PassedType->hasFloatingRepresentation()) {
+ QualType ExpectedType = this->Context.FloatTy;
+ if (auto *VecTyA = PassedType->getAs<VectorType>())
+ ExpectedType = this->Context.getVectorType(
+ ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind());
+ Diag(TheCall->getArg(0)->getBeginLoc(),
+ diag::err_typecheck_convert_incompatible)
+ << PassedType << ExpectedType << 1 << 0 << 0;
+ return true;
+ }
+ }
case Builtin::BI__builtin_hlsl_lerp: {
if (checkArgCount(*this, TheCall, 3))
return true;
@@ -5266,6 +5289,8 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return true;
if (SemaBuiltinElementwiseTernaryMath(TheCall))
return true;
+ if (checkAllArgsAreFloatRepresentation(TheCall))
+ return true;
break;
}
}
diff --git a/clang/test/CodeGenHLSL/builtins/frac.hlsl b/clang/test/CodeGenHLSL/builtins/frac.hlsl
new file mode 100644
index 00000000000000..f2d36adc1ad200
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/frac.hlsl
@@ -0,0 +1,69 @@
+// 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/SemaHLSL/BuiltIns/frac-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl
new file mode 100644
index 00000000000000..6e7b98c4a611af
--- /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 at -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 at -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 at -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 at -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 at -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/OverloadResolutionBugs.hlsl b/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl
index 8464f1c1a7c2cd..de8cdb750079d7 100644
--- a/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl
+++ b/clang/test/SemaHLSL/OverloadResolutionBugs.hlsl
@@ -64,6 +64,18 @@ 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 \
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] >;
}
>From cb9768bbf2ccf9eb67953dc468ab3f703db52b4d Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzon at farzon.org>
Date: Wed, 28 Feb 2024 16:46:04 -0500
Subject: [PATCH 2/3] run clang format on tests
---
clang/test/CodeGenHLSL/builtins/frac.hlsl | 32 +++++--------------
clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl | 20 ++++++------
2 files changed, 18 insertions(+), 34 deletions(-)
diff --git a/clang/test/CodeGenHLSL/builtins/frac.hlsl b/clang/test/CodeGenHLSL/builtins/frac.hlsl
index f2d36adc1ad200..7c4d1468e96d27 100644
--- a/clang/test/CodeGenHLSL/builtins/frac.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/frac.hlsl
@@ -12,58 +12,42 @@
// 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 );
-}
+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 );
-}
+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 );
-}
+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 );
-}
+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 );
-}
+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 );
-}
+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 );
-}
+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 );
-}
+float4 test_frac_float4(float4 p0) { return frac(p0); }
diff --git a/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl
index 6e7b98c4a611af..06dbdf0a68dfc1 100644
--- a/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/frac-errors.hlsl
@@ -1,27 +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 ();
+float test_too_few_arg() {
+ return __builtin_hlsl_elementwise_frac();
// expected-error at -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);
+float2 test_too_many_arg(float2 p0) {
+ return __builtin_hlsl_elementwise_frac(p0, p0);
// expected-error at -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 );
+float builtin_bool_to_float_type_promotion(bool p1) {
+ return __builtin_hlsl_elementwise_frac(p1);
// expected-error at -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 );
+float builtin_frac_int_to_float_promotion(int p1) {
+ return __builtin_hlsl_elementwise_frac(p1);
// expected-error at -1 {{passing 'int' to parameter of incompatible type 'float'}}
}
-float2 builtin_frac_int2_to_float2_promotion (int2 p1 ) {
- return __builtin_hlsl_elementwise_frac ( p1 );
+float2 builtin_frac_int2_to_float2_promotion(int2 p1) {
+ return __builtin_hlsl_elementwise_frac(p1);
// expected-error at -1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}}
}
>From e0239e8ac1ee9a2489e853cf65d7cfd2562d3b7b Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzon at farzon.org>
Date: Thu, 29 Feb 2024 10:33:13 -0500
Subject: [PATCH 3/3] fix build issue from bad merge
---
clang/include/clang/Basic/Builtins.td | 2 +-
clang/lib/Sema/SemaChecking.cpp | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 9af07e16e1b3cf..a51f3b2984ea49 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4542,7 +4542,7 @@ def HLSLFrac : LangBuiltin<"HLSL_LANG"> {
}
def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
- let Spellings = ["__builtin_hlsl_elementwise_frac"];
+ let Spellings = ["__builtin_hlsl_lerp"];
let Attributes = [NoThrow, Const];
let Prototype = "void(...)";
}
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bee794f66367f9..fea05f0faa041e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5281,6 +5281,7 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
<< PassedType << ExpectedType << 1 << 0 << 0;
return true;
}
+ break;
}
case Builtin::BI__builtin_hlsl_lerp: {
if (checkArgCount(*this, TheCall, 3))
More information about the cfe-commits
mailing list