Skip to content

Commit 55a143b

Browse files
svenvhsys-ce-bb
authored andcommitted
Fix allowed types for OpConstantNull (#2361)
The SPIR-V Specification allows `OpConstantNull` types to be scalar or vector booleans, integers, or floats. Update an assert for this and add a SPIR-V -> LLVM IR test. Original commit: KhronosGroup/SPIRV-LLVM-Translator@9ec969c1c379bde
1 parent 272ba9e commit 55a143b

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVValue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class SPIRVConstantNull : public SPIRVConstantEmpty<OpConstantNull> {
269269
protected:
270270
void validate() const override {
271271
SPIRVConstantEmpty::validate();
272-
assert((Type->isTypeComposite() || Type->isTypeOpaque() ||
272+
assert((Type->isTypeBool() || Type->isTypeInt() || Type->isTypeFloat() ||
273+
Type->isTypeComposite() || Type->isTypeOpaque() ||
273274
Type->isTypeEvent() || Type->isTypePointer() ||
274275
Type->isTypeReserveId() || Type->isTypeDeviceEvent() ||
275276
(Type->isTypeSubgroupAvcINTEL() &&

llvm-spirv/test/OpConstantNull.spvasm

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; REQUIRES: spirv-as
2+
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s
5+
OpCapability Addresses
6+
OpCapability Kernel
7+
OpMemoryModel Physical32 OpenCL
8+
OpEntryPoint Kernel %1 "testNullConstants"
9+
%void = OpTypeVoid
10+
%bool = OpTypeBool
11+
%uint = OpTypeInt 32 0
12+
%float = OpTypeFloat 32
13+
%boolv3 = OpTypeVector %bool 3
14+
%uintv3 = OpTypeVector %uint 3
15+
%floatv3 = OpTypeVector %float 3
16+
%5 = OpTypeFunction %void %bool %boolv3 %uint %uintv3 %float %floatv3
17+
%bool0 = OpConstantNull %bool
18+
%boolv30 = OpConstantNull %boolv3
19+
%uint0 = OpConstantNull %uint
20+
%uintv30 = OpConstantNull %uintv3
21+
%float0 = OpConstantNull %float
22+
%floatv30 = OpConstantNull %floatv3
23+
24+
%1 = OpFunction %void None %5
25+
%pb = OpFunctionParameter %bool
26+
%pbv3 = OpFunctionParameter %boolv3
27+
%pu = OpFunctionParameter %uint
28+
%puv3 = OpFunctionParameter %uintv3
29+
%pf = OpFunctionParameter %float
30+
%pfv3 = OpFunctionParameter %floatv3
31+
%entry = OpLabel
32+
%tb = OpLogicalEqual %bool %pb %bool0
33+
%tbv3 = OpLogicalEqual %boolv3 %pbv3 %boolv30
34+
%tu = OpIEqual %bool %pu %uint0
35+
%tuv3 = OpIEqual %boolv3 %puv3 %uintv30
36+
%tf = OpFOrdEqual %bool %pf %float0
37+
%tfv3 = OpFOrdEqual %boolv3 %pfv3 %floatv30
38+
OpReturn
39+
OpFunctionEnd
40+
41+
; CHECK: icmp eq i1 %[[#]], false
42+
; CHECK: icmp eq <3 x i1> %[[#]], zeroinitializer
43+
; CHECK: icmp eq i32 %[[#]], 0
44+
; CHECK: icmp eq <3 x i32> %[[#]], zeroinitializer
45+
; CHECK: fcmp oeq float %[[#]], 0.000000e+00
46+
; CHECK: fcmp oeq <3 x float> %[[#]], zeroinitializer

0 commit comments

Comments
 (0)