Skip to content

Commit 807602e

Browse files
committed
Addressed PR feedback
1 parent 0beb7c7 commit 807602e

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4894,7 +4894,7 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
48944894
def HLSLDot2Add : LangBuiltin<"HLSL_LANG"> {
48954895
let Spellings = ["__builtin_hlsl_dot2add"];
48964896
let Attributes = [NoThrow, Const, CustomTypeChecking];
4897-
let Prototype = "void(...)";
4897+
let Prototype = "float(_ExtVector<2, _Float16>,_ExtVector<2, _Float16>, float)";
48984898
}
48994899

49004900
def HLSLDot4AddI8Packed : LangBuiltin<"HLSL_LANG"> {

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,15 @@ const inline float distance(__detail::HLSL_FIXED_VECTOR<float, N> X,
179179
// dot2add builtins
180180
//===----------------------------------------------------------------------===//
181181

182-
/// \fn float dot2add(half2 a, half2 b, float c)
182+
/// \fn float dot2add(half2 A, half2 B, float C)
183183
/// \brief Dot product of 2 vector of type half and add a float scalar value.
184+
/// \param A The first input value to dot product.
185+
/// \param B The second input value to dot product.
186+
/// \param C The input value added to the dot product.
184187

185188
_HLSL_AVAILABILITY(shadermodel, 6.4)
186-
const inline float dot2add(half2 a, half2 b, float c) {
187-
return __detail::dot2add_impl(a, b, c);
189+
const inline float dot2add(half2 A, half2 B, float C) {
190+
return __detail::dot2add_impl(A, B, C);
188191
}
189192

190193
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,11 +2476,9 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24762476
break;
24772477
}
24782478
case Builtin::BI__builtin_hlsl_dot2add: {
2479-
// Check number of arguments should be 3
24802479
if (SemaRef.checkArgCount(TheCall, 3))
24812480
return true;
24822481

2483-
// Check first two arguments are vector of length 2 with half data type
24842482
auto checkHalfVectorOfSize2 = [](clang::QualType PassedType) -> bool {
24852483
if (const auto *VecTy = PassedType->getAs<VectorType>())
24862484
return !(VecTy->getNumElements() == 2 &&
@@ -2496,10 +2494,9 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24962494
checkHalfVectorOfSize2))
24972495
return true;
24982496

2499-
// Check third argument is a float
25002497
if (CheckArgTypeMatches(&SemaRef, TheCall->getArg(2), SemaRef.getASTContext().FloatTy))
25012498
return true;
2502-
TheCall->setType(TheCall->getArg(2)->getType());
2499+
TheCall->setType(SemaRef.getASTContext().FloatTy);
25032500
break;
25042501
}
25052502
case Builtin::BI__builtin_hlsl_elementwise_firstbithigh:
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple \
1+
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
22
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \
33
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
4-
// RUN: %clang_cc1 -finclude-default-header -triple \
4+
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
55
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
66
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
77

88
// Test basic lowering to runtime function call.
99

1010
float test(half2 p1, half2 p2, float p3) {
11-
// CHECK-SPIRV: %[[MUL:.*]] = call {{.*}} float @llvm.spv.fdot.v2f32(<2 x float> %1, <2 x float> %2)
11+
// CHECK-SPIRV: %[[MUL:.*]] = call {{.*}} half @llvm.spv.fdot.v2f16(<2 x half> %1, <2 x half> %2)
12+
// CHECK-SPIRV: %[[CONVERT:.*]] = fpext {{.*}} half %[[MUL:.*]] to float
1213
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr, align 4
13-
// CHECK-SPIRV: %[[RES:.*]] = fadd {{.*}} float %[[MUL]], %[[C]]
14-
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f32(<2 x float> %0, <2 x float> %1, float %2)
14+
// CHECK-SPIRV: %[[RES:.*]] = fadd {{.*}} float %[[CONVERT:.*]], %[[C:.*]]
15+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %0, <2 x half> %1, float %2)
1516
// CHECK: ret float %[[RES]]
1617
return dot2add(p1, p2, p3);
17-
}
18+
}
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1-
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify
22

3-
bool test_too_few_arg() {
3+
float test_too_few_arg() {
44
return __builtin_hlsl_dot2add();
55
// expected-error@-1 {{too few arguments to function call, expected 3, have 0}}
66
}
77

8-
bool test_too_many_arg(half2 p1, half2 p2, float p3) {
8+
float test_too_many_arg(half2 p1, half2 p2, float p3) {
99
return __builtin_hlsl_dot2add(p1, p2, p3, p1);
1010
// expected-error@-1 {{too many arguments to function call, expected 3, have 4}}
1111
}
12+
13+
float test_float_arg2_type(half2 p1, float2 p2, float p3) {
14+
return __builtin_hlsl_dot2add(p1, p2, p3);
15+
// expected-error@-1 {{passing 'float2' (aka 'vector<float, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(half)))) half' (vector of 2 'half' values)}}
16+
}
17+
18+
float test_float_arg1_type(float2 p1, half2 p2, float p3) {
19+
return __builtin_hlsl_dot2add(p1, p2, p3);
20+
// expected-error@-1 {{passing 'float2' (aka 'vector<float, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(half)))) half' (vector of 2 'half' values)}}
21+
}
22+
23+
float test_double_arg3_type(half2 p1, half2 p2, double p3) {
24+
return __builtin_hlsl_dot2add(p1, p2, p3);
25+
// expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}}
26+
}
27+
28+
float test_float_arg1_arg2_type(float2 p1, float2 p2, float p3) {
29+
return __builtin_hlsl_dot2add(p1, p2, p3);
30+
// expected-error@-1 {{passing 'float2' (aka 'vector<float, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(half)))) half' (vector of 2 'half' values)}}
31+
}
32+
33+
float test_int16_arg1_arg2_type(int16_t2 p1, int16_t2 p2, float p3) {
34+
return __builtin_hlsl_dot2add(p1, p2, p3);
35+
// expected-error@-1 {{passing 'int16_t2' (aka 'vector<int16_t, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(half)))) half' (vector of 2 'half' values)}}
36+
}

llvm/test/CodeGen/DirectX/dot2add.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ entry:
55
; CHECK: call float @dx.op.dot2AddHalf(i32 162, float %c, half %0, half %1, half %2, half %3)
66
%ret = call float @llvm.dx.dot2add(<2 x half> %a, <2 x half> %b, float %c)
77
ret float %ret
8-
}
8+
}

0 commit comments

Comments
 (0)