llvm-project/llvm/test/CodeGen/SPIRV/transcoding/OpImageSampleExplicitLod.ll
Vyacheslav Levytskyy f9c98068c8
[SPIR-V] Rework usage of virtual registers' types and classes (#101732)
This PR contains changes in virtual register processing aimed to improve
correctness of emitted MIR between passes from the perspective of
MachineVerifier. This potentially helps to detect previously missed
flaws in code emission and harden the test suite. As a measure of
correctness and usefulness of this PR we may use a mode with expensive
checks set on, and MachineVerifier reports problems in the test suite.

In order to satisfy Machine Verifier requirements to MIR correctness not
only a rework of usage of virtual registers' types and classes is
required, but also corrections into pre-legalizer and instruction
selection logics. Namely, the following changes are introduced:
* scalar virtual registers have proper bit width,
* detect register class by SPIR-V type,
* add a superclass for id virtual register classes,
* fix Tablegen rules used for instruction selection,
* fixes of minor existed issues (missed flag for proper representation
of a null constant for OpenCL vs. HLSL, wrong usage of integer virtual
registers as a synonym of any non-type virtual register).
2024-08-12 15:49:43 +02:00

34 lines
2.2 KiB
LLVM

; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; CHECK-SPIRV-DAG: %[[#RetID:]] = OpImageSampleExplicitLod %[[#RetType:]] %[[#]] %[[#]] Lod %[[#]]
; CHECK-SPIRV-DAG: %[[#RetType]] = OpTypeVector %[[#]] 4
; CHECK-SPIRV: %[[#]] = OpCompositeExtract %[[#]] %[[#RetID]] 0
define spir_kernel void @sample_kernel(target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0) %input, i32 %imageSampler, float addrspace(1)* %xOffsets, float addrspace(1)* %yOffsets, float addrspace(1)* %results) {
entry:
%call = call spir_func i32 @_Z13get_global_idj(i32 0)
%call1 = call spir_func i32 @_Z13get_global_idj(i32 1)
%call2.tmp1 = call spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_depth_ro(target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0) %input)
%call2.old = extractelement <2 x i32> %call2.tmp1, i32 0
%mul = mul i32 %call1, %call2.old
%add = add i32 %mul, %call
%arrayidx = getelementptr inbounds float, float addrspace(1)* %xOffsets, i32 %add
%0 = load float, float addrspace(1)* %arrayidx, align 4
%conv = fptosi float %0 to i32
%vecinit = insertelement <2 x i32> undef, i32 %conv, i32 0
%arrayidx3 = getelementptr inbounds float, float addrspace(1)* %yOffsets, i32 %add
%1 = load float, float addrspace(1)* %arrayidx3, align 4
%conv4 = fptosi float %1 to i32
%vecinit5 = insertelement <2 x i32> %vecinit, i32 %conv4, i32 1
%call6.tmp.tmp = call spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv2_i(target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0) %input, i32 %imageSampler, <2 x i32> %vecinit5)
%arrayidx7 = getelementptr inbounds float, float addrspace(1)* %results, i32 %add
store float %call6.tmp.tmp, float addrspace(1)* %arrayidx7, align 4
ret void
}
declare spir_func float @_Z11read_imagef20ocl_image2d_depth_ro11ocl_samplerDv2_i(target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0), i32, <2 x i32>)
declare spir_func i32 @_Z13get_global_idj(i32)
declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_depth_ro(target("spirv.Image", void, 1, 1, 0, 0, 0, 0, 0))