Skip to content

Commit 9c0a802

Browse files
authored
updates spirv instructions generated for atomic_compare_exhange_weak (#1830)
Updating atomic compare exchange weak SPIRV instructions given OpAtomicCompareExchangeWeak is deprecated starting from SPIR-V 1.4 and has the same semantics as OpAtomicCompareExchange
1 parent 951a6ad commit 9c0a802

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5249,6 +5249,11 @@ Op LLVMToSPIRVBase::transBoolOpCode(SPIRVValue *Opn, Op OC) {
52495249
SPIRVInstruction *
52505250
LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
52515251
SPIRVBasicBlock *BB) {
5252+
// OpAtomicCompareExchangeWeak is not "weak" at all,
5253+
// but instead has the same semantics as OpAtomicCompareExchange.
5254+
// Moreover, OpAtomicCompareExchangeWeak has been deprecated.
5255+
if (OC == OpAtomicCompareExchangeWeak)
5256+
OC = OpAtomicCompareExchange;
52525257
if (isGroupOpCode(OC))
52535258
BM->addCapability(CapabilityGroups);
52545259
switch (OC) {

test/AtomicCompareExchange_cl20.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ entry:
6464
; CHECK: Load [[int]] [[Value:[0-9]+]] [[desired_addr]]
6565
; CHECK: Load [[int]] [[ComparatorWeak:[0-9]+]] [[exp]]
6666
%call2 = call spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)* %4, i32 addrspace(4)* %5, i32 %6)
67-
; CHECK-NEXT: 9 AtomicCompareExchangeWeak [[int]] [[Result:[0-9]+]] [[Pointer]] [[DeviceScope]] [[SequentiallyConsistent_MS]] [[SequentiallyConsistent_MS]] [[Value]] [[ComparatorWeak]]
67+
; CHECK-NEXT: 9 AtomicCompareExchange [[int]] [[Result:[0-9]+]] [[Pointer]] [[DeviceScope]] [[SequentiallyConsistent_MS]] [[SequentiallyConsistent_MS]] [[Value]] [[ComparatorWeak]]
6868
; CHECK-NEXT: Store [[exp]] [[Result]]
6969
; CHECK-NEXT: IEqual [[bool]] [[CallRes:[0-9]+]] [[Result]] [[ComparatorWeak]]
7070
; CHECK-NOT: [[Result]]

test/transcoding/AtomicCompareExchangeExplicit_cl20.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ __kernel void testAtomicCompareExchangeExplicit_cl20(
4242

4343
//CHECK-SPIRV: AtomicCompareExchange {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[DeviceScope]] [[ReleaseMemSem]] [[RelaxedMemSem]]
4444
//CHECK-SPIRV: AtomicCompareExchange {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[WorkgroupScope]] [[AcqRelMemSem]] [[RelaxedMemSem]]
45-
//CHECK-SPIRV: AtomicCompareExchangeWeak {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[DeviceScope]] [[ReleaseMemSem]] [[RelaxedMemSem]]
46-
//CHECK-SPIRV: AtomicCompareExchangeWeak {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[WorkgroupScope]] [[AcqRelMemSem]] [[RelaxedMemSem]]
45+
//CHECK-SPIRV: AtomicCompareExchange {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[DeviceScope]] [[ReleaseMemSem]] [[RelaxedMemSem]]
46+
//CHECK-SPIRV: AtomicCompareExchange {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} [[WorkgroupScope]] [[AcqRelMemSem]] [[RelaxedMemSem]]
4747

4848
//CHECK-LLVM: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS4VU7_AtomiciPU3AS4ii12memory_orderS4_12memory_scope(ptr addrspace(4) %0, ptr addrspace(4) %expected5.as, i32 %desired, i32 3, i32 0, i32 2)
4949
//CHECK-LLVM: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS4VU7_AtomiciPU3AS4ii12memory_orderS4_12memory_scope(ptr addrspace(4) %0, ptr addrspace(4) %expected8.as, i32 %desired, i32 4, i32 0, i32 1)

0 commit comments

Comments
 (0)