-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Implements isnan() HLSL intrinsic for DXIL and SPIR-V targets. #157733
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,20 @@ | ||
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ | ||
// RUN: -o - | FileCheck %s | ||
|
||
// CHECK: define hidden noundef i1 @ | ||
// CHECK: %hlsl.isnan = call i1 @llvm.dx.isnan.f32( | ||
// CHECK: ret i1 %hlsl.isnan | ||
bool test_isnan_double(double p0) { return isnan(p0); } | ||
// CHECK: define hidden noundef <2 x i1> @ | ||
// CHECK: %hlsl.isnan = call <2 x i1> @llvm.dx.isnan.v2f32 | ||
// CHECK: ret <2 x i1> %hlsl.isnan | ||
bool2 test_isnan_double2(double2 p0) { return isnan(p0); } | ||
// CHECK: define hidden noundef <3 x i1> @ | ||
// CHECK: %hlsl.isnan = call <3 x i1> @llvm.dx.isnan.v3f32 | ||
// CHECK: ret <3 x i1> %hlsl.isnan | ||
bool3 test_isnan_double3(double3 p0) { return isnan(p0); } | ||
// CHECK: define hidden noundef <4 x i1> @ | ||
// CHECK: %hlsl.isnan = call <4 x i1> @llvm.dx.isnan.v4f32 | ||
// CHECK: ret <4 x i1> %hlsl.isnan | ||
bool4 test_isnan_double4(double4 p0) { return isnan(p0); } |
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,62 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ | ||
// RUN: --check-prefixes=CHECK,DXCHECK,NATIVE_HALF | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ | ||
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,DXCHECK,NO_HALF | ||
|
||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ | ||
// RUN: --check-prefixes=CHECK,SPVCHECK,NATIVE_HALF | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \ | ||
// RUN: -o - | FileCheck %s --check-prefixes=CHECK,SPVCHECK,NO_HALF | ||
|
||
// DXCHECK: define hidden [[FN_TYPE:]]noundef i1 @ | ||
// SPVCHECK: define hidden [[FN_TYPE:spir_func ]]noundef i1 @ | ||
// DXCHECK: %hlsl.isnan = call i1 @llvm.[[ICF:dx]].isnan.f32( | ||
// SPVCHECK: %hlsl.isnan = call i1 @llvm.[[ICF:spv]].isnan.f32( | ||
// CHECK: ret i1 %hlsl.isnan | ||
bool test_isnan_float(float p0) { return isnan(p0); } | ||
|
||
// CHECK: define hidden [[FN_TYPE]]noundef i1 @ | ||
// NATIVE_HALF: %hlsl.isnan = call i1 @llvm.[[ICF]].isnan.f16( | ||
// NO_HALF: %hlsl.isnan = call i1 @llvm.[[ICF]].isnan.f32( | ||
// CHECK: ret i1 %hlsl.isnan | ||
bool test_isnan_half(half p0) { return isnan(p0); } | ||
|
||
// CHECK: define hidden [[FN_TYPE]]noundef <2 x i1> @ | ||
// NATIVE_HALF: %hlsl.isnan = call <2 x i1> @llvm.[[ICF]].isnan.v2f16 | ||
// NO_HALF: %hlsl.isnan = call <2 x i1> @llvm.[[ICF]].isnan.v2f32( | ||
// CHECK: ret <2 x i1> %hlsl.isnan | ||
bool2 test_isnan_half2(half2 p0) { return isnan(p0); } | ||
|
||
// NATIVE_HALF: define hidden [[FN_TYPE]]noundef <3 x i1> @ | ||
// NATIVE_HALF: %hlsl.isnan = call <3 x i1> @llvm.[[ICF]].isnan.v3f16 | ||
// NO_HALF: %hlsl.isnan = call <3 x i1> @llvm.[[ICF]].isnan.v3f32( | ||
// CHECK: ret <3 x i1> %hlsl.isnan | ||
bool3 test_isnan_half3(half3 p0) { return isnan(p0); } | ||
|
||
// NATIVE_HALF: define hidden [[FN_TYPE]]noundef <4 x i1> @ | ||
// NATIVE_HALF: %hlsl.isnan = call <4 x i1> @llvm.[[ICF]].isnan.v4f16 | ||
// NO_HALF: %hlsl.isnan = call <4 x i1> @llvm.[[ICF]].isnan.v4f32( | ||
// CHECK: ret <4 x i1> %hlsl.isnan | ||
bool4 test_isnan_half4(half4 p0) { return isnan(p0); } | ||
|
||
|
||
// CHECK: define hidden [[FN_TYPE]]noundef <2 x i1> @ | ||
// CHECK: %hlsl.isnan = call <2 x i1> @llvm.[[ICF]].isnan.v2f32 | ||
// CHECK: ret <2 x i1> %hlsl.isnan | ||
bool2 test_isnan_float2(float2 p0) { return isnan(p0); } | ||
|
||
// CHECK: define hidden [[FN_TYPE]]noundef <3 x i1> @ | ||
// CHECK: %hlsl.isnan = call <3 x i1> @llvm.[[ICF]].isnan.v3f32 | ||
// CHECK: ret <3 x i1> %hlsl.isnan | ||
bool3 test_isnan_float3(float3 p0) { return isnan(p0); } | ||
|
||
// CHECK: define hidden [[FN_TYPE]]noundef <4 x i1> @ | ||
// CHECK: %hlsl.isnan = call <4 x i1> @llvm.[[ICF]].isnan.v4f32 | ||
// CHECK: ret <4 x i1> %hlsl.isnan | ||
bool4 test_isnan_float4(float4 p0) { return isnan(p0); } |
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,38 @@ | ||
|
||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify | ||
|
||
bool test_too_few_arg() { | ||
return __builtin_hlsl_elementwise_isnan(); | ||
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}} | ||
} | ||
|
||
bool2 test_too_many_arg(float2 p0) { | ||
return __builtin_hlsl_elementwise_isnan(p0, p0); | ||
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}} | ||
} | ||
|
||
bool builtin_bool_to_float_type_promotion(bool p1) { | ||
return __builtin_hlsl_elementwise_isnan(p1); | ||
// expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'bool')}} | ||
} | ||
|
||
bool builtin_isnan_int_to_float_promotion(int p1) { | ||
return __builtin_hlsl_elementwise_isnan(p1); | ||
// expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int')}} | ||
} | ||
|
||
bool2 builtin_isnan_int2_to_float2_promotion(int2 p1) { | ||
return __builtin_hlsl_elementwise_isnan(p1); | ||
// expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'int2' (aka 'vector<int, 2>'))}} | ||
} | ||
|
||
// builtins are variadic functions and so are subject to DefaultVariadicArgumentPromotion | ||
half builtin_isnan_half_scalar (half p0) { | ||
return __builtin_hlsl_elementwise_isnan (p0); | ||
// expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} | ||
} | ||
|
||
float builtin_isnan_float_scalar ( float p0) { | ||
return __builtin_hlsl_elementwise_isnan (p0); | ||
// expected-error@-1 {{1st argument must be a scalar or vector of 16 or 32 bit floating-point types (was 'double')}} | ||
} |
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,45 @@ | ||
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan %s -o - | FileCheck %s | ||
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o - -filetype=obj | spirv-val --target-env spv1.4 %} | ||
|
||
; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16 | ||
; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32 | ||
; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4 | ||
; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4 | ||
; CHECK-DAG: %[[#bool:]] = OpTypeBool | ||
; CHECK-DAG: %[[#vec4_bool:]] = OpTypeVector %[[#bool]] 4 | ||
|
||
define noundef i1 @isnan_half(half noundef %a) { | ||
entry: | ||
; CHECK: %[[#]] = OpFunction %[[#bool]] None %[[#]] | ||
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_16]] | ||
; CHECK: %[[#]] = OpIsNan %[[#bool]] %[[#arg0]] | ||
%hlsl.isnan = call i1 @llvm.spv.isnan.f16(half %a) | ||
ret i1 %hlsl.isnan | ||
} | ||
|
||
define noundef i1 @isnan_float(float noundef %a) { | ||
entry: | ||
; CHECK: %[[#]] = OpFunction %[[#bool]] None %[[#]] | ||
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_32]] | ||
; CHECK: %[[#]] = OpIsNan %[[#bool]] %[[#arg0]] | ||
%hlsl.isnan = call i1 @llvm.spv.isnan.f32(float %a) | ||
ret i1 %hlsl.isnan | ||
} | ||
|
||
define noundef <4 x i1> @isnan_half4(<4 x half> noundef %a) { | ||
entry: | ||
; CHECK: %[[#]] = OpFunction %[[#vec4_bool]] None %[[#]] | ||
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_16]] | ||
; CHECK: %[[#]] = OpIsNan %[[#vec4_bool]] %[[#arg0]] | ||
%hlsl.isnan = call <4 x i1> @llvm.spv.isnan.v4f16(<4 x half> %a) | ||
ret <4 x i1> %hlsl.isnan | ||
} | ||
|
||
define noundef <4 x i1> @isnan_float4(<4 x float> noundef %a) { | ||
entry: | ||
; CHECK: %[[#]] = OpFunction %[[#vec4_bool]] None %[[#]] | ||
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]] | ||
; CHECK: %[[#]] = OpIsNan %[[#vec4_bool]] %[[#arg0]] | ||
%hlsl.isnan = call <4 x i1> @llvm.spv.isnan.v4f32(<4 x float> %a) | ||
ret <4 x i1> %hlsl.isnan | ||
} |
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.