Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; This test case checks that LLVM -> SPIR-V translation produces valid
; SPIR-V module, where a global variable, defined with non-default
; address space, have correct non-function storage class.
;
; No additional checks are needed in addition to simple translation
; to SPIR-V. In case of an error newly produced SPIR-V module validation
; would fail due to spirv-val that detects problematic SPIR-V code from
; translator and reports it as the following error:
;
; "Variables can not have a function[7] storage class outside of a function".
;
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: %[[#Ptr:]] = OpTypePointer CrossWorkgroup %[[#]]
; CHECK: %[[#]] = OpVariable %[[#Ptr]] CrossWorkgroup %[[#]]

@G = addrspace(1) global i1 true

define spir_func i1 @f(i1 %0) {
store i1 %0, ptr addrspace(1) @G, align 1
ret i1 %0
}
37 changes: 37 additions & 0 deletions llvm/test/CodeGen/SPIRV/SamplerArgNonKernel.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}

;CHECK: OpEntryPoint Kernel %[[#KernelId:]]
;CHECK: %[[#image2d_t:]] = OpTypeImage
;CHECK: %[[#sampler_t:]] = OpTypeSampler
;CHECK: %[[#sampled_image_t:]] = OpTypeSampledImage

define spir_func float @test(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp) {
;CHECK-NOT: %[[#KernelId]] = OpFunction %[[#]]
;CHECK: OpFunction
;CHECK: %[[#image:]] = OpFunctionParameter %[[#image2d_t]]
;CHECK: %[[#sampler:]] = OpFunctionParameter %[[#sampler_t]]
entry:
%call = call spir_func <4 x i32> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp, <2 x i32> zeroinitializer)
;CHECK: %[[#sampled_image:]] = OpSampledImage %[[#sampled_image_t]] %[[#image]] %[[#sampler]]
;CHECK: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#sampled_image]] %[[#]] Lod %[[#]]

%0 = extractelement <4 x i32> %call, i32 0
%conv = sitofp i32 %0 to float
ret float %conv
}

declare spir_func <4 x i32> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0), i32, <2 x i32>)

define spir_kernel void @test2(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp, ptr addrspace(1) %result) {
;CHECK: %[[#KernelId]] = OpFunction %[[#]]
entry:
%call = call spir_func float @test(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp)
%0 = load float, ptr addrspace(1) %result, align 4
%add = fadd float %0, %call
store float %add, ptr addrspace(1) %result, align 4
ret void
}
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/SPIRV/align-duplicate.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o -
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; Test that duplicate align information does not result in SPIR-V validation
; errors due to duplicate Alignment Decorations.

;CHECK: OpDecorate %[[#Var:]] Alignment
;CHECK: %[[#Var]] = OpVariable %[[#]]

define spir_func void @f() {
%res = alloca i16, align 2, !spirv.Decorations !1
ret void
}

!1 = !{!2}
!2 = !{i32 44, i32 2}
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/SPIRV/duplicate-types.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Check that we don't end up with duplicated array types in TypeMap.
; No FileCheck needed, we only want to check the absence of errors.
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o -
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}

; CHECK: %[[#]] = OpTypeArray %[[#]] %[[#]]
; CHECK-NOT: OpTypeArray

%duplicate = type { [2 x ptr addrspace(4)] }

define spir_kernel void @foo() {
entry:
alloca [2 x ptr addrspace(4)], align 8
alloca %duplicate, align 8
ret void
}