Skip to content

Commit 4b18b19

Browse files
authored
properly handle LOD values when nontemporal image operand is present (#3050)
Instead of checking that the image operands are equal to the LOD mask, check that the LOD bit is in the image operands. This way an LOD value of zero may be ignored even when image operands contains bits other than the LOD bit, such as for the SPIR-V 1.6 nontemporal image operand. fixes #3049
1 parent a3a498d commit 4b18b19

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,10 @@ SPIRVToOCLBase::mutateCallImageOperands(CallInst *CI, StringRef NewFuncName,
752752
ConstantFP *LodVal = dyn_cast<ConstantFP>(Mutator.getArg(ImOpArgIndex));
753753
// If the image operand is LOD and its value is zero, drop it too.
754754
if (LodVal && LodVal->isNullValue() &&
755-
ImOpValue == ImageOperandsMask::ImageOperandsLodMask)
755+
ImOpValue & ImageOperandsMask::ImageOperandsLodMask) {
756756
Mutator.removeArgs(ImOpArgIndex, Mutator.arg_size() - ImOpArgIndex);
757+
ImOpValue &= ~ImageOperandsMask::ImageOperandsLodMask;
758+
}
757759
}
758760
}
759761
return Mutator;

test/image_operand_nontemporal.spvasm

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; Tests the Nontemporal image operand that was added for SPIR-V 1.6.
2+
3+
; REQUIRES: spirv-as
4+
; RUN: spirv-as --target-env spv1.6 -o %t.spv %s
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis %t.rev.bc
8+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
9+
10+
OpCapability Addresses
11+
OpCapability Kernel
12+
OpCapability ImageBasic
13+
OpCapability LiteralSampler
14+
OpMemoryModel Physical64 OpenCL
15+
OpEntryPoint Kernel %kernel "read_write_image_nontemporal"
16+
%uint = OpTypeInt 32 0
17+
%void = OpTypeVoid
18+
%read_image2d_t = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly
19+
%write_image2d_t = OpTypeImage %void 2D 0 0 0 0 Unknown WriteOnly
20+
%sampler_t = OpTypeSampler
21+
%kernel_sig = OpTypeFunction %void %read_image2d_t %write_image2d_t
22+
%sampledimage_t = OpTypeSampledImage %read_image2d_t
23+
%v2uint = OpTypeVector %uint 2
24+
%float = OpTypeFloat 32
25+
%v4float = OpTypeVector %float 4
26+
%sampler = OpConstantSampler %sampler_t None 0 Nearest
27+
%coord_0_0 = OpConstantNull %v2uint
28+
%float_0 = OpConstant %float 0
29+
%kernel = OpFunction %void None %kernel_sig
30+
%src = OpFunctionParameter %read_image2d_t
31+
%dst = OpFunctionParameter %write_image2d_t
32+
%entry = OpLabel
33+
%si = OpSampledImage %sampledimage_t %src %sampler
34+
%data0 = OpImageSampleExplicitLod %v4float %si %coord_0_0 Lod %float_0
35+
OpImageWrite %dst %coord_0_0 %data0
36+
%data1 = OpImageSampleExplicitLod %v4float %si %coord_0_0 Lod|Nontemporal %float_0
37+
OpImageWrite %dst %coord_0_0 %data1 Nontemporal
38+
OpReturn
39+
OpFunctionEnd
40+
41+
; CHECK-LLVM: define spir_kernel void @read_write_image_nontemporal
42+
; CHECK-LLVM: call spir_func <4 x float> [[READ_IMAGEF:@[a-zA-Z0-9_]+]](
43+
; CHECK-LLVM: call spir_func void [[WRITE_IMAGEF:@[a-zA-Z0-9_]+]](
44+
; CHECK-LLVM: call spir_func <4 x float> [[READ_IMAGEF]](
45+
; CHECK-LLVM: call spir_func void [[WRITE_IMAGEF]](

0 commit comments

Comments
 (0)