-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL][SPIRV][DXIL] Implement dot4add_u8packed
intrinsic
#115068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
414b07f
[HLSL][SPIRV][DXIL] Implement `dot4add_u8packed` intrinsic
inbelic 8d097c8
fix typo
inbelic 462fae7
move the Result bug fix to seperate pr
inbelic 7c9f3f1
review comment
inbelic 50f496a
Merge branch 'main' into inbelic/packed-dot-u8
inbelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
// RUN: %clang_cc1 -finclude-default-header -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \ | ||
// RUN: FileCheck %s -DTARGET=dx | ||
// RUN: %clang_cc1 -finclude-default-header -triple \ | ||
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \ | ||
// RUN: FileCheck %s -DTARGET=spv | ||
|
||
// Test basic lowering to runtime function call. | ||
|
||
// CHECK-LABEL: define {{.*}}test | ||
uint test(uint a, uint b, uint c) { | ||
// CHECK: %[[RET:.*]] = call [[TY:i32]] @llvm.[[TARGET]].dot4add.u8packed([[TY]] %[[#]], [[TY]] %[[#]], [[TY]] %[[#]]) | ||
// CHECK: ret [[TY]] %[[RET]] | ||
return dot4add_u8packed(a, b, c); | ||
} | ||
|
||
// CHECK: declare [[TY]] @llvm.[[TARGET]].dot4add.u8packed([[TY]], [[TY]], [[TY]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify | ||
|
||
int test_too_few_arg0() { | ||
return __builtin_hlsl_dot4add_u8packed(); | ||
// expected-error@-1 {{too few arguments to function call, expected 3, have 0}} | ||
} | ||
|
||
int test_too_few_arg1(int p0) { | ||
return __builtin_hlsl_dot4add_u8packed(p0); | ||
// expected-error@-1 {{too few arguments to function call, expected 3, have 1}} | ||
} | ||
|
||
int test_too_few_arg2(uint p0) { | ||
return __builtin_hlsl_dot4add_u8packed(p0, p0); | ||
// expected-error@-1 {{too few arguments to function call, expected 3, have 2}} | ||
} | ||
|
||
int test_too_many_arg(uint p0) { | ||
return __builtin_hlsl_dot4add_u8packed(p0, p0, p0, p0); | ||
// expected-error@-1 {{too many arguments to function call, expected 3, have 4}} | ||
} | ||
|
||
struct S { float f; }; | ||
|
||
int test_expr_struct_type_check(S p0, uint p1) { | ||
return __builtin_hlsl_dot4add_u8packed(p1, p1, p0); | ||
// expected-error@-1 {{no viable conversion from 'S' to 'unsigned int'}} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s | ||
|
||
define void @main(i32 %a, i32 %b, i32 %c) { | ||
entry: | ||
; CHECK: call i32 @dx.op.dot4AddPacked(i32 164, i32 %a, i32 %b, i32 %c) | ||
%0 = call i32 @llvm.dx.dot4add.u8packed(i32 %a, i32 %b, i32 %c) | ||
ret void | ||
} | ||
|
||
declare i32 @llvm.dx.dot4add.u8packed(i32, i32, i32) |
65 changes: 65 additions & 0 deletions
65
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/dot4add_u8packed.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
; RUN: llc -O0 -mtriple=spirv1.5-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-EXP | ||
; RUN: llc -O0 -mtriple=spirv1.6-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-DOT | ||
; RUN: llc -O0 -mtriple=spirv-unknown-unknown -spirv-ext=+SPV_KHR_integer_dot_product %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-DOT,CHECK-EXT | ||
inbelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv1.5-unknown-unknown %s -o - -filetype=obj | spirv-val %} | ||
; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv1.6-unknown-unknown %s -o - -filetype=obj | spirv-val %} | ||
; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown -spirv-ext=+SPV_KHR_integer_dot_product %s -o - -filetype=obj | spirv-val %} | ||
|
||
; CHECK-DOT: OpCapability DotProduct | ||
; CHECK-DOT: OpCapability DotProductInput4x8BitPacked | ||
; CHECK-EXT: OpExtension "SPV_KHR_integer_dot_product" | ||
|
||
; CHECK: %[[#int_32:]] = OpTypeInt 32 0 | ||
; CHECK-EXP-DAG: %[[#int_8:]] = OpTypeInt 8 0 | ||
; CHECK-EXP-DAG: %[[#zero:]] = OpConstantNull %[[#int_8]] | ||
; CHECK-EXP-DAG: %[[#eight:]] = OpConstant %[[#int_8]] 8 | ||
; CHECK-EXP-DAG: %[[#sixteen:]] = OpConstant %[[#int_8]] 16 | ||
; CHECK-EXP-DAG: %[[#twentyfour:]] = OpConstant %[[#int_8]] 24 | ||
|
||
; CHECK-LABEL: Begin function test_dot | ||
define noundef i32 @test_dot(i32 noundef %a, i32 noundef %b, i32 noundef %c) { | ||
entry: | ||
; CHECK: %[[#A:]] = OpFunctionParameter %[[#int_32]] | ||
; CHECK: %[[#B:]] = OpFunctionParameter %[[#int_32]] | ||
; CHECK: %[[#C:]] = OpFunctionParameter %[[#int_32]] | ||
|
||
; Test that we use the dot product op when capabilities allow | ||
|
||
; CHECK-DOT: %[[#DOT:]] = OpUDot %[[#int_32]] %[[#A]] %[[#B]] | ||
; CHECK-DOT: %[[#RES:]] = OpIAdd %[[#int_32]] %[[#DOT]] %[[#C]] | ||
|
||
; Test expansion is used when spirv dot product capabilities aren't available: | ||
|
||
; First element of the packed vector | ||
; CHECK-EXP: %[[#A0:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#zero]] %[[#eight]] | ||
; CHECK-EXP: %[[#B0:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#zero]] %[[#eight]] | ||
; CHECK-EXP: %[[#MUL0:]] = OpIMul %[[#int_32]] %[[#A0]] %[[#B0]] | ||
; CHECK-EXP: %[[#MASK0:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL0]] %[[#zero]] %[[#eight]] | ||
; CHECK-EXP: %[[#ACC0:]] = OpIAdd %[[#int_32]] %[[#C]] %[[#MASK0]] | ||
|
||
; Second element of the packed vector | ||
; CHECK-EXP: %[[#A1:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#eight]] %[[#eight]] | ||
; CHECK-EXP: %[[#B1:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#eight]] %[[#eight]] | ||
; CHECK-EXP: %[[#MUL1:]] = OpIMul %[[#int_32]] %[[#A1]] %[[#B1]] | ||
; CHECK-EXP: %[[#MASK1:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL1]] %[[#zero]] %[[#eight]] | ||
; CHECK-EXP: %[[#ACC1:]] = OpIAdd %[[#int_32]] %[[#ACC0]] %[[#MASK1]] | ||
|
||
; Third element of the packed vector | ||
; CHECK-EXP: %[[#A2:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#sixteen]] %[[#eight]] | ||
; CHECK-EXP: %[[#B2:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#sixteen]] %[[#eight]] | ||
; CHECK-EXP: %[[#MUL2:]] = OpIMul %[[#int_32]] %[[#A2]] %[[#B2]] | ||
; CHECK-EXP: %[[#MASK2:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL2]] %[[#zero]] %[[#eight]] | ||
; CHECK-EXP: %[[#ACC2:]] = OpIAdd %[[#int_32]] %[[#ACC1]] %[[#MASK2]] | ||
|
||
; Fourth element of the packed vector | ||
; CHECK-EXP: %[[#A3:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#twentyfour]] %[[#eight]] | ||
; CHECK-EXP: %[[#B3:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#twentyfour]] %[[#eight]] | ||
; CHECK-EXP: %[[#MUL3:]] = OpIMul %[[#int_32]] %[[#A3]] %[[#B3]] | ||
; CHECK-EXP: %[[#MASK3:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL3]] %[[#zero]] %[[#eight]] | ||
|
||
; CHECK-EXP: %[[#RES:]] = OpIAdd %[[#int_32]] %[[#ACC2]] %[[#MASK3]] | ||
; CHECK: OpReturnValue %[[#RES]] | ||
%spv.dot = call i32 @llvm.spv.dot4add.u8packed(i32 %a, i32 %b, i32 %c) | ||
|
||
ret i32 %spv.dot | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.