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
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ template <spv::Op OC> class SPIRVConstantBase : public SPIRVValue {

// Common method for getting values of size less or equal to 64 bits.
template <typename T> T getValue() const {
if (OpCode == OpConstantNull)
return 0;
Copy link

@Naghasan Naghasan Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
if (OpCode == OpConstantNull)
return 0;
if (OpCode == OpConstantNull) {
assert(std::is_arithmetic_v<T> && "OpConstantNull has no defined value for this type");
return 0;
}

Copy link
Contributor

@MrSidims MrSidims Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually have another Q. In which contexts getValue is called? Can it be called to get value of an object of Event type or a Coop Matrix or any composite? If yes note, that ConstantNull is defined as:

Result Type must be one of the following types:
- Scalar or vector Boolean type
- Scalar or vector integer type
- Scalar or vector floating-point type
- Pointer type
- Event type
- Device side event type
- Reservation id type
- Queue type
- Composite type

hence here we should:
a. not add the proposed assetion;
b. return not null, but a value constructed by the T's default c'tor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I got the answer: the method is protected and used only by:

  uint64_t getZExtIntValue() const { return getValue<uint64_t>(); }
  float getFloatValue() const { return getValue<float>(); }
  double getDoubleValue() const { return getValue<double>(); }

hence we can even make the proposed by Viktor assert to be a static_assert

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I got the answer: the method is protected and used only by:

yeah, that's why I suggested the nit, I suggested an assert because the function is all constants not just null constant.

constexpr auto ValueSize = static_cast<unsigned>(sizeof(T));
assert((ValueSize <= 8) && "Incorrect result type of requested value");
T TheValue{};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; REQUIRES: spirv-as
; RUN: spirv-as --target-env spv1.0 -o %t.spv %s
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s

OpCapability Addresses
OpCapability Kernel
OpCapability CooperativeMatrixKHR
OpExtension "SPV_KHR_cooperative_matrix"
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %1 "test"
%uint = OpTypeInt 32 0
%uint_0 = OpConstantNull %uint
%uint_12 = OpConstant %uint 12
%uint_2 = OpConstant %uint 2
%void = OpTypeVoid
%fnTy = OpTypeFunction %void
%matTy = OpTypeCooperativeMatrixKHR %uint %uint_0 %uint_12 %uint_12 %uint_0
%1 = OpFunction %void None %fnTy
%2 = OpLabel
%3 = OpCompositeConstruct %matTy %uint_0
OpReturn
OpFunctionEnd

; CHECK: call spir_func target("spirv.CooperativeMatrixKHR", i32, 0, 12, 12, 0) @_Z26__spirv_CompositeConstructi(i32 0)