-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HLSL][DXIL] Implement asdouble
intrinsic
#114847
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
c0bf6ac
[HLSL] Add `asdouble` builtin
inbelic e8a47ba
[HLSL] Add codegen to llvm intrinsics
inbelic 9d300da
[DXIL] Using a dx intrinsic for directx backend
inbelic b217494
review comment:
inbelic b646c7c
add asdouble to overload api
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,37 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \ | ||
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL | ||
// RUN: %clang_cc1 -finclude-default-header -triple \ | ||
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \ | ||
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPV | ||
|
||
// Test lowering of asdouble expansion to shuffle/bitcast and splat when required | ||
|
||
// CHECK-LABEL: test_uint | ||
double test_uint(uint low, uint high) { | ||
// CHECK-SPV: %[[LOW_INSERT:.*]] = insertelement <1 x i32> | ||
// CHECK-SPV: %[[LOW_SHUFFLE:.*]] = shufflevector <1 x i32> %[[LOW_INSERT]], {{.*}} zeroinitializer | ||
// CHECK-SPV: %[[HIGH_INSERT:.*]] = insertelement <1 x i32> | ||
// CHECK-SPV: %[[HIGH_SHUFFLE:.*]] = shufflevector <1 x i32> %[[HIGH_INSERT]], {{.*}} zeroinitializer | ||
|
||
// CHECK-SPV: %[[SHUFFLE0:.*]] = shufflevector <1 x i32> %[[LOW_SHUFFLE]], <1 x i32> %[[HIGH_SHUFFLE]], | ||
// CHECK-SPV-SAME: {{.*}} <i32 0, i32 1> | ||
// CHECK-SPV: bitcast <2 x i32> %[[SHUFFLE0]] to double | ||
|
||
// CHECK-DXIL: call double @llvm.dx.asdouble.i32 | ||
return asdouble(low, high); | ||
} | ||
|
||
// CHECK-DXIL: declare double @llvm.dx.asdouble.i32 | ||
|
||
// CHECK-LABEL: test_vuint | ||
double3 test_vuint(uint3 low, uint3 high) { | ||
// CHECK-SPV: %[[SHUFFLE1:.*]] = shufflevector | ||
// CHECK-SPV-SAME: {{.*}} <i32 0, i32 3, i32 1, i32 4, i32 2, i32 5> | ||
// CHECK-SPV: bitcast <6 x i32> %[[SHUFFLE1]] to <3 x double> | ||
|
||
// CHECK-DXIL: call <3 x double> @llvm.dx.asdouble.v3i32 | ||
return asdouble(low, high); | ||
} | ||
|
||
// CHECK-DXIL: declare <3 x double> @llvm.dx.asdouble.v3i32 |
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,16 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify | ||
|
||
double test_too_few_arg() { | ||
return __builtin_hlsl_asdouble(); | ||
// expected-error@-1 {{too few arguments to function call, expected 2, have 0}} | ||
} | ||
|
||
double test_too_few_arg_1(uint p0) { | ||
return __builtin_hlsl_asdouble(p0); | ||
// expected-error@-1 {{too few arguments to function call, expected 2, have 1}} | ||
} | ||
|
||
double test_too_many_arg(uint p0) { | ||
return __builtin_hlsl_asdouble(p0, p0, p0); | ||
// expected-error@-1 {{too many arguments to function call, expected 2, have 3}} | ||
} | ||
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,22 @@ | ||
; RUN: opt -S -scalarizer -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s | ||
|
||
; Test that for scalar and vector inputs, asdouble maps down to the makeDouble | ||
; DirectX op | ||
|
||
define noundef double @asdouble_scalar(i32 noundef %low, i32 noundef %high) { | ||
; CHECK: call double @dx.op.makeDouble(i32 101, i32 %low, i32 %high) | ||
%ret = call double @llvm.dx.asdouble.i32(i32 %low, i32 %high) | ||
ret double %ret | ||
} | ||
|
||
declare double @llvm.dx.asdouble.i32(i32, i32) | ||
|
||
define noundef <3 x double> @asdouble_vec(<3 x i32> noundef %low, <3 x i32> noundef %high) { | ||
; CHECK: call double @dx.op.makeDouble(i32 101, i32 %low.i0, i32 %high.i0) | ||
; CHECK: call double @dx.op.makeDouble(i32 101, i32 %low.i1, i32 %high.i1) | ||
; CHECK: call double @dx.op.makeDouble(i32 101, i32 %low.i2, i32 %high.i2) | ||
%ret = call <3 x double> @llvm.dx.asdouble.v3i32(<3 x i32> %low, <3 x i32> %high) | ||
ret <3 x double> %ret | ||
} | ||
|
||
declare <3 x double> @llvm.dx.asdouble.v3i32(<3 x i32>, <3 x i32>) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like adding some tests to check for type mismatch would be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a type that you have in mind? Most types will be implicitly converted here, I added the custom struct type to illustrate that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any type really, what we really care about here is making sure the error is meaningful to the user. I usually write such tests with
half
,float
orbool
if the former are implicitly cast.