| 1 |
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s |
| 2 |
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64v1.2-unknown-unknown %s -o - -filetype=obj | spirv-val %} |
| 3 |
|
| 4 |
; CHECK-NOT: OpCapability Int64Atomics |
| 5 |
|
| 6 |
; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0 |
| 7 |
; CHECK-DAG: %[[#int8:]] = OpTypeInt 8 0 |
| 8 |
; CHECK-DAG: %[[#DeviceScope:]] = OpConstant %[[#int]] 1 |
| 9 |
; CHECK-DAG: %[[#SequentiallyConsistent_MS:]] = OpConstant %[[#int]] 16 |
| 10 |
; CHECK-DAG: %[[#int_ptr:]] = OpTypePointer Generic %[[#int]] |
| 11 |
; CHECK-DAG: %[[#int_ptr8:]] = OpTypePointer Generic %[[#int8]] |
| 12 |
; CHECK-DAG: %[[#bool:]] = OpTypeBool |
| 13 |
|
| 14 |
define spir_func void @test(ptr addrspace(4) %object, ptr addrspace(4) %expected, i32 %desired) { |
| 15 |
|
| 16 |
; CHECK: %[[#object:]] = OpFunctionParameter %[[#int_ptr8]] |
| 17 |
; CHECK: %[[#expected:]] = OpFunctionParameter %[[#int_ptr8]] |
| 18 |
; CHECK: %[[#desired:]] = OpFunctionParameter %[[#int]] |
| 19 |
|
| 20 |
entry: |
| 21 |
%object.addr = alloca ptr addrspace(4), align 4 |
| 22 |
%expected.addr = alloca ptr addrspace(4), align 4 |
| 23 |
%desired.addr = alloca i32, align 4 |
| 24 |
%strong_res = alloca i8, align 1 |
| 25 |
%res = alloca i8, align 1 |
| 26 |
%weak_res = alloca i8, align 1 |
| 27 |
store ptr addrspace(4) %object, ptr %object.addr, align 4 |
| 28 |
store ptr addrspace(4) %expected, ptr %expected.addr, align 4 |
| 29 |
store i32 %desired, ptr %desired.addr, align 4 |
| 30 |
%0 = load ptr addrspace(4), ptr %object.addr, align 4 |
| 31 |
%1 = load ptr addrspace(4), ptr %expected.addr, align 4 |
| 32 |
%2 = load i32, ptr %desired.addr, align 4 |
| 33 |
|
| 34 |
; CHECK-DAG: OpStore %[[#object_addr:]] %[[#object]] |
| 35 |
; CHECK-DAG: OpStore %[[#expected_addr:]] %[[#expected]] |
| 36 |
; CHECK-DAG: OpStore %[[#desired_addr:]] %[[#desired]] |
| 37 |
|
| 38 |
; CHECK: %[[#Pointer:]] = OpLoad %[[#int_ptr]] %[[#]] |
| 39 |
; CHECK: %[[#exp:]] = OpLoad %[[#int_ptr]] %[[#]] |
| 40 |
; CHECK: %[[#Value:]] = OpLoad %[[#int]] %[[#desired_addr]] |
| 41 |
; CHECK: %[[#Comparator:]] = OpLoad %[[#int]] %[[#exp]] |
| 42 |
|
| 43 |
; CHECK: %[[#Result:]] = OpAtomicCompareExchange %[[#int]] %[[#]] %[[#DeviceScope]] %[[#SequentiallyConsistent_MS]] %[[#SequentiallyConsistent_MS]] %[[#Value]] %[[#Comparator]] |
| 44 |
%call = call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(ptr addrspace(4) %0, ptr addrspace(4) %1, i32 %2) |
| 45 |
|
| 46 |
; CHECK-NEXT: OpStore %[[#exp]] %[[#Result]] |
| 47 |
; CHECK-NEXT: %[[#CallRes:]] = OpIEqual %[[#bool]] %[[#Result]] %[[#Comparator]] |
| 48 |
; CHECK-NOT: %[[#Result]] |
| 49 |
|
| 50 |
%frombool = zext i1 %call to i8 |
| 51 |
store i8 %frombool, ptr %strong_res, align 1 |
| 52 |
%3 = load i8, ptr %strong_res, align 1 |
| 53 |
%tobool = trunc i8 %3 to i1 |
| 54 |
%lnot = xor i1 %tobool, true |
| 55 |
%frombool1 = zext i1 %lnot to i8 |
| 56 |
store i8 %frombool1, ptr %res, align 1 |
| 57 |
%4 = load ptr addrspace(4), ptr %object.addr, align 4 |
| 58 |
%5 = load ptr addrspace(4), ptr %expected.addr, align 4 |
| 59 |
%6 = load i32, ptr %desired.addr, align 4 |
| 60 |
|
| 61 |
; CHECK: %[[#Pointer:]] = OpLoad %[[#int_ptr]] %[[#]] |
| 62 |
; CHECK: %[[#exp:]] = OpLoad %[[#int_ptr]] %[[#]] |
| 63 |
; CHECK: %[[#Value:]] = OpLoad %[[#int]] %[[#desired_addr]] |
| 64 |
; CHECK: %[[#ComparatorWeak:]] = OpLoad %[[#int]] %[[#exp]] |
| 65 |
|
| 66 |
; CHECK: %[[#Result:]] = OpAtomicCompareExchangeWeak %[[#int]] %[[#]] %[[#DeviceScope]] %[[#SequentiallyConsistent_MS]] %[[#SequentiallyConsistent_MS]] %[[#Value]] %[[#ComparatorWeak]] |
| 67 |
%call2 = call spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(ptr addrspace(4) %4, ptr addrspace(4) %5, i32 %6) |
| 68 |
|
| 69 |
; CHECK-NEXT: OpStore %[[#exp]] %[[#Result]] |
| 70 |
; CHECK-NEXT: %[[#CallRes:]] = OpIEqual %[[#bool]] %[[#Result]] %[[#ComparatorWeak]] |
| 71 |
; CHECK-NOT: %[[#Result]] |
| 72 |
|
| 73 |
%frombool3 = zext i1 %call2 to i8 |
| 74 |
store i8 %frombool3, ptr %weak_res, align 1 |
| 75 |
%7 = load i8, ptr %weak_res, align 1 |
| 76 |
%tobool4 = trunc i8 %7 to i1 |
| 77 |
%lnot5 = xor i1 %tobool4, true |
| 78 |
%frombool6 = zext i1 %lnot5 to i8 |
| 79 |
store i8 %frombool6, ptr %res, align 1 |
| 80 |
ret void |
| 81 |
} |
| 82 |
|
| 83 |
declare spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(ptr addrspace(4), ptr addrspace(4), i32) #1 |
| 84 |
declare spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(ptr addrspace(4), ptr addrspace(4), i32) #1 |