Skip to content

Commit a44ad52

Browse files
committed
move dot2add to DirectX.cpp TargetBuiltins
1 parent 7feb18f commit a44ad52

File tree

9 files changed

+42
-29
lines changed

9 files changed

+42
-29
lines changed

.github/new-prs-labeler.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ backend:DirectX:
663663
- clang/lib/Sema/SemaDirectX.cpp
664664
- clang/include/clang/Sema/SemaDirectX.h
665665
- clang/include/clang/Basic/BuiltinsDirectX.td
666+
- clang/lib/CodeGen/TargetBuiltins/DirectX.cpp
666667
- clang/test/CodeGenDirectX/**
667668
- clang/test/SemaDirectX/**
668669

clang/include/clang/Basic/Builtins.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,12 +4891,6 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
48914891
let Prototype = "void(...)";
48924892
}
48934893

4894-
def HLSLDot2Add : LangBuiltin<"HLSL_LANG"> {
4895-
let Spellings = ["__builtin_hlsl_dot2add"];
4896-
let Attributes = [NoThrow, Const];
4897-
let Prototype = "float(_ExtVector<2, _Float16>, _ExtVector<2, _Float16>, float)";
4898-
}
4899-
49004894
def HLSLDot4AddI8Packed : LangBuiltin<"HLSL_LANG"> {
49014895
let Spellings = ["__builtin_hlsl_dot4add_i8packed"];
49024896
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/BuiltinsDirectX.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ include "clang/Basic/BuiltinsBase.td"
1111
def DxDot2Add : Builtin {
1212
let Spellings = ["__builtin_dx_dot2add"];
1313
let Attributes = [NoThrow, Const];
14-
let Prototype = "float(_ExtVector<2, __fp16>,_ExtVector<2, __fp16>,float)";
14+
let Prototype = "float(_ExtVector<2, _Float16>, _ExtVector<2, _Float16>, float)";
1515
}

clang/include/clang/Sema/SemaDirectX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----- SemaDirectX.h ----- Semantic Analysis for DirectX
2-
//constructs--------===//
2+
// constructs--------===//
33
//
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55
// See https://llvm.org/LICENSE.txt for license information.

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
380380
getDotProductIntrinsic(CGM.getHLSLRuntime(), VecTy0->getElementType()),
381381
ArrayRef<Value *>{Op0, Op1}, nullptr, "hlsl.dot");
382382
}
383-
case Builtin::BI__builtin_hlsl_dot2add: {
384-
assert(CGM.getTarget().getTriple().getArch() == llvm::Triple::dxil &&
385-
"Intrinsic dot2add is only allowed for dxil architecture");
386-
Value *A = EmitScalarExpr(E->getArg(0));
387-
Value *B = EmitScalarExpr(E->getArg(1));
388-
Value *C = EmitScalarExpr(E->getArg(2));
389-
390-
Intrinsic::ID ID = llvm ::Intrinsic::dx_dot2add;
391-
return Builder.CreateIntrinsic(
392-
/*ReturnType=*/C->getType(), ID, ArrayRef<Value *>{A, B, C}, nullptr,
393-
"dx.dot2add");
394-
}
395383
case Builtin::BI__builtin_hlsl_dot4add_i8packed: {
396384
Value *A = EmitScalarExpr(E->getArg(0));
397385
Value *B = EmitScalarExpr(E->getArg(1));

clang/lib/CodeGen/TargetBuiltins/DirectX.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ using namespace CodeGen;
2020
using namespace llvm;
2121

2222
Value *CodeGenFunction::EmitDirectXBuiltinExpr(unsigned BuiltinID,
23-
const CallExpr *E) {
24-
return nullptr;
23+
const CallExpr *E) {
24+
switch (BuiltinID) {
25+
case DirectX::BI__builtin_dx_dot2add: {
26+
Value *A = EmitScalarExpr(E->getArg(0));
27+
Value *B = EmitScalarExpr(E->getArg(1));
28+
Value *C = EmitScalarExpr(E->getArg(2));
29+
30+
Intrinsic::ID ID = llvm ::Intrinsic::dx_dot2add;
31+
return Builder.CreateIntrinsic(
32+
/*ReturnType=*/C->getType(), ID, ArrayRef<Value *>{A, B, C}, nullptr,
33+
"dx.dot2add");
34+
}
35+
}
36+
return nullptr;
2537
}

clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ distance_vec_impl(vector<T, N> X, vector<T, N> Y) {
4646
}
4747

4848
constexpr float dot2add_impl(half2 a, half2 b, float c) {
49-
#if defined(__DIRECTX__)
50-
return __builtin_hlsl_dot2add(a, b, c);
49+
#if (__has_builtin(__builtin_dx_dot2add))
50+
return __builtin_dx_dot2add(a, b, c);
5151
#else
5252
return dot(a, b) + c;
5353
#endif

clang/lib/Sema/SemaDirectX.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ SemaDirectX::SemaDirectX(Sema &S) : SemaBase(S) {}
1818

1919
bool SemaDirectX::CheckDirectXBuiltinFunctionCall(unsigned BuiltinID,
2020
CallExpr *TheCall) {
21-
switch (BuiltinID) {
22-
case DirectX::BI__builtin_dx_dot2add: {
23-
}
24-
}
25-
2621
return false;
2722
}
2823
} // namespace clang
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
3+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -o - | FileCheck %s
4+
5+
typedef _Float16 half;
6+
typedef half half2 __attribute__((ext_vector_type(2)));
7+
8+
// CHECK-LABEL: define float @test_dot2add(
9+
// CHECK-SAME: <2 x half> noundef [[X:%.*]], <2 x half> noundef [[Y:%.*]], float noundef [[Z:%.*]]) #[[ATTR0:[0-9]+]] {
10+
// CHECK-NEXT: [[ENTRY:.*:]]
11+
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca <2 x half>, align 4
12+
// CHECK-NEXT: [[Y_ADDR:%.*]] = alloca <2 x half>, align 4
13+
// CHECK-NEXT: [[Z_ADDR:%.*]] = alloca float, align 4
14+
// CHECK-NEXT: store <2 x half> [[X]], ptr [[X_ADDR]], align 4
15+
// CHECK-NEXT: store <2 x half> [[Y]], ptr [[Y_ADDR]], align 4
16+
// CHECK-NEXT: store float [[Z]], ptr [[Z_ADDR]], align 4
17+
// CHECK-NEXT: [[TMP0:%.*]] = load <2 x half>, ptr [[X_ADDR]], align 4
18+
// CHECK-NEXT: [[TMP1:%.*]] = load <2 x half>, ptr [[Y_ADDR]], align 4
19+
// CHECK-NEXT: [[TMP2:%.*]] = load float, ptr [[Z_ADDR]], align 4
20+
// CHECK-NEXT: [[DX_DOT2ADD:%.*]] = call float @llvm.dx.dot2add.v2f16(<2 x half> [[TMP0]], <2 x half> [[TMP1]], float [[TMP2]])
21+
// CHECK-NEXT: ret float [[DX_DOT2ADD]]
22+
//
23+
float test_dot2add(half2 X, half2 Y, float Z) { return __builtin_dx_dot2add(X, Y, Z); }

0 commit comments

Comments
 (0)