Skip to content

Commit

Permalink
Handle removed OpAtomicCompareExchangeWeak (#2824)
Browse files Browse the repository at this point in the history
OpAtomicCompareExchangeWeak has been removed and #2665 added a validation for it.
This pull request replaces OpAtomicCompareExchangeWeak with OpAtomicCompareExchange.
  • Loading branch information
qichaogu authored Nov 6, 2024
1 parent 925255c commit eb64e4d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ SPIRVEntry *SPIRVEntry::create(Op OpCode) {
if (OpCode == internal::OpTypeJointMatrixINTELv2)
OpCode = internal::OpTypeJointMatrixINTEL;

// OpAtomicCompareExchangeWeak is removed starting from SPIR-V 1.4
if (OpCode == OpAtomicCompareExchangeWeak)
OpCode = OpAtomicCompareExchange;

OpToFactoryMapTy::const_iterator Loc = OpToFactoryMap.find(OpCode);
if (Loc != OpToFactoryMap.end())
return Loc->second();
Expand Down
57 changes: 57 additions & 0 deletions test/AtomicCompareExchangeWeak.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; Check OpAtomicCompareExchangeWeak is treated as OpAtomicCompareExchange

; REQUIRES: spirv-as
; RUN: spirv-as --target-env spv1.3 -o %t.spv %s
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r --spirv-target-env=CL2.0 --spirv-target-env="SPV-IR" -o - %t.spv | llvm-dis | FileCheck %s

OpCapability Addresses
OpCapability Linkage
OpCapability Kernel
OpCapability Int8
%1 = OpExtInstImport "OpenCL.std"
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %19 "test_atomic_global"
OpSource OpenCL_C 200000
OpName %test_atomic_global "test_atomic_global"
OpName %dst "dst"
OpName %object "object"
OpName %expected "expected"
OpName %desired "desired"
OpName %dst_0 "dst"
OpName %object_0 "object"
OpName %expected_0 "expected"
OpName %desired_0 "desired"
OpDecorate %test_atomic_global LinkageAttributes "test_atomic_global" Export
OpDecorate %dst_0 Volatile
%uint = OpTypeInt 32 0
%uchar = OpTypeInt 8 0
%uint_1 = OpConstant %uint 1
%uint_16 = OpConstant %uint 16
%uint_0 = OpConstant %uint 0
%void = OpTypeVoid
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
%_ptr_CrossWorkgroup_uchar = OpTypePointer CrossWorkgroup %uchar
%7 = OpTypeFunction %void %_ptr_CrossWorkgroup_uint %_ptr_CrossWorkgroup_uchar %_ptr_CrossWorkgroup_uchar %uint
%test_atomic_global = OpFunction %void None %7
%dst = OpFunctionParameter %_ptr_CrossWorkgroup_uint
%object = OpFunctionParameter %_ptr_CrossWorkgroup_uchar
%expected = OpFunctionParameter %_ptr_CrossWorkgroup_uchar
%desired = OpFunctionParameter %uint
%13 = OpLabel
%17 = OpAtomicCompareExchange %uint %dst %uint_1 %uint_16 %uint_16 %uint_1 %uint_0
%18 = OpAtomicCompareExchangeWeak %uint %dst %uint_1 %uint_16 %uint_16 %uint_1 %uint_0
OpReturn
OpFunctionEnd
%19 = OpFunction %void None %7
%dst_0 = OpFunctionParameter %_ptr_CrossWorkgroup_uint
%object_0 = OpFunctionParameter %_ptr_CrossWorkgroup_uchar
%expected_0 = OpFunctionParameter %_ptr_CrossWorkgroup_uchar
%desired_0 = OpFunctionParameter %uint
%24 = OpLabel
%25 = OpFunctionCall %void %test_atomic_global %dst_0 %object_0 %expected_0 %desired_0
OpReturn
OpFunctionEnd

; CHECK: call spir_func i32 @_Z29__spirv_AtomicCompareExchangePU3AS1iiiiii(
; CHECK-NOT: call spir_func i32 @_Z33__spirv_AtomicCompareExchangeWeakPU3AS1iiiiii(

0 comments on commit eb64e4d

Please sign in to comment.