[llvm] 116f7a2 - [SPIRV] Test basic float and int types (#66282)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 07:24:57 PDT 2023


Author: Natalie Chouinard
Date: 2023-09-19T10:24:53-04:00
New Revision: 116f7a2dcb86a7a8812a60fb7101f90329dada19

URL: https://github.com/llvm/llvm-project/commit/116f7a2dcb86a7a8812a60fb7101f90329dada19
DIFF: https://github.com/llvm/llvm-project/commit/116f7a2dcb86a7a8812a60fb7101f90329dada19.diff

LOG: [SPIRV] Test basic float and int types (#66282)

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

Added: 
    llvm/test/CodeGen/SPIRV/basic_float_types.ll
    llvm/test/CodeGen/SPIRV/basic_int_types.ll

Modified: 
    llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 065eacf6ad1f1f7..3754f57ef3ac703 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/basic_float_types.ll b/llvm/test/CodeGen/SPIRV/basic_float_types.ll
new file mode 100644
index 000000000000000..4287adc85cfd846
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/basic_float_types.ll
@@ -0,0 +1,51 @@
+; 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:
+; 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/basic_int_types.ll b/llvm/test/CodeGen/SPIRV/basic_int_types.ll
new file mode 100644
index 000000000000000..b479cee0bed71cc
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/basic_int_types.ll
@@ -0,0 +1,73 @@
+; 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:
+; 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
+}


        


More information about the llvm-commits mailing list