Skip to content

Commit a35eaab

Browse files
committed
Addressed PR feedback
1 parent 08a7892 commit a35eaab

File tree

5 files changed

+80
-87
lines changed

5 files changed

+80
-87
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4893,8 +4893,8 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
48934893

48944894
def HLSLDot2Add : LangBuiltin<"HLSL_LANG"> {
48954895
let Spellings = ["__builtin_hlsl_dot2add"];
4896-
let Attributes = [NoThrow, Const, CustomTypeChecking];
4897-
let Prototype = "float(_ExtVector<2, _Float16>,_ExtVector<2, _Float16>, float)";
4896+
let Attributes = [NoThrow, Const];
4897+
let Prototype = "float(_ExtVector<2, __fp16>,_ExtVector<2, __fp16>, float)";
48984898
}
48994899

49004900
def HLSLDot4AddI8Packed : LangBuiltin<"HLSL_LANG"> {

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,50 +2475,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24752475
return true;
24762476
break;
24772477
}
2478-
case Builtin::BI__builtin_hlsl_dot2add: {
2479-
if (SemaRef.checkArgCount(TheCall, 3))
2480-
return true;
2481-
2482-
auto checkHalfVectorOfSize2 = [](clang::QualType PassedType) -> bool {
2483-
if (const auto *VecTy = PassedType->getAs<VectorType>())
2484-
return !(VecTy->getNumElements() == 2 &&
2485-
VecTy->getElementType()->isHalfType());
2486-
return true;
2487-
};
2488-
2489-
auto CheckArgTypeIsCorrect = [](
2490-
Sema *S, Expr *Arg, QualType ExpectedType,
2491-
llvm::function_ref<bool(clang::QualType PassedType)> Check) -> bool {
2492-
QualType PassedType = Arg->getType();
2493-
if (Check(PassedType)) {
2494-
if (auto *VecTyA = PassedType->getAs<VectorType>())
2495-
ExpectedType = S->Context.getVectorType(
2496-
ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind());
2497-
S->Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
2498-
<< PassedType << ExpectedType << 1 << 0 << 0;
2499-
return true;
2500-
}
2501-
return false;
2502-
};
2503-
2504-
if(CheckArgTypeIsCorrect(&SemaRef, TheCall->getArg(0),
2505-
SemaRef.getASTContext().HalfTy,
2506-
checkHalfVectorOfSize2))
2507-
return true;
2508-
if(CheckArgTypeIsCorrect(&SemaRef, TheCall->getArg(1),
2509-
SemaRef.getASTContext().HalfTy,
2510-
checkHalfVectorOfSize2))
2511-
return true;
2512-
2513-
if (!SemaRef.getASTContext().hasSameUnqualifiedType(TheCall->getArg(2)->getType(), SemaRef.getASTContext().FloatTy)) {
2514-
SemaRef.Diag(TheCall->getArg(2)->getBeginLoc(), diag::err_typecheck_convert_incompatible)
2515-
<< TheCall->getArg(2)->getType() << SemaRef.getASTContext().FloatTy << 1 << 0 << 0;
2516-
return true;
2517-
}
2518-
2519-
TheCall->setType(SemaRef.getASTContext().FloatTy);
2520-
break;
2521-
}
25222478
case Builtin::BI__builtin_hlsl_elementwise_firstbithigh:
25232479
case Builtin::BI__builtin_hlsl_elementwise_firstbitlow: {
25242480
if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))

clang/test/CodeGenHLSL/builtins/dot2add.hlsl

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,72 @@
77

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

10+
// CHECK-LABEL: define {{.*}}test
1011
float test(half2 p1, half2 p2, float p3) {
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
13-
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr, align 4
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)
12+
// CHECK-SPIRV: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %1, <2 x half> {{.*}} %2, float {{.*}} %3) #3 {{.*}}
13+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %0, <2 x half> {{.*}} %1, float {{.*}} %2) #2
1614
// CHECK: ret float %[[RES]]
1715
return dot2add(p1, p2, p3);
1816
}
17+
18+
// CHECK-LABEL: define {{.*}}test_float_arg2_type
19+
float test_float_arg2_type(half2 p1, float2 p2, float p3) {
20+
// CHECK-SPIRV: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %2 to <2 x half>
21+
// CHECK-SPIRV: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %1, <2 x half> {{.*}} %conv, float {{.*}} %3) #3 {{.*}}
22+
// CHECK-DXIL: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %1 to <2 x half>
23+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %0, <2 x half> {{.*}} %conv, float {{.*}} %2) #2
24+
// CHECK: ret float %[[RES]]
25+
return dot2add(p1, p2, p3);
26+
}
27+
28+
// CHECK-LABEL: define {{.*}}test_float_arg1_type
29+
float test_float_arg1_type(float2 p1, half2 p2, float p3) {
30+
// CHECK-SPIRV: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %1 to <2 x half>
31+
// CHECK-SPIRV: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %conv, <2 x half> {{.*}} %2, float {{.*}} %3) #3 {{.*}}
32+
// CHECK-DXIL: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %0 to <2 x half>
33+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %conv, <2 x half> {{.*}} %1, float {{.*}} %2) #2
34+
// CHECK: ret float %[[RES]]
35+
return dot2add(p1, p2, p3);
36+
}
37+
38+
// CHECK-LABEL: define {{.*}}test_double_arg3_type
39+
float test_double_arg3_type(half2 p1, half2 p2, double p3) {
40+
// CHECK-SPIRV: %conv = fptrunc reassoc nnan ninf nsz arcp afn double %3 to float
41+
// CHECK-SPIRV: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %1, <2 x half> {{.*}} %2, float {{.*}} %conv) #3 {{.*}}
42+
// CHECK-DXIL: %conv = fptrunc reassoc nnan ninf nsz arcp afn double %2 to float
43+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %0, <2 x half> {{.*}} %1, float {{.*}} %conv) #2
44+
// CHECK: ret float %[[RES]]
45+
return dot2add(p1, p2, p3);
46+
}
47+
48+
// CHECK-LABEL: define {{.*}}test_float_arg1_arg2_type
49+
float test_float_arg1_arg2_type(float2 p1, float2 p2, float p3) {
50+
// CHECK-SPIRV: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %1 to <2 x half>
51+
// CHECK-SPIRV: %conv1 = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %2 to <2 x half>
52+
// CHECK-SPIRV: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %conv, <2 x half> {{.*}} %conv1, float {{.*}} %3) #3 {{.*}}
53+
// CHECK-DXIL: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %0 to <2 x half>
54+
// CHECK-DXIL: %conv1 = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %1 to <2 x half>
55+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %conv, <2 x half> {{.*}} %conv1, float {{.*}} %2) #2
56+
// CHECK: ret float %[[RES]]
57+
return dot2add(p1, p2, p3);
58+
}
59+
60+
// CHECK-LABEL: define {{.*}}test_int16_arg1_arg2_type
61+
float test_int16_arg1_arg2_type(int16_t2 p1, int16_t2 p2, float p3) {
62+
// CHECK-SPIRV: %conv = sitofp <2 x i16> %1 to <2 x half>
63+
// CHECK-SPIRV: %conv1 = sitofp <2 x i16> %2 to <2 x half>
64+
// CHECK-SPIRV: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %conv, <2 x half> {{.*}} %conv1, float {{.*}} %3) #3 {{.*}}
65+
// CHECK-DXIL: %conv = sitofp <2 x i16> %0 to <2 x half>
66+
// CHECK-DXIL: %conv1 = sitofp <2 x i16> %1 to <2 x half>
67+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @_ZN4hlsl7dot2addEDv2_DhS0_f(<2 x half> {{.*}} %conv, <2 x half> {{.*}} %conv1, float {{.*}} %2) #2
68+
// CHECK: ret float %[[RES]]
69+
return dot2add(p1, p2, p3);
70+
}
71+
72+
// CHECK-LABEL: define {{.*}}dot2add_impl
73+
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %1, <2 x half> %2)
74+
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
75+
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr, align 4
76+
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
77+
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %0, <2 x half> %1, float %2)
78+
// CHECK: ret float %[[RES]]

clang/test/SemaHLSL/BuiltIns/Dot2Add-errors.hlsl

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify
2+
3+
float test_too_few_arg() {
4+
return dot2add();
5+
// expected-error@-1 {{no matching function for call to 'dot2add'}}
6+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 3 arguments, but 0 were provided}}
7+
}
8+
9+
float test_too_many_arg(half2 p1, half2 p2, float p3) {
10+
return dot2add(p1, p2, p3, p1);
11+
// expected-error@-1 {{no matching function for call to 'dot2add'}}
12+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
13+
}

0 commit comments

Comments
 (0)