-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HLSL] implement the rcp intrinsic (#83857)
This PR implements the frontend for #70100 This PR is part 1 of 2. Part 2 requires an intrinsic to instructions lowering. - `Builtins.td` - add an `rcp` builtin - `CGBuiltin.cpp` - add the builtin to intrinsic lowering - `hlsl_intrinsics.h` - add the `rcp` api - `SemaChecking.cpp` - reuse frac's sema checks - `IntrinsicsDirectX.td` - add the llvm intrinsic
- Loading branch information
Showing
7 changed files
with
144 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,53 @@ | ||
// 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,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,NO_HALF | ||
|
||
// NATIVE_HALF: define noundef half @ | ||
// NATIVE_HALF: %dx.rcp = call half @llvm.dx.rcp.f16( | ||
// NATIVE_HALF: ret half %dx.rcp | ||
// NO_HALF: define noundef float @"?test_rcp_half@@YA$halff@$halff@@Z"( | ||
// NO_HALF: %dx.rcp = call float @llvm.dx.rcp.f32( | ||
// NO_HALF: ret float %dx.rcp | ||
half test_rcp_half(half p0) { return rcp(p0); } | ||
// NATIVE_HALF: define noundef <2 x half> @ | ||
// NATIVE_HALF: %dx.rcp = call <2 x half> @llvm.dx.rcp.v2f16 | ||
// NATIVE_HALF: ret <2 x half> %dx.rcp | ||
// NO_HALF: define noundef <2 x float> @ | ||
// NO_HALF: %dx.rcp = call <2 x float> @llvm.dx.rcp.v2f32( | ||
// NO_HALF: ret <2 x float> %dx.rcp | ||
half2 test_rcp_half2(half2 p0) { return rcp(p0); } | ||
// NATIVE_HALF: define noundef <3 x half> @ | ||
// NATIVE_HALF: %dx.rcp = call <3 x half> @llvm.dx.rcp.v3f16 | ||
// NATIVE_HALF: ret <3 x half> %dx.rcp | ||
// NO_HALF: define noundef <3 x float> @ | ||
// NO_HALF: %dx.rcp = call <3 x float> @llvm.dx.rcp.v3f32( | ||
// NO_HALF: ret <3 x float> %dx.rcp | ||
half3 test_rcp_half3(half3 p0) { return rcp(p0); } | ||
// NATIVE_HALF: define noundef <4 x half> @ | ||
// NATIVE_HALF: %dx.rcp = call <4 x half> @llvm.dx.rcp.v4f16 | ||
// NATIVE_HALF: ret <4 x half> %dx.rcp | ||
// NO_HALF: define noundef <4 x float> @ | ||
// NO_HALF: %dx.rcp = call <4 x float> @llvm.dx.rcp.v4f32( | ||
// NO_HALF: ret <4 x float> %dx.rcp | ||
half4 test_rcp_half4(half4 p0) { return rcp(p0); } | ||
|
||
// CHECK: define noundef float @ | ||
// CHECK: %dx.rcp = call float @llvm.dx.rcp.f32( | ||
// CHECK: ret float %dx.rcp | ||
float test_rcp_float(float p0) { return rcp(p0); } | ||
// CHECK: define noundef <2 x float> @ | ||
// CHECK: %dx.rcp = call <2 x float> @llvm.dx.rcp.v2f32 | ||
// CHECK: ret <2 x float> %dx.rcp | ||
float2 test_rcp_float2(float2 p0) { return rcp(p0); } | ||
// CHECK: define noundef <3 x float> @ | ||
// CHECK: %dx.rcp = call <3 x float> @llvm.dx.rcp.v3f32 | ||
// CHECK: ret <3 x float> %dx.rcp | ||
float3 test_rcp_float3(float3 p0) { return rcp(p0); } | ||
// CHECK: define noundef <4 x float> @ | ||
// CHECK: %dx.rcp = call <4 x float> @llvm.dx.rcp.v4f32 | ||
// CHECK: ret <4 x float> %dx.rcp | ||
float4 test_rcp_float4(float4 p0) { return rcp(p0); } |
This file contains 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,27 @@ | ||
|
||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify -verify-ignore-unexpected | ||
|
||
float test_too_few_arg() { | ||
return __builtin_hlsl_elementwise_rcp(); | ||
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}} | ||
} | ||
|
||
float2 test_too_many_arg(float2 p0) { | ||
return __builtin_hlsl_elementwise_rcp(p0, p0); | ||
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}} | ||
} | ||
|
||
float builtin_bool_to_float_type_promotion(bool p1) { | ||
return __builtin_hlsl_elementwise_rcp(p1); | ||
// expected-error@-1 {{1st argument must be a vector, integer or floating point type (was 'bool')}} | ||
} | ||
|
||
float builtin_rcp_int_to_float_promotion(int p1) { | ||
return __builtin_hlsl_elementwise_rcp(p1); | ||
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} | ||
} | ||
|
||
float2 builtin_rcp_int2_to_float2_promotion(int2 p1) { | ||
return __builtin_hlsl_elementwise_rcp(p1); | ||
// expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float)))) float' (vector of 2 'float' values)}} | ||
} |
This file contains 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