From ff8b37b5b7984ad9403c00d4787b5e0f7f5b71d7 Mon Sep 17 00:00:00 2001 From: Natalie Chouinard Date: Wed, 13 Sep 2023 19:36:25 +0000 Subject: [PATCH 1/3] [SPIRV] Test basic float and int types Add Int16, Int64 and Float64 capabilities as always available for Vulkan (since 1.0), and add tests covering most of the basic types from clang/test/CodeGenHLSL/basic_types.hlsl except for half floats. Depends on D156049 --- llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 3 + .../hlsl-intrinsics/basic_float_types.ll | 49 +++++++++++++ .../SPIRV/hlsl-intrinsics/basic_int_types.ll | 71 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_int_types.ll diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp index 065eacf6ad1f1..3754f57ef3ac7 100644 --- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp @@ -587,6 +587,9 @@ void RequirementHandler::initAvailableCapabilitiesForOpenCL( void RequirementHandler::initAvailableCapabilitiesForVulkan( const SPIRVSubtarget &ST) { addAvailableCaps({Capability::Shader, Capability::Linkage}); + + // Provided by Vulkan version 1.0. + addAvailableCaps({Capability::Int16, Capability::Int64, Capability::Float64}); } } // namespace SPIRV diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll new file mode 100644 index 0000000000000..c649922977190 --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll @@ -0,0 +1,49 @@ +; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s + +define void @main() { +entry: +; CHECK-DAG: %[[#float:]] = OpTypeFloat 32 +; CHECK-DAG: %[[#double:]] = OpTypeFloat 64 + +; CHECK-DAG: %[[#v2float:]] = OpTypeVector %[[#float]] 2 +; CHECK-DAG: %[[#v3float:]] = OpTypeVector %[[#float]] 3 +; CHECK-DAG: %[[#v4float:]] = OpTypeVector %[[#float]] 4 + +; CHECK-DAG: %[[#v2double:]] = OpTypeVector %[[#double]] 2 +; CHECK-DAG: %[[#v3double:]] = OpTypeVector %[[#double]] 3 +; CHECK-DAG: %[[#v4double:]] = OpTypeVector %[[#double]] 4 + +; CHECK-DAG: %[[#ptr_Function_float:]] = OpTypePointer Function %[[#float]] +; CHECK-DAG: %[[#ptr_Function_double:]] = OpTypePointer Function %[[#double]] +; CHECK-DAG: %[[#ptr_Function_v2float:]] = OpTypePointer Function %[[#v2float]] +; CHECK-DAG: %[[#ptr_Function_v3float:]] = OpTypePointer Function %[[#v3float]] +; CHECK-DAG: %[[#ptr_Function_v4float:]] = OpTypePointer Function %[[#v4float]] +; CHECK-DAG: %[[#ptr_Function_v2double:]] = OpTypePointer Function %[[#v2double]] +; CHECK-DAG: %[[#ptr_Function_v3double:]] = OpTypePointer Function %[[#v3double]] +; CHECK-DAG: %[[#ptr_Function_v4double:]] = OpTypePointer Function %[[#v4double]] + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_float]] Function + %float_Val = alloca float, align 4 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_double]] Function + %double_Val = alloca double, align 8 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v2float]] Function + %float2_Val = alloca <2 x float>, align 8 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v3float]] Function + %float3_Val = alloca <3 x float>, align 16 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v4float]] Function + %float4_Val = alloca <4 x float>, align 16 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v2double]] Function + %double2_Val = alloca <2 x double>, align 16 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v3double]] Function + %double3_Val = alloca <3 x double>, align 32 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v4double]] Function + %double4_Val = alloca <4 x double>, align 32 + ret void +} diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_int_types.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_int_types.ll new file mode 100644 index 0000000000000..ebe2f4e168a4d --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_int_types.ll @@ -0,0 +1,71 @@ +; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s + +define void @main() { +entry: +; CHECK-DAG: %[[#short:]] = OpTypeInt 16 0 +; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0 +; CHECK-DAG: %[[#long:]] = OpTypeInt 64 0 + +; CHECK-DAG: %[[#v2short:]] = OpTypeVector %[[#short]] 2 +; CHECK-DAG: %[[#v3short:]] = OpTypeVector %[[#short]] 3 +; CHECK-DAG: %[[#v4short:]] = OpTypeVector %[[#short]] 4 + +; CHECK-DAG: %[[#v2int:]] = OpTypeVector %[[#int]] 2 +; CHECK-DAG: %[[#v3int:]] = OpTypeVector %[[#int]] 3 +; CHECK-DAG: %[[#v4int:]] = OpTypeVector %[[#int]] 4 + +; CHECK-DAG: %[[#v2long:]] = OpTypeVector %[[#long]] 2 +; CHECK-DAG: %[[#v3long:]] = OpTypeVector %[[#long]] 3 +; CHECK-DAG: %[[#v4long:]] = OpTypeVector %[[#long]] 4 + +; CHECK-DAG: %[[#ptr_Function_short:]] = OpTypePointer Function %[[#short]] +; CHECK-DAG: %[[#ptr_Function_int:]] = OpTypePointer Function %[[#int]] +; CHECK-DAG: %[[#ptr_Function_long:]] = OpTypePointer Function %[[#long]] +; CHECK-DAG: %[[#ptr_Function_v2short:]] = OpTypePointer Function %[[#v2short]] +; CHECK-DAG: %[[#ptr_Function_v3short:]] = OpTypePointer Function %[[#v3short]] +; CHECK-DAG: %[[#ptr_Function_v4short:]] = OpTypePointer Function %[[#v4short]] +; CHECK-DAG: %[[#ptr_Function_v2int:]] = OpTypePointer Function %[[#v2int]] +; CHECK-DAG: %[[#ptr_Function_v3int:]] = OpTypePointer Function %[[#v3int]] +; CHECK-DAG: %[[#ptr_Function_v4int:]] = OpTypePointer Function %[[#v4int]] +; CHECK-DAG: %[[#ptr_Function_v2long:]] = OpTypePointer Function %[[#v2long]] +; CHECK-DAG: %[[#ptr_Function_v3long:]] = OpTypePointer Function %[[#v3long]] +; CHECK-DAG: %[[#ptr_Function_v4long:]] = OpTypePointer Function %[[#v4long]] + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_short]] Function + %int16_t_Val = alloca i16, align 2 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_int]] Function + %int_Val = alloca i32, align 4 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_long]] Function + %int64_t_Val = alloca i64, align 8 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v2short]] Function + %int16_t2_Val = alloca <2 x i16>, align 4 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v3short]] Function + %int16_t3_Val = alloca <3 x i16>, align 8 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v4short]] Function + %int16_t4_Val = alloca <4 x i16>, align 8 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v2int]] Function + %int2_Val = alloca <2 x i32>, align 8 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v3int]] Function + %int3_Val = alloca <3 x i32>, align 16 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v4int]] Function + %int4_Val = alloca <4 x i32>, align 16 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v2long]] Function + %int64_t2_Val = alloca <2 x i64>, align 16 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v3long]] Function + %int64_t3_Val = alloca <3 x i64>, align 32 + +; CHECK: %[[#]] = OpVariable %[[#ptr_Function_v4long]] Function + %int64_t4_Val = alloca <4 x i64>, align 32 + + ret void +} From e9587782fefbc9ca77d97da4ac9ab5fb2e8eb47f Mon Sep 17 00:00:00 2001 From: Natalie Chouinard Date: Thu, 14 Sep 2023 14:59:55 +0000 Subject: [PATCH 2/3] Move tests --- .../test/CodeGen/SPIRV/{hlsl-intrinsics => }/basic_float_types.ll | 0 llvm/test/CodeGen/SPIRV/{hlsl-intrinsics => }/basic_int_types.ll | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename llvm/test/CodeGen/SPIRV/{hlsl-intrinsics => }/basic_float_types.ll (100%) rename llvm/test/CodeGen/SPIRV/{hlsl-intrinsics => }/basic_int_types.ll (100%) diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll b/llvm/test/CodeGen/SPIRV/basic_float_types.ll similarity index 100% rename from llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll rename to llvm/test/CodeGen/SPIRV/basic_float_types.ll diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_int_types.ll b/llvm/test/CodeGen/SPIRV/basic_int_types.ll similarity index 100% rename from llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_int_types.ll rename to llvm/test/CodeGen/SPIRV/basic_int_types.ll From 77555294cb8d6930237f9d9a696ad1fa5d6d60b4 Mon Sep 17 00:00:00 2001 From: Natalie Chouinard Date: Thu, 14 Sep 2023 18:13:36 +0000 Subject: [PATCH 3/3] Add RUN lines --- llvm/test/CodeGen/SPIRV/basic_float_types.ll | 2 ++ llvm/test/CodeGen/SPIRV/basic_int_types.ll | 2 ++ 2 files changed, 4 insertions(+) diff --git a/llvm/test/CodeGen/SPIRV/basic_float_types.ll b/llvm/test/CodeGen/SPIRV/basic_float_types.ll index c649922977190..4287adc85cfd8 100644 --- a/llvm/test/CodeGen/SPIRV/basic_float_types.ll +++ b/llvm/test/CodeGen/SPIRV/basic_float_types.ll @@ -1,4 +1,6 @@ ; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s +; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s +; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s define void @main() { entry: diff --git a/llvm/test/CodeGen/SPIRV/basic_int_types.ll b/llvm/test/CodeGen/SPIRV/basic_int_types.ll index ebe2f4e168a4d..b479cee0bed71 100644 --- a/llvm/test/CodeGen/SPIRV/basic_int_types.ll +++ b/llvm/test/CodeGen/SPIRV/basic_int_types.ll @@ -1,4 +1,6 @@ ; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s +; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s +; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s define void @main() { entry: