Skip to content

Commit cbc8f65

Browse files
authored
[HLSL][DirectX] Fix dot2add DXIL operation to use float overload (#152781)
Fixes #152585. The `dot2add` DXILOpFunction should be `dx.op.dot2AddHalf.f32` (i.e. it has [a single overload that's a float](https://github.com/microsoft/DirectXShaderCompiler/blob/main/utils/hct/hctdb.py#L3960), rather than no overloads). It was also being defined for too low of a DXIL version - [dxc says SM6.4](https://github.com/microsoft/DirectXShaderCompiler/blob/main/utils/hct/hctdb.py#L740).
1 parent 55e71c0 commit cbc8f65

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

clang/test/CodeGenHLSL/builtins/dot2add.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
2-
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -o - | \
2+
// RUN: dxil-pc-shadermodel6.4-compute %s -emit-llvm -o - | \
33
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
44
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
55
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -o - | \

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,11 +1108,11 @@ def RawBufferStore : DXILOp<140, rawBufferStore> {
11081108
def Dot2AddHalf : DXILOp<162, dot2AddHalf> {
11091109
let Doc = "2D half dot product with accumulate to float";
11101110
let intrinsics = [IntrinSelect<int_dx_dot2add>];
1111-
let arguments = [FloatTy, HalfTy, HalfTy, HalfTy, HalfTy];
1112-
let result = FloatTy;
1113-
let overloads = [Overloads<DXIL1_0, []>];
1114-
let stages = [Stages<DXIL1_0, [all_stages]>];
1115-
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
1111+
let arguments = [OverloadTy, HalfTy, HalfTy, HalfTy, HalfTy];
1112+
let result = OverloadTy;
1113+
let overloads = [Overloads<DXIL1_4, [FloatTy]>];
1114+
let stages = [Stages<DXIL1_4, [all_stages]>];
1115+
let attributes = [Attributes<DXIL1_4, [ReadNone]>];
11161116
}
11171117

11181118
def Dot4AddI8Packed : DXILOp<163, dot4AddPacked> {

llvm/test/CodeGen/DirectX/dot2add.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s
1+
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.4-compute %s | FileCheck %s
22

33
define noundef float @dot2add_simple(<2 x half> noundef %a, <2 x half> noundef %b, float %acc) {
44
entry:
@@ -7,7 +7,7 @@ entry:
77
%bx = extractelement <2 x half> %b, i32 0
88
%by = extractelement <2 x half> %b, i32 1
99

10-
; CHECK: call float @dx.op.dot2AddHalf(i32 162, float %acc, half %ax, half %ay, half %bx, half %by)
10+
; CHECK: call float @dx.op.dot2AddHalf.f32(i32 162, float %acc, half %ax, half %ay, half %bx, half %by)
1111
%ret = call float @llvm.dx.dot2add(float %acc, half %ax, half %ay, half %bx, half %by)
1212
ret float %ret
1313
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s 2>&1 | FileCheck %s
2+
3+
; CHECK: in function f
4+
; CHECK-SAME: Cannot create Dot2AddHalf operation: No valid overloads for DXIL version 1.3
5+
6+
define noundef float @f(<2 x half> noundef %a, <2 x half> noundef %b, float %acc) {
7+
entry:
8+
%ax = extractelement <2 x half> %a, i32 0
9+
%ay = extractelement <2 x half> %a, i32 1
10+
%bx = extractelement <2 x half> %b, i32 0
11+
%by = extractelement <2 x half> %b, i32 1
12+
13+
%ret = call float @llvm.dx.dot2add(float %acc, half %ax, half %ay, half %bx, half %by)
14+
ret float %ret
15+
}

0 commit comments

Comments
 (0)