diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 0baadf0d196b2c..cc64469da9e4a8 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4708,7 +4708,7 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> { } def HLSLLength : LangBuiltin<"HLSL_LANG"> { - let Spellings = ["__builtin_hlsl_elementwise_length"]; + let Spellings = ["__builtin_hlsl_length"]; let Attributes = [NoThrow, Const]; let Prototype = "void(...)"; } diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e071b384bccb81..7406acbcca7c49 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18460,7 +18460,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, /*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(), ArrayRef{X, Y, S}, nullptr, "hlsl.lerp"); } - case Builtin::BI__builtin_hlsl_elementwise_length: { + case Builtin::BI__builtin_hlsl_length: { Value *X = EmitScalarExpr(E->getArg(0)); assert(E->getArg(0)->getType()->hasFloatingRepresentation() && diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index 03e74ef35b5bf9..e1a2b5135c8a41 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -919,25 +919,25 @@ float4 lerp(float4, float4, float4); /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + …). _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) half length(half); _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) half length(half2); _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) half length(half3); _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) half length(half4); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) float length(float); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) float length(float2); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) float length(float3); -_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_length) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length) float length(float4); //===----------------------------------------------------------------------===// diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index ee307a7da21362..203be090638e6d 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -1079,13 +1079,11 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; break; } - case Builtin::BI__builtin_hlsl_elementwise_length: { + case Builtin::BI__builtin_hlsl_length: { if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall)) return true; if (SemaRef.checkArgCount(TheCall, 1)) return true; - if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall)) - return true; ExprResult A = TheCall->getArg(0); QualType ArgTyA = A.get()->getType(); diff --git a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl index 0f7d8b2d65eaf2..fe0046a2ab5a1e 100644 --- a/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/length-errors.hlsl @@ -2,30 +2,30 @@ void test_too_few_arg() { - return __builtin_hlsl_elementwise_length(); + return __builtin_hlsl_length(); // expected-error@-1 {{too few arguments to function call, expected 1, have 0}} } void test_too_many_arg(float2 p0) { - return __builtin_hlsl_elementwise_length(p0, p0); + return __builtin_hlsl_length(p0, p0); // expected-error@-1 {{too many arguments to function call, expected 1, have 2}} } bool builtin_bool_to_float_type_promotion(bool p1) { - return __builtin_hlsl_elementwise_length(p1); + return __builtin_hlsl_length(p1); // expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}} } bool builtin_length_int_to_float_promotion(int p1) { - return __builtin_hlsl_elementwise_length(p1); + return __builtin_hlsl_length(p1); // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} } bool2 builtin_length_int2_to_float2_promotion(int2 p1) { - return __builtin_hlsl_elementwise_length(p1); + return __builtin_hlsl_length(p1); // expected-error@-1 {{passing 'int2' (aka 'vector') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} } diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp index 97fd7c007c1b14..501231298ed25a 100644 --- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp +++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp @@ -170,11 +170,12 @@ static bool expandLengthIntrinsic(CallInst *Orig) { // CGBuiltin.cpp should have emitted a fabs call. Value *Elt = Builder.CreateExtractElement(X, (uint64_t)0); auto *XVec = dyn_cast(Ty); - unsigned size = XVec->getNumElements(); - assert(Ty->isVectorTy() && size > 1 && "dx.length only works on vector type"); + unsigned XVecSize = XVec->getNumElements(); + assert(Ty->isVectorTy() && XVecSize > 1 && + "dx.length requires a vector of length 2 or more"); Value *Sum = Builder.CreateFMul(Elt, Elt); - for (unsigned I = 1; I < size; I++) { + for (unsigned I = 1; I < XVecSize; I++) { Elt = Builder.CreateExtractElement(X, I); Value *Mul = Builder.CreateFMul(Elt, Elt); Sum = Builder.CreateFAdd(Sum, Mul); diff --git a/llvm/test/CodeGen/DirectX/length.ll b/llvm/test/CodeGen/DirectX/length.ll index fc7384267912c7..d12fcf4722a07b 100644 --- a/llvm/test/CodeGen/DirectX/length.ll +++ b/llvm/test/CodeGen/DirectX/length.ll @@ -13,14 +13,6 @@ declare float @llvm.dx.length.v2f32(<2 x float>) declare float @llvm.dx.length.v3f32(<3 x float>) declare float @llvm.dx.length.v4f32(<4 x float>) -define noundef half @test_length_half(half noundef %p0) { -entry: - ; EXPCHECK: call half @llvm.fabs.f16(half %{{.*}}) - ; DOPCHECK: call half @dx.op.unary.f16(i32 6, half %{{.*}}) - %0 = call half @llvm.fabs.f16(half %p0) - ret half %0 -} - define noundef half @test_length_half2(<2 x half> noundef %p0) { entry: ; CHECK: extractelement <2 x half> %{{.*}}, i64 0 @@ -72,15 +64,6 @@ entry: ret half %hlsl.length } -define noundef float @test_length_float(float noundef %p0) { -entry: - ; EXPCHECK: call float @llvm.fabs.f32(float %p0) - ; DOPCHECK: call float @dx.op.unary.f32(i32 6, float %{{.*}}) - - %0 = call float @llvm.fabs.f32(float %p0) - ret float %0 -} - define noundef float @test_length_float2(<2 x float> noundef %p0) { entry: ; CHECK: extractelement <2 x float> %{{.*}}, i64 0