forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cross builtins and cross HLSL function to DirectX and SPIR-V back…
…end (llvm#109180) This PR adds the step intrinsic and an HLSL function that uses it. The SPIRV backend is also implemented. Used llvm#106471 as a reference. Fixes llvm#99095
- Loading branch information
Showing
15 changed files
with
299 additions
and
5 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
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,37 @@ | ||
// 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: -DFNATTRS=noundef -DTARGET=dx | ||
// 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 \ | ||
// RUN: -DFNATTRS=noundef -DTARGET=dx | ||
// 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,NATIVE_HALF \ | ||
// RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv | ||
// 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,NO_HALF \ | ||
// RUN: -DFNATTRS="spir_func noundef" -DTARGET=spv | ||
|
||
// NATIVE_HALF: define [[FNATTRS]] <3 x half> @ | ||
// NATIVE_HALF: call <3 x half> @llvm.[[TARGET]].cross.v3f16(<3 x half> | ||
// NATIVE_HALF: ret <3 x half> %hlsl.cross | ||
// NO_HALF: define [[FNATTRS]] <3 x float> @ | ||
// NO_HALF: call <3 x float> @llvm.[[TARGET]].cross.v3f32(<3 x float> | ||
// NO_HALF: ret <3 x float> %hlsl.cross | ||
half3 test_cross_half3(half3 p0, half3 p1) | ||
{ | ||
return cross(p0, p1); | ||
} | ||
|
||
// CHECK: define [[FNATTRS]] <3 x float> @ | ||
// CHECK: %hlsl.cross = call <3 x float> @llvm.[[TARGET]].cross.v3f32( | ||
// CHECK: ret <3 x float> %hlsl.cross | ||
float3 test_cross_float3(float3 p0, float3 p1) | ||
{ | ||
return cross(p0, p1); | ||
} |
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,43 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -disable-llvm-passes -verify | ||
|
||
void test_too_few_arg() | ||
{ | ||
return __builtin_hlsl_cross(); | ||
// expected-error@-1 {{too few arguments to function call, expected 2, have 0}} | ||
} | ||
|
||
void test_too_many_arg(float3 p0) | ||
{ | ||
return __builtin_hlsl_cross(p0, p0, p0); | ||
// expected-error@-1 {{too many arguments to function call, expected 2, have 3}} | ||
} | ||
|
||
bool builtin_bool_to_float_type_promotion(bool p1) | ||
{ | ||
return __builtin_hlsl_cross(p1, p1); | ||
// expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} | ||
} | ||
|
||
bool builtin_cross_int_to_float_promotion(int p1) | ||
{ | ||
return __builtin_hlsl_cross(p1, p1); | ||
// expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} | ||
} | ||
|
||
bool2 builtin_cross_int2_to_float2_promotion(int2 p1) | ||
{ | ||
return __builtin_hlsl_cross(p1, 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)}} | ||
} | ||
|
||
float2 builtin_cross_float2(float2 p1, float2 p2) | ||
{ | ||
return __builtin_hlsl_cross(p1, p2); | ||
// expected-error@-1 {{too many elements in vector operand (expected 3 elements, have 2)}} | ||
} | ||
|
||
float3 builtin_cross_float3_int3(float3 p1, int3 p2) | ||
{ | ||
return __builtin_hlsl_cross(p1, p2); | ||
// expected-error@-1 {{all arguments to '__builtin_hlsl_cross' must have the same type}} | ||
} |
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,56 @@ | ||
; RUN: opt -S -dxil-intrinsic-expansion < %s | FileCheck %s | ||
|
||
; Make sure dxil operation function calls for cross are generated for half/float. | ||
|
||
declare <3 x half> @llvm.dx.cross.v3f16(<3 x half>, <3 x half>) | ||
declare <3 x float> @llvm.dx.cross.v3f32(<3 x float>, <3 x float>) | ||
|
||
define noundef <3 x half> @test_cross_half3(<3 x half> noundef %p0, <3 x half> noundef %p1) { | ||
entry: | ||
; CHECK: %x0 = extractelement <3 x half> %p0, i64 0 | ||
; CHECK: %x1 = extractelement <3 x half> %p0, i64 1 | ||
; CHECK: %x2 = extractelement <3 x half> %p0, i64 2 | ||
; CHECK: %y0 = extractelement <3 x half> %p1, i64 0 | ||
; CHECK: %y1 = extractelement <3 x half> %p1, i64 1 | ||
; CHECK: %y2 = extractelement <3 x half> %p1, i64 2 | ||
; CHECK: %0 = fmul half %x1, %y2 | ||
; CHECK: %1 = fmul half %x2, %y1 | ||
; CHECK: %hlsl.cross1 = fsub half %0, %1 | ||
; CHECK: %2 = fmul half %x2, %y0 | ||
; CHECK: %3 = fmul half %x0, %y2 | ||
; CHECK: %hlsl.cross2 = fsub half %2, %3 | ||
; CHECK: %4 = fmul half %x0, %y1 | ||
; CHECK: %5 = fmul half %x1, %y0 | ||
; CHECK: %hlsl.cross3 = fsub half %4, %5 | ||
; CHECK: %6 = insertelement <3 x half> undef, half %hlsl.cross1, i64 0 | ||
; CHECK: %7 = insertelement <3 x half> %6, half %hlsl.cross2, i64 1 | ||
; CHECK: %8 = insertelement <3 x half> %7, half %hlsl.cross3, i64 2 | ||
; CHECK: ret <3 x half> %8 | ||
%hlsl.cross = call <3 x half> @llvm.dx.cross.v3f16(<3 x half> %p0, <3 x half> %p1) | ||
ret <3 x half> %hlsl.cross | ||
} | ||
|
||
define noundef <3 x float> @test_cross_float3(<3 x float> noundef %p0, <3 x float> noundef %p1) { | ||
entry: | ||
; CHECK: %x0 = extractelement <3 x float> %p0, i64 0 | ||
; CHECK: %x1 = extractelement <3 x float> %p0, i64 1 | ||
; CHECK: %x2 = extractelement <3 x float> %p0, i64 2 | ||
; CHECK: %y0 = extractelement <3 x float> %p1, i64 0 | ||
; CHECK: %y1 = extractelement <3 x float> %p1, i64 1 | ||
; CHECK: %y2 = extractelement <3 x float> %p1, i64 2 | ||
; CHECK: %0 = fmul float %x1, %y2 | ||
; CHECK: %1 = fmul float %x2, %y1 | ||
; CHECK: %hlsl.cross1 = fsub float %0, %1 | ||
; CHECK: %2 = fmul float %x2, %y0 | ||
; CHECK: %3 = fmul float %x0, %y2 | ||
; CHECK: %hlsl.cross2 = fsub float %2, %3 | ||
; CHECK: %4 = fmul float %x0, %y1 | ||
; CHECK: %5 = fmul float %x1, %y0 | ||
; CHECK: %hlsl.cross3 = fsub float %4, %5 | ||
; CHECK: %6 = insertelement <3 x float> undef, float %hlsl.cross1, i64 0 | ||
; CHECK: %7 = insertelement <3 x float> %6, float %hlsl.cross2, i64 1 | ||
; CHECK: %8 = insertelement <3 x float> %7, float %hlsl.cross3, i64 2 | ||
; CHECK: ret <3 x float> %8 | ||
%hlsl.cross = call <3 x float> @llvm.dx.cross.v3f32(<3 x float> %p0, <3 x float> %p1) | ||
ret <3 x float> %hlsl.cross | ||
} |
Oops, something went wrong.