diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 0e6c1c284da6cf..92118418d9d459 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -53,9 +53,6 @@ class MSInt32_64Template : Template<["msint32_t", "int64_t"], class FloatDoubleTemplate : Template<["float", "double"], ["f", ""]>; -class HLSLFloatAndIntTemplate : Template< - ["unsigned int", "int", "float"], - ["", "si", "f"]>; // FIXME: These assume that char -> i8, short -> i16, int -> i32, // long long -> i64. class SyncBuiltinsTemplate : @@ -4754,12 +4751,6 @@ def HLSLRcp : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } -def HLSLAsUint : LangBuiltin<"HLSL_LANG">, HLSLFloatAndIntTemplate { - let Spellings = ["__builtin_hlsl_elementwise_asuint"]; - let Attributes = [NoThrow, Const]; - let Prototype = "unsigned int (T)"; -} - def HLSLRSqrt : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_elementwise_rsqrt"]; let Attributes = [NoThrow, Const]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 012623a3d7032f..da7a1a55da5313 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18815,19 +18815,6 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index", {}, false, true)); } - case Builtin::BI__builtin_hlsl_elementwise_asuint: { - Value *Op = EmitScalarExpr(E->getArg(0)); - - llvm::Type *DestTy = llvm::Type::getInt32Ty(this->getLLVMContext()); - - if (Op->getType()->isVectorTy()) { - const VectorType *VecTy = E->getArg(0)->getType()->getAs(); - DestTy = llvm::VectorType::get( - DestTy, ElementCount::getFixed(VecTy->getNumElements())); - } - - return Builder.CreateBitCast(Op, DestTy); - } case Builtin::BI__builtin_hlsl_wave_is_first_lane: { Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic(); return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index 178484f5852f51..9e5a303baaceba 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -395,32 +395,18 @@ float4 asin(float4); /// \brief Interprets the bit pattern of x as an unsigned integer. /// \param Val The input value. -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint asuint(float); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint2 asuint(float2); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint3 asuint(float3); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint4 asuint(float4); - -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint asuint(uint); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint2 asuint(uint2); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint3 asuint(uint3); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint4 asuint(uint4); - -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint asuint(int); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint2 asuint(int2); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint3 asuint(int3); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_asuint) -uint4 asuint(int4); +template +__attribute__((__always_inline__, __nodebug__)) static inline vector +asuint(vector V) { + _Static_assert(sizeof(T) == 4, "Input type to asuint must be 32-bit"); + return __builtin_bit_cast(vector, V); +} + +template +__attribute__((__always_inline__, __nodebug__)) static inline uint asuint(T F) { + _Static_assert(sizeof(T) == 4, "Input type to asuint must be 32-bit"); + return __builtin_bit_cast(uint, F); +} //===----------------------------------------------------------------------===// // atan builtins diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 10019067c803eb..2285b5b20b18bc 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -1491,18 +1491,6 @@ bool CheckAllArgsHaveFloatRepresentation(Sema *S, CallExpr *TheCall) { checkAllFloatTypes); } -bool CheckNotFloatAndInt(Sema *S, CallExpr *TheCall) { - auto checkFloat = [](clang::QualType PassedType) -> bool { - clang::QualType BaseType = - PassedType->isVectorType() - ? PassedType->getAs()->getElementType() - : PassedType; - return !(BaseType->isFloat32Type() || BaseType->isIntegerType()); - }; - - return CheckArgsTypesAreCorrect(S, TheCall, S->Context.FloatTy, checkFloat); -} - bool CheckFloatOrHalfRepresentations(Sema *S, CallExpr *TheCall) { auto checkFloatorHalf = [](clang::QualType PassedType) -> bool { clang::QualType BaseType = @@ -1657,15 +1645,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; break; } - case Builtin::BI__builtin_hlsl_elementwise_asuint: { - if (SemaRef.checkArgCount(TheCall, 1)) - return true; - - if (CheckNotFloatAndInt(&SemaRef, TheCall)) - return true; - - break; - } case Builtin::BI__builtin_elementwise_acos: case Builtin::BI__builtin_elementwise_asin: case Builtin::BI__builtin_elementwise_atan: diff --git a/clang/test/CodeGenHLSL/builtins/asuint.hlsl b/clang/test/CodeGenHLSL/builtins/asuint.hlsl index 1edf07942d3a09..ac3dae26d6caed 100644 --- a/clang/test/CodeGenHLSL/builtins/asuint.hlsl +++ b/clang/test/CodeGenHLSL/builtins/asuint.hlsl @@ -3,39 +3,39 @@ // CHECK: define {{.*}}test_uint{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret i32 [[VAL]] -export uint test_uint(uint p0) { +uint test_uint(uint p0) { return asuint(p0); } // CHECK: define {{.*}}test_int{{.*}}(i32 {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret i32 [[VAL]] -export uint test_int(int p0) { +uint test_int(int p0) { return asuint(p0); } // CHECK: define {{.*}}test_float{{.*}}(float {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast float [[VAL]] to i32 -export uint test_float(float p0) { +uint test_float(float p0) { return asuint(p0); } // CHECK: define {{.*}}test_vector_uint{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x i32> [[VAL]] -export uint4 test_vector_uint(uint4 p0) { +uint4 test_vector_uint(uint4 p0) { return asuint(p0); } // CHECK: define {{.*}}test_vector_int{{.*}}(<4 x i32> {{.*}} [[VAL:%.*]]){{.*}} // CHECK-NOT: bitcast // CHECK: ret <4 x i32> [[VAL]] -export uint4 test_vector_int(int4 p0) { +uint4 test_vector_int(int4 p0) { return asuint(p0); } // CHECK: define {{.*}}test_vector_float{{.*}}(<4 x float> {{.*}} [[VAL:%.*]]){{.*}} // CHECK: bitcast <4 x float> [[VAL]] to <4 x i32> -export uint4 test_vector_float(float4 p0) { +uint4 test_vector_float(float4 p0) { return asuint(p0); } diff --git a/clang/test/SemaHLSL/BuiltIns/asuint-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/asuint-errors.hlsl index e9da975bff1b5e..5b37eb55aeba27 100644 --- a/clang/test/SemaHLSL/BuiltIns/asuint-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/asuint-errors.hlsl @@ -1,18 +1,18 @@ // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected -export uint4 test_asuint_too_many_arg(float p0, float p1) { - return __builtin_hlsl_elementwise_asuint(p0, p1); - // expected-error@-1 {{too many arguments to function call, expected 1, have 2}} +uint4 test_asuint_too_many_arg(float p0, float p1) { + return asuint(p0, p1); + // expected-error@-1 {{no matching function for call to 'asuint'}} } - -export uint fn(double p1) { +uint test_asuint_double(double p1) { return asuint(p1); - // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} + // expected-error@-1 {/clang/20/include/hlsl/hlsl_intrinsics.h} {{static assertion failed due to requirement 'sizeof(double) == 4': Input type to asuint must be 32-bit}} } -export uint fn(half p1) { + +uint test_asuint_half(half p1) { return asuint(p1); - // expected-error@-1 {{passing 'half' to parameter of incompatible type 'float'}} + // expected-error@-1 {/clang/20/include/hlsl/hlsl_intrinsics.h} {{static assertion failed due to requirement 'sizeof(double) == 4': Input type to asuint must be 32-bit}} }