Debian Codegraph @

llvm/test/CodeGen/SPIRV/AtomicCompareExchange64BitPhiNode.ll

raw
1 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3
4 ; Regression test for issue https://github.com/llvm/llvm-project/issues/152863
5 ; Ensure OpAtomicCompareExchange returns the correct i64 type when used in phi nodes.
6 ; Previously, this would generate invalid SPIR-V where the atomic operation returned
7 ; uint (32-bit) but the phi node expected ulong (64-bit), causing validation errors.
8
9 ; CHECK-SPIRV-DAG: %[[#Long:]] = OpTypeInt 64 0
10 ; CHECK-SPIRV-DAG: %[[#Ptr:]] = OpTypePointer CrossWorkgroup %[[#Long]]
11 ; CHECK-SPIRV-DAG: %[[#Zero64:]] = OpConstantNull %[[#Long]]
12
13 ; Verify that both the phi node and atomic operation use the same i64 type
14 ; CHECK-SPIRV: %[[#ValuePhi:]] = OpPhi %[[#Long]] %[[#Zero64]] %[[#]] %[[#AtomicResult:]] %[[#]]
15 ; CHECK-SPIRV: %[[#AtomicResult]] = OpAtomicCompareExchange %[[#Long]] %[[#]] %[[#]] %[[#]] %[[#]] %[[#Zero64]] %[[#ValuePhi]]
16
17 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
18 target triple = "spirv64-unknown-unknown"
19
20 declare i64 @_Z14atomic_cmpxchgPU8CLglobalVlll(ptr addrspace(1), i64, i64)
21
22 define spir_kernel void @test_atomic_cmpxchg_phi(ptr addrspace(1) %ptr) {
23 conversion:
24 br label %L6
25
26 L6: ; preds = %L6, %conversion
27 %value_phi = phi i64 [ 0, %conversion ], [ %1, %L6 ]
28 %1 = call i64 @_Z14atomic_cmpxchgPU8CLglobalVlll(ptr addrspace(1) %ptr, i64 %value_phi, i64 0)
29 br label %L6
30 }