Skip to content

Commit b900379

Browse files
authored
[HLSL] Reapply Move length support out of the DirectX Backend (#121611) (#122337)
## Changes - Delete DirectX length intrinsic - Delete HLSL length lang builtin - Implement length algorithm entirely in the header. ## History - In the past if an HLSL intrinsic lowered to either a spirv op code or a DXIL opcode we represented it with intrinsics ## Why we are moving away? - To make HLSL apis more portable the team decided that it makes sense for some intrinsics to be defined only in the header. - Since there tends to be more SPIRV opcodes than DXIL opcodes the plan is to support SPIRV opcodes either with target specific builtins or via pattern matching.
1 parent c91d805 commit b900379

File tree

14 files changed

+183
-324
lines changed

14 files changed

+183
-324
lines changed

clang/include/clang/Basic/Builtins.td

-6
Original file line numberDiff line numberDiff line change
@@ -4865,12 +4865,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
48654865
let Prototype = "void(...)";
48664866
}
48674867

4868-
def HLSLLength : LangBuiltin<"HLSL_LANG"> {
4869-
let Spellings = ["__builtin_hlsl_length"];
4870-
let Attributes = [NoThrow, Const];
4871-
let Prototype = "void(...)";
4872-
}
4873-
48744868
def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
48754869
let Spellings = ["__builtin_hlsl_lerp"];
48764870
let Attributes = [NoThrow, Const];

clang/lib/CodeGen/CGBuiltin.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -19334,20 +19334,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1933419334
/*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
1933519335
ArrayRef<Value *>{X, Y, S}, nullptr, "hlsl.lerp");
1933619336
}
19337-
case Builtin::BI__builtin_hlsl_length: {
19338-
Value *X = EmitScalarExpr(E->getArg(0));
19339-
19340-
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
19341-
"length operand must have a float representation");
19342-
// if the operand is a scalar, we can use the fabs llvm intrinsic directly
19343-
if (!E->getArg(0)->getType()->isVectorType())
19344-
return EmitFAbs(*this, X);
19345-
19346-
return Builder.CreateIntrinsic(
19347-
/*ReturnType=*/X->getType()->getScalarType(),
19348-
CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef<Value *>{X},
19349-
nullptr, "hlsl.length");
19350-
}
1935119337
case Builtin::BI__builtin_hlsl_normalize: {
1935219338
Value *X = EmitScalarExpr(E->getArg(0));
1935319339

clang/lib/CodeGen/CGHLSLRuntime.h

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class CGHLSLRuntime {
7777
GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
7878
GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
7979
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
80-
GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
8180
GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
8281
GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
8382
GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)

clang/lib/Headers/hlsl/hlsl_detail.h

+20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ namespace hlsl {
1313

1414
namespace __detail {
1515

16+
template <typename T, typename U> struct is_same {
17+
static const bool value = false;
18+
};
19+
20+
template <typename T> struct is_same<T, T> {
21+
static const bool value = true;
22+
};
23+
1624
template <bool B, typename T> struct enable_if {};
1725

1826
template <typename T> struct enable_if<true, T> {
@@ -33,6 +41,18 @@ constexpr enable_if_t<sizeof(U) == sizeof(T), U> bit_cast(T F) {
3341
return __builtin_bit_cast(U, F);
3442
}
3543

44+
template <typename T>
45+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
46+
length_impl(T X) {
47+
return __builtin_elementwise_abs(X);
48+
}
49+
50+
template <typename T, int N>
51+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
52+
length_vec_impl(vector<T, N> X) {
53+
return __builtin_elementwise_sqrt(__builtin_hlsl_dot(X, X));
54+
}
55+
3656
} // namespace __detail
3757
} // namespace hlsl
3858
#endif //_HLSL_HLSL_DETAILS_H_

clang/lib/Headers/hlsl/hlsl_intrinsics.h

+12-20
Original file line numberDiff line numberDiff line change
@@ -1298,26 +1298,18 @@ float4 lerp(float4, float4, float4);
12981298
/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
12991299

13001300
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1301-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1302-
half length(half);
1303-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1304-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1305-
half length(half2);
1306-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1307-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1308-
half length(half3);
1309-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1310-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1311-
half length(half4);
1312-
1313-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1314-
float length(float);
1315-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1316-
float length(float2);
1317-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1318-
float length(float3);
1319-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1320-
float length(float4);
1301+
const inline half length(half X) { return __detail::length_impl(X); }
1302+
const inline float length(float X) { return __detail::length_impl(X); }
1303+
1304+
template <int N>
1305+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1306+
const inline half length(vector<half, N> X) {
1307+
return __detail::length_vec_impl(X);
1308+
}
1309+
1310+
template <int N> const inline float length(vector<float, N> X) {
1311+
return __detail::length_vec_impl(X);
1312+
}
13211313

13221314
//===----------------------------------------------------------------------===//
13231315
// log builtins

clang/lib/Sema/SemaHLSL.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -2112,24 +2112,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
21122112
return true;
21132113
break;
21142114
}
2115-
case Builtin::BI__builtin_hlsl_length: {
2116-
if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall))
2117-
return true;
2118-
if (SemaRef.checkArgCount(TheCall, 1))
2119-
return true;
2120-
2121-
ExprResult A = TheCall->getArg(0);
2122-
QualType ArgTyA = A.get()->getType();
2123-
QualType RetTy;
2124-
2125-
if (auto *VTy = ArgTyA->getAs<VectorType>())
2126-
RetTy = VTy->getElementType();
2127-
else
2128-
RetTy = TheCall->getArg(0)->getType();
2129-
2130-
TheCall->setType(RetTy);
2131-
break;
2132-
}
21332115
case Builtin::BI__builtin_hlsl_mad: {
21342116
if (SemaRef.checkArgCount(TheCall, 3))
21352117
return true;
+115-73
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,115 @@
1-
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2-
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3-
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4-
// RUN: --check-prefixes=CHECK,NATIVE_HALF
5-
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
6-
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
7-
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF
8-
9-
// NATIVE_HALF: define noundef nofpclass(nan inf) half @
10-
// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn half @llvm.fabs.f16(half
11-
// NO_HALF: call reassoc nnan ninf nsz arcp afn float @llvm.fabs.f32(float
12-
// NATIVE_HALF: ret half
13-
// NO_HALF: ret float
14-
half test_length_half(half p0)
15-
{
16-
return length(p0);
17-
}
18-
// NATIVE_HALF: define noundef nofpclass(nan inf) half @
19-
// NATIVE_HALF: %hlsl.length = call reassoc nnan ninf nsz arcp afn half @llvm.dx.length.v2f16
20-
// NO_HALF: %hlsl.length = call reassoc nnan ninf nsz arcp afn float @llvm.dx.length.v2f32(
21-
// NATIVE_HALF: ret half %hlsl.length
22-
// NO_HALF: ret float %hlsl.length
23-
half test_length_half2(half2 p0)
24-
{
25-
return length(p0);
26-
}
27-
// NATIVE_HALF: define noundef nofpclass(nan inf) half @
28-
// NATIVE_HALF: %hlsl.length = call reassoc nnan ninf nsz arcp afn half @llvm.dx.length.v3f16
29-
// NO_HALF: %hlsl.length = call reassoc nnan ninf nsz arcp afn float @llvm.dx.length.v3f32(
30-
// NATIVE_HALF: ret half %hlsl.length
31-
// NO_HALF: ret float %hlsl.length
32-
half test_length_half3(half3 p0)
33-
{
34-
return length(p0);
35-
}
36-
// NATIVE_HALF: define noundef nofpclass(nan inf) half @
37-
// NATIVE_HALF: %hlsl.length = call reassoc nnan ninf nsz arcp afn half @llvm.dx.length.v4f16
38-
// NO_HALF: %hlsl.length = call reassoc nnan ninf nsz arcp afn float @llvm.dx.length.v4f32(
39-
// NATIVE_HALF: ret half %hlsl.length
40-
// NO_HALF: ret float %hlsl.length
41-
half test_length_half4(half4 p0)
42-
{
43-
return length(p0);
44-
}
45-
46-
// CHECK: define noundef nofpclass(nan inf) float @
47-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.fabs.f32(float
48-
// CHECK: ret float
49-
float test_length_float(float p0)
50-
{
51-
return length(p0);
52-
}
53-
// CHECK: define noundef nofpclass(nan inf) float @
54-
// CHECK: %hlsl.length = call reassoc nnan ninf nsz arcp afn float @llvm.dx.length.v2f32(
55-
// CHECK: ret float %hlsl.length
56-
float test_length_float2(float2 p0)
57-
{
58-
return length(p0);
59-
}
60-
// CHECK: define noundef nofpclass(nan inf) float @
61-
// CHECK: %hlsl.length = call reassoc nnan ninf nsz arcp afn float @llvm.dx.length.v3f32(
62-
// CHECK: ret float %hlsl.length
63-
float test_length_float3(float3 p0)
64-
{
65-
return length(p0);
66-
}
67-
// CHECK: define noundef nofpclass(nan inf) float @
68-
// CHECK: %hlsl.length = call reassoc nnan ninf nsz arcp afn float @llvm.dx.length.v4f32(
69-
// CHECK: ret float %hlsl.length
70-
float test_length_float4(float4 p0)
71-
{
72-
return length(p0);
73-
}
1+
// RUN: %clang_cc1 -finclude-default-header -triple \
2+
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3+
// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,DXCHECK \
4+
// RUN: -DTARGET=dx
5+
6+
// RUN: %clang_cc1 -finclude-default-header -triple \
7+
// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \
8+
// RUN: -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,SPVCHECK \
9+
// RUN: -DTARGET=spv
10+
11+
12+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half @_Z16test_length_halfDh(
13+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) half @_Z16test_length_halfDh(
14+
// CHECK-SAME: half noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
15+
// CHECK-NEXT: [[ENTRY:.*:]]
16+
// CHECK-NEXT: [[ELT_ABS_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.fabs.f16(half [[P0]])
17+
// CHECK-NEXT: ret half [[ELT_ABS_I]]
18+
//
19+
20+
half test_length_half(half p0)
21+
{
22+
return length(p0);
23+
}
24+
25+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half @_Z17test_length_half2Dv2_Dh(
26+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) half @_Z17test_length_half2Dv2_Dh(
27+
// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
28+
// CHECK-NEXT: [[ENTRY:.*:]]
29+
// CHECK-NEXT: [[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn half @llvm.[[TARGET]].fdot.v2f16(<2 x half> [[P0]], <2 x half> [[P0]])
30+
// CHECK-NEXT: [[TMP0:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.sqrt.f16(half [[HLSL_DOT_I]])
31+
// CHECK-NEXT: ret half [[TMP0]]
32+
//
33+
34+
35+
half test_length_half2(half2 p0)
36+
{
37+
return length(p0);
38+
}
39+
40+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half @_Z17test_length_half3Dv3_Dh(
41+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) half @_Z17test_length_half3Dv3_Dh(
42+
// CHECK-SAME: <3 x half> noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
43+
// CHECK-NEXT: [[ENTRY:.*:]]
44+
// CHECK-NEXT: [[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn half @llvm.[[TARGET]].fdot.v3f16(<3 x half> [[P0]], <3 x half> [[P0]])
45+
// CHECK-NEXT: [[TMP0:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.sqrt.f16(half [[HLSL_DOT_I]])
46+
// CHECK-NEXT: ret half [[TMP0]]
47+
//
48+
half test_length_half3(half3 p0)
49+
{
50+
return length(p0);
51+
}
52+
53+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half @_Z17test_length_half4Dv4_Dh(
54+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) half @_Z17test_length_half4Dv4_Dh(
55+
// CHECK-SAME: <4 x half> noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
56+
// CHECK-NEXT: [[ENTRY:.*:]]
57+
// CHECK-NEXT: [[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn half @llvm.[[TARGET]].fdot.v4f16(<4 x half> [[P0]], <4 x half> [[P0]])
58+
// CHECK-NEXT: [[TMP0:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef half @llvm.sqrt.f16(half [[HLSL_DOT_I]])
59+
// CHECK-NEXT: ret half [[TMP0]]
60+
//
61+
half test_length_half4(half4 p0)
62+
{
63+
return length(p0);
64+
}
65+
66+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) float @_Z17test_length_floatf(
67+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) float @_Z17test_length_floatf(
68+
// CHECK-SAME: float noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
69+
// CHECK-NEXT: [[ENTRY:.*:]]
70+
// CHECK-NEXT: [[ELT_ABS_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.fabs.f32(float [[P0]])
71+
// CHECK-NEXT: ret float [[ELT_ABS_I]]
72+
//
73+
float test_length_float(float p0)
74+
{
75+
return length(p0);
76+
}
77+
78+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) float @_Z18test_length_float2Dv2_f(
79+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) float @_Z18test_length_float2Dv2_f(
80+
// CHECK-SAME: <2 x float> noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
81+
// CHECK-NEXT: [[ENTRY:.*:]]
82+
// CHECK-NEXT: [[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].fdot.v2f32(<2 x float> [[P0]], <2 x float> [[P0]])
83+
// CHECK-NEXT: [[TMP0:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.sqrt.f32(float [[HLSL_DOT_I]])
84+
// CHECK-NEXT: ret float [[TMP0]]
85+
//
86+
float test_length_float2(float2 p0)
87+
{
88+
return length(p0);
89+
}
90+
91+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) float @_Z18test_length_float3Dv3_f(
92+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) float @_Z18test_length_float3Dv3_f(
93+
// CHECK-SAME: <3 x float> noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
94+
// CHECK-NEXT: [[ENTRY:.*:]]
95+
// CHECK-NEXT: [[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].fdot.v3f32(<3 x float> [[P0]], <3 x float> [[P0]])
96+
// CHECK-NEXT: [[TMP0:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.sqrt.f32(float [[HLSL_DOT_I]])
97+
// CHECK-NEXT: ret float [[TMP0]]
98+
//
99+
float test_length_float3(float3 p0)
100+
{
101+
return length(p0);
102+
}
103+
104+
// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) float @_Z18test_length_float4Dv4_f(
105+
// DXCHECK-LABEL: define noundef nofpclass(nan inf) float @_Z18test_length_float4Dv4_f(
106+
// CHECK-SAME: <4 x float> noundef nofpclass(nan inf) [[P0:%.*]]) local_unnamed_addr #[[ATTR0]] {
107+
// CHECK-NEXT: [[ENTRY:.*:]]
108+
// CHECK-NEXT: [[HLSL_DOT_I:%.*]] = tail call reassoc nnan ninf nsz arcp afn float @llvm.[[TARGET]].fdot.v4f32(<4 x float> [[P0]], <4 x float> [[P0]])
109+
// CHECK-NEXT: [[TMP0:%.*]] = tail call reassoc nnan ninf nsz arcp afn noundef float @llvm.sqrt.f32(float [[HLSL_DOT_I]])
110+
// CHECK-NEXT: ret float [[TMP0]]
111+
//
112+
float test_length_float4(float4 p0)
113+
{
114+
return length(p0);
115+
}
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes -verify -verify-ignore-unexpected
2-
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify
32

43
void test_too_few_arg()
54
{
6-
return __builtin_hlsl_length();
7-
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
5+
return length();
6+
// expected-error@-1 {{no matching function for call to 'length'}}
7+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires single argument 'X', but no arguments were provided}}
8+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires single argument 'X', but no arguments were provided}}
9+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but no arguments were provided}}
10+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but no arguments were provided}}
811
}
912

1013
void test_too_many_arg(float2 p0)
1114
{
12-
return __builtin_hlsl_length(p0, p0);
13-
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
15+
return length(p0, p0);
16+
// expected-error@-1 {{no matching function for call to 'length'}}
17+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires single argument 'X', but 2 arguments were provided}}
18+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but 2 arguments were provided}}
19+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires single argument 'X', but 2 arguments were provided}}
20+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires single argument 'X', but 2 arguments were provided}}
21+
}
22+
23+
float double_to_float_type(double p0) {
24+
return length(p0);
25+
// expected-error@-1 {{call to 'length' is ambiguous}}
26+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
27+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
1428
}
1529

16-
bool builtin_bool_to_float_type_promotion(bool p1)
30+
31+
float bool_to_float_type_promotion(bool p1)
1732
{
18-
return __builtin_hlsl_length(p1);
19-
// expected-error@-1 {passing 'bool' to parameter of incompatible type 'float'}}
33+
return length(p1);
34+
// expected-error@-1 {{call to 'length' is ambiguous}}
35+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
36+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
2037
}
2138

22-
bool builtin_length_int_to_float_promotion(int p1)
39+
float length_int_to_float_promotion(int p1)
2340
{
24-
return __builtin_hlsl_length(p1);
25-
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}}
41+
return length(p1);
42+
// expected-error@-1 {{call to 'length' is ambiguous}}
43+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
44+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
2645
}
2746

28-
bool2 builtin_length_int2_to_float2_promotion(int2 p1)
47+
float2 length_int2_to_float2_promotion(int2 p1)
2948
{
30-
return __builtin_hlsl_length(p1);
31-
// 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)}}
49+
return length(p1);
50+
// expected-error@-1 {{call to 'length' is ambiguous}}
51+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
52+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
3253
}

0 commit comments

Comments
 (0)