[llvm] [SPIRV] Test basic float and int types (PR #66282)

Natalie Chouinard via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 12:54:25 PDT 2023


https://github.com/sudonatalie created https://github.com/llvm/llvm-project/pull/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

>From 3db1a6a0c48bb34b71fb85f7657c3d28bae5e7ee Mon Sep 17 00:00:00 2001
From: Natalie Chouinard <chouinard at google.com>
Date: Wed, 13 Sep 2023 19:36:25 +0000
Subject: [PATCH] [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 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/hlsl-intrinsics/basic_float_types.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/basic_float_types.ll
new file mode 100644
index 000000000000000..c64992297719040
--- /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 000000000000000..ebe2f4e168a4d09
--- /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
+}



More information about the llvm-commits mailing list