Resolves #99114. Tasks completed: - Implement `faceforward` in `hlsl_intrinsics.h`/`hlsl_intrinsic_helpers.h` - Implement `faceforward` SPIR-V target builtin in `clang/include/clang/Basic/BuiltinsSPIRV.td` - Add a SPIR-V fast path in `hlsl_intrinsic_helpers.h` - Add sema checks for `faceforward` to `CheckSPIRVBuiltinFunctionCall` in `clang/lib/Sema/SemaSPIRV.cpp` - Add codegen for SPIR-V `faceforward` builtin to `EmitSPIRVBuiltinExpr` in `SPIR.cpp` - Add HLSL codegen tests to `clang/test/CodeGenHLSL/builtins/faceforward.hlsl` - Add SPIRV builtin codegen tests to `clang/test/CodeGenSPIRV/Builtins/faceforward.c` - Add sema tests to `clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl` - Add spirv sema tests to `clang/test/SemaSPIRV/BuiltIns/faceforward-errors.c` - Create the `int_spv_faceforward` intrinsic in `IntrinsicsSPIRV.td` - In `SPIRVInstructionSelector.cpp` create the `faceforward` lowering and map it to `int_spv_faceforward` in `SPIRVInstructionSelector::selectIntrinsic` - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll` Incomplete tasks: - Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/opencl/faceforward.ll` - Not applicable because the OpenCL SPIR-V extended instruction set does not include a `faceforward` function Follow-up tasks: - Implement pattern matching for `faceforward` in `SPIRVCombine.td` and `SPIRVPreLegalizerCombiner.cpp` - In `faceforward.ll`, change `--target-env spv1.4` to `vulkan1.3` and update the test accordingly once [#136344](https://github.com/llvm/llvm-project/issues/136344) has been resolved
68 lines
4.8 KiB
C
68 lines
4.8 KiB
C
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
|
|
|
|
// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s
|
|
|
|
typedef _Float16 half;
|
|
typedef half half2 __attribute__((ext_vector_type(2)));
|
|
typedef half half3 __attribute__((ext_vector_type(3)));
|
|
typedef half half4 __attribute__((ext_vector_type(4)));
|
|
typedef float float2 __attribute__((ext_vector_type(2)));
|
|
typedef float float3 __attribute__((ext_vector_type(3)));
|
|
typedef float float4 __attribute__((ext_vector_type(4)));
|
|
|
|
// CHECK-LABEL: define spir_func half @test_faceforward_half(
|
|
// CHECK-SAME: half noundef [[N:%.*]], half noundef [[I:%.*]], half noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call half @llvm.spv.faceforward.f16(half [[N]], half [[I]], half [[NG]])
|
|
// CHECK-NEXT: ret half [[SPV_FACEFORWARD]]
|
|
half test_faceforward_half(half N, half I, half Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func <2 x half> @test_faceforward_half2(
|
|
// CHECK-SAME: <2 x half> noundef [[N:%.*]], <2 x half> noundef [[I:%.*]], <2 x half> noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call <2 x half> @llvm.spv.faceforward.v2f16(<2 x half> [[N]], <2 x half> [[I]], <2 x half> [[NG]])
|
|
// CHECK-NEXT: ret <2 x half> [[SPV_FACEFORWARD]]
|
|
half2 test_faceforward_half2(half2 N, half2 I, half2 Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func <3 x half> @test_faceforward_half3(
|
|
// CHECK-SAME: <3 x half> noundef [[N:%.*]], <3 x half> noundef [[I:%.*]], <3 x half> noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call <3 x half> @llvm.spv.faceforward.v3f16(<3 x half> [[N]], <3 x half> [[I]], <3 x half> [[NG]])
|
|
// CHECK-NEXT: ret <3 x half> [[SPV_FACEFORWARD]]
|
|
half3 test_faceforward_half3(half3 N, half3 I, half3 Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func <4 x half> @test_faceforward_half4(
|
|
// CHECK-SAME: <4 x half> noundef [[N:%.*]], <4 x half> noundef [[I:%.*]], <4 x half> noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call <4 x half> @llvm.spv.faceforward.v4f16(<4 x half> [[N]], <4 x half> [[I]], <4 x half> [[NG]])
|
|
// CHECK-NEXT: ret <4 x half> [[SPV_FACEFORWARD]]
|
|
half4 test_faceforward_half4(half4 N, half4 I, half4 Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func float @test_faceforward_float(
|
|
// CHECK-SAME: float noundef [[N:%.*]], float noundef [[I:%.*]], float noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call float @llvm.spv.faceforward.f32(float [[N]], float [[I]], float [[NG]])
|
|
// CHECK-NEXT: ret float [[SPV_FACEFORWARD]]
|
|
float test_faceforward_float(float N, float I, float Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func <2 x float> @test_faceforward_float2(
|
|
// CHECK-SAME: <2 x float> noundef [[N:%.*]], <2 x float> noundef [[I:%.*]], <2 x float> noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call <2 x float> @llvm.spv.faceforward.v2f32(<2 x float> [[N]], <2 x float> [[I]], <2 x float> [[NG]])
|
|
// CHECK-NEXT: ret <2 x float> [[SPV_FACEFORWARD]]
|
|
float2 test_faceforward_float2(float2 N, float2 I, float2 Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func <3 x float> @test_faceforward_float3(
|
|
// CHECK-SAME: <3 x float> noundef [[N:%.*]], <3 x float> noundef [[I:%.*]], <3 x float> noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call <3 x float> @llvm.spv.faceforward.v3f32(<3 x float> [[N]], <3 x float> [[I]], <3 x float> [[NG]])
|
|
// CHECK-NEXT: ret <3 x float> [[SPV_FACEFORWARD]]
|
|
float3 test_faceforward_float3(float3 N, float3 I, float3 Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|
|
|
|
// CHECK-LABEL: define spir_func <4 x float> @test_faceforward_float4(
|
|
// CHECK-SAME: <4 x float> noundef [[N:%.*]], <4 x float> noundef [[I:%.*]], <4 x float> noundef [[NG:%.*]]) local_unnamed_addr #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[SPV_FACEFORWARD:%.*]] = tail call <4 x float> @llvm.spv.faceforward.v4f32(<4 x float> [[N]], <4 x float> [[I]], <4 x float> [[NG]])
|
|
// CHECK-NEXT: ret <4 x float> [[SPV_FACEFORWARD]]
|
|
float4 test_faceforward_float4(float4 N, float4 I, float4 Ng) { return __builtin_spirv_faceforward(N, I, Ng); }
|