Skip to content

Commit e56509e

Browse files
committed
End to end working code for dot2add
1 parent b7ff3bf commit e56509e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
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];
4897-
let Prototype = "void(...)";
4896+
let Attributes = [NoThrow, Const, CustomTypeChecking];
4897+
let Prototype = "float(...)";
48984898
}
48994899

49004900
def HLSLDot4AddI8Packed : LangBuiltin<"HLSL_LANG"> {

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,8 +2490,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
24902490
break;
24912491
}
24922492
case Builtin::BI__builtin_hlsl_dot2add: {
2493+
// Check number of arguments should be 3
24932494
if (SemaRef.checkArgCount(TheCall, 3))
24942495
return true;
2496+
// Check first two arguments should be vectors of same length
24952497
if (CheckVectorElementCallArgs(&SemaRef, TheCall, TheCall->getNumArgs() - 1))
24962498
return true;
24972499
if (CheckArgTypeMatches(&SemaRef, TheCall->getArg(2), SemaRef.getASTContext().FloatTy))
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// RUN: %clang_cc1 -finclude-default-header -triple \
22
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \
3-
// RUN: FileCheck %s -DTARGET=dx
3+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
4+
// RUN: %clang_cc1 -finclude-default-header -triple \
5+
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
6+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
47

58
// Test basic lowering to runtime function call.
69

7-
// CHECK-LABEL: test
810
float test(half2 p1, half2 p2, float p3) {
9-
// CHECK-DXIL: %hlsl.dot2add = call reassoc nnan ninf nsz arcp afn float @llvm.dx.dot2add.v2f32(<2 x float> %0, <2 x float> %1, float %2)
10-
// CHECK: ret float %hlsl.dot2add
11+
// CHECK-SPIRV: %[[MUL:.*]] = call {{.*}} float @llvm.spv.fdot.v2f32(<2 x float> %1, <2 x float> %2)
12+
// 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)
15+
// CHECK: ret float %[[RES]]
1116
return dot2add(p1, p2, p3);
12-
}
13-
14-
// CHECK: declare [[TY]] @llvm.[[TARGET]].dot4add.i8packed([[TY]], [[TY]], [[TY]])
17+
}

0 commit comments

Comments
 (0)