-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL] Implement dot2add intrinsic #131237
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
17 commits
Select commit
Hold shift + click to select a range
53a21df
dot2add working for dxil without sema check
sumitsays 9aacccd
WIP
sumitsays 7c81ed6
WIP
sumitsays b7ff3bf
WIP: Mostly wrote everything.
sumitsays e56509e
End to end working code for dot2add
sumitsays 275f481
Update SemaCheck and set return type and make void as return type in …
sumitsays 54346f2
Revert not required change
sumitsays 0beb7c7
Remove commented code
sumitsays 807602e
Addressed PR feedback
sumitsays 08a7892
update sema
sumitsays a35eaab
Addressed PR feedback
sumitsays c2b3fd3
use _Float16 instead of __fp16
sumitsays be85207
WIP: Addressed PR feedback
sumitsays 3accc04
address pr feedback
sumitsays c4fae79
remove specific register from expected output
sumitsays e12c903
nit
sumitsays 6d0eb98
Clang format
sumitsays 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,135 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -o - | \ | ||
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL | ||
// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \ | ||
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -o - | \ | ||
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV | ||
|
||
// Test basic lowering to runtime function call. | ||
|
||
// CHECK-LABEL: define {{.*}}test_default_parameter_type | ||
float test_default_parameter_type(half2 p1, half2 p2, float p3) { | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_float_arg2_type | ||
float test_float_arg2_type(half2 p1, float2 p2, float p3) { | ||
// CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_float_arg1_type | ||
float test_float_arg1_type(float2 p1, half2 p2, float p3) { | ||
// CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_double_arg3_type | ||
float test_double_arg3_type(half2 p1, half2 p2, double p3) { | ||
// CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to float | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_float_arg1_arg2_type | ||
float test_float_arg1_arg2_type(float2 p1, float2 p2, float p3) { | ||
sumitsays marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half> | ||
// CHECK: %conv1 = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_double_arg1_arg2_type | ||
float test_double_arg1_arg2_type(double2 p1, double2 p2, float p3) { | ||
// CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x double> %{{.*}} to <2 x half> | ||
// CHECK: %conv1 = fptrunc reassoc nnan ninf nsz arcp afn <2 x double> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_int16_arg1_arg2_type | ||
float test_int16_arg1_arg2_type(int16_t2 p1, int16_t2 p2, float p3) { | ||
// CHECK: %conv = sitofp <2 x i16> %{{.*}} to <2 x half> | ||
// CHECK: %conv1 = sitofp <2 x i16> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_int32_arg1_arg2_type | ||
float test_int32_arg1_arg2_type(int32_t2 p1, int32_t2 p2, float p3) { | ||
// CHECK: %conv = sitofp <2 x i32> %{{.*}} to <2 x half> | ||
// CHECK: %conv1 = sitofp <2 x i32> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_int64_arg1_arg2_type | ||
float test_int64_arg1_arg2_type(int64_t2 p1, int64_t2 p2, float p3) { | ||
// CHECK: %conv = sitofp <2 x i64> %{{.*}} to <2 x half> | ||
// CHECK: %conv1 = sitofp <2 x i64> %{{.*}} to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}test_bool_arg1_arg2_type | ||
float test_bool_arg1_arg2_type(bool2 p1, bool2 p2, float p3) { | ||
// CHECK: %loadedv = trunc <2 x i32> %{{.*}} to <2 x i1> | ||
// CHECK: %conv = uitofp <2 x i1> %loadedv to <2 x half> | ||
// CHECK: %loadedv1 = trunc <2 x i32> %{{.*}} to <2 x i1> | ||
// CHECK: %conv2 = uitofp <2 x i1> %loadedv1 to <2 x half> | ||
// CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}) | ||
// CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float | ||
// CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4 | ||
// CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]] | ||
// CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}}) | ||
// CHECK: ret float %[[RES]] | ||
return dot2add(p1, p2, p3); | ||
} |
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,13 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify | ||
|
||
float test_too_few_arg() { | ||
return dot2add(); | ||
// expected-error@-1 {{no matching function for call to 'dot2add'}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 3 arguments, but 0 were provided}} | ||
} | ||
|
||
float test_too_many_arg(half2 p1, half2 p2, float p3) { | ||
return dot2add(p1, p2, p3, p1); | ||
// expected-error@-1 {{no matching function for call to 'dot2add'}} | ||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}} | ||
sumitsays marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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,8 @@ | ||
; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-compute %s | FileCheck %s | ||
|
||
define noundef float @dot2add_simple(<2 x half> noundef %a, <2 x half> noundef %b, float %c) { | ||
entry: | ||
; CHECK: call float @dx.op.dot2AddHalf(i32 162, float %c, half %0, half %1, half %2, half %3) | ||
%ret = call float @llvm.dx.dot2add(<2 x half> %a, <2 x half> %b, float %c) | ||
farzonl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ret float %ret | ||
} |
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.