Skip to content

Commit 3f8d86b

Browse files
authored
[Backport to 20] Fix incorrect translation for AtomicCmpExchangeWeak builtin ptr arg type. (#3390) (#3393)
Add missing case so that pointer argument types for `OpAtomicCompareExchangeWeak` are resolved correctly. The newly added test, without this patch would introduce an invalid bitcast just before the atomic builtin.
1 parent 578442e commit 3f8d86b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/SPIRV/SPIRVTypeScavenger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ bool SPIRVTypeScavenger::typeIntrinsicCall(
453453
case OpAtomicLoad:
454454
case OpAtomicExchange:
455455
case OpAtomicCompareExchange:
456+
case OpAtomicCompareExchangeWeak:
456457
case OpAtomicIAdd:
457458
case OpAtomicISub:
458459
case OpAtomicFAddEXT:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefixes=CHECK
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
6+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
7+
target triple = "spir64"
8+
9+
; CHECK-DAG: 4 TypeInt [[#int:]] 32 0
10+
; CHECK-DAG: Constant [[#int]] [[#DeviceScope:]] 4
11+
; CHECK-DAG: Constant [[#int]] [[#SequentiallyConsistent_MS:]] 0
12+
; CHECK-DAG: 4 TypePointer [[#int_ptr:]] 4 [[#int]]
13+
; CHECK-DAG: 2 TypeBool [[#bool:]]
14+
15+
define spir_kernel void @test_atomic_kernel() {
16+
entry:
17+
%arrayidx7 = getelementptr i32, ptr addrspace(3) null, i64 0
18+
19+
; CHECK: PtrAccessChain [[#int_ptr]] [[#Pointer:]] [[#]] [[#]]
20+
; CHECK: Load [[#int]] [[#Comparator:]] [[#]]
21+
; CHECK-NEXT: AtomicCompareExchange [[#int]] [[#Result:]] [[#Pointer]] [[#DeviceScope]] [[#SequentiallyConsistent_MS]] [[#SequentiallyConsistent_MS]] [[#]] [[#Comparator]]
22+
; CHECK-NEXT: Store [[#]] [[#Result]]
23+
; CHECK-NEXT: IEqual [[#bool]] [[#]] [[#Result]] [[#Comparator]]
24+
%call10 = call spir_func i1 @_Z37atomic_compare_exchange_weak_explicitPU3AS3VU7_AtomiciPii12memory_orderS4_12memory_scope(ptr addrspace(3) %arrayidx7, ptr null, i32 14, i32 0, i32 0, i32 0)
25+
26+
; CHECK: Load [[#int]] [[#Comparator:]] [[#]]
27+
; CHECK-NEXT: AtomicCompareExchange [[#int]] [[#Result2:]] [[#Pointer]] [[#DeviceScope]] [[#SequentiallyConsistent_MS]] [[#SequentiallyConsistent_MS]] [[#]] [[#Comparator]]
28+
; CHECK-NEXT: Store [[#]] [[#Result2]]
29+
; CHECK-NEXT: IEqual [[#bool]] [[#]] [[#Result2]] [[#Comparator]]
30+
%call11 = call spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS3VU7_AtomiciPii12memory_orderS4_12memory_scope(ptr addrspace(3) %arrayidx7, ptr null, i32 14, i32 0, i32 0, i32 0)
31+
ret void
32+
}
33+
34+
declare spir_func i1 @_Z37atomic_compare_exchange_weak_explicitPU3AS3VU7_AtomiciPii12memory_orderS4_12memory_scope(ptr addrspace(3), ptr, i32, i32, i32, i32)
35+
declare spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS3VU7_AtomiciPii12memory_orderS4_12memory_scope(ptr addrspace(3), ptr, i32, i32, i32, i32)
36+
37+
!opencl.ocl.version = !{!0}
38+
39+
!0 = !{i32 3, i32 0}
40+

0 commit comments

Comments
 (0)