| 1 |
; ModuleID = '' |
| 2 |
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" |
| 3 |
target triple = "spir-unknown-unknown" |
| 4 |
|
| 5 |
; RUN: llvm-as %s -o %t.bc |
| 6 |
; RUN: llvm-spirv %t.bc -o %t.spv |
| 7 |
; RUN: llvm-spirv -r --spirv-target-env=CL2.0 %t.spv -o %t.bc |
| 8 |
; RUN: llvm-dis < %t.bc | FileCheck %s |
| 9 |
|
| 10 |
; Check 'LLVM ==> SPIR-V ==> LLVM' conversion of atomic_compare_exchange_strong and atomic_compare_exchange_weak. |
| 11 |
|
| 12 |
; SPIR-V does not include an equivalent of atomic_compare_exchange_weak |
| 13 |
; (OpAtomicCompareExchangeWeak is identical to OpAtomicCompareExchange and |
| 14 |
; is deprecated, and removed in SPIR-V 1.4.) |
| 15 |
; This breaks the round trip for atomic_compare_exchange_weak, which must be |
| 16 |
; translated back to LLVM IR as atomic_compare_exchange_strong, regardless |
| 17 |
; of whether OpAtomicCompareExchange or OpAtomicCompareExchangeWeak is used. |
| 18 |
|
| 19 |
; Function Attrs: nounwind |
| 20 |
|
| 21 |
; CHECK-LABEL: define spir_func void @test_strong |
| 22 |
; CHECK-NEXT: entry: |
| 23 |
; CHECK: [[PTR_STRONG:%expected[0-9]*]] = alloca i32, align 4 |
| 24 |
; CHECK: store i32 {{.*}}, ptr [[PTR_STRONG]] |
| 25 |
; CHECK: [[PTR_STRONG]].as = addrspacecast ptr [[PTR_STRONG]] to ptr addrspace(4) |
| 26 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicit{{.*}}(ptr {{.*}} %object, ptr {{.*}} [[PTR_STRONG]].as, i32 %desired, i32 5, i32 5, i32 2) |
| 27 |
; CHECK: load i32, ptr addrspace(4) [[PTR_STRONG]].as |
| 28 |
|
| 29 |
; CHECK-LABEL: define spir_func void @test_strong_float |
| 30 |
; CHECK-NEXT: entry: |
| 31 |
; CHECK: [[PTR_STRONG:%expected[0-9]*]] = alloca i32, align 4 |
| 32 |
; CHECK: [[DESIRED_CAST:%[0-9]*]] = bitcast float %desired to i32 |
| 33 |
; CHECK: store i32 {{.*}}, ptr [[PTR_STRONG]] |
| 34 |
; CHECK: [[PTR_STRONG]].as = addrspacecast ptr [[PTR_STRONG]] to ptr addrspace(4) |
| 35 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicit{{.*}}(ptr {{.*}} %object, ptr {{.*}} [[PTR_STRONG]].as, i32 [[DESIRED_CAST]], i32 5, i32 5, i32 2) |
| 36 |
; CHECK: load i32, ptr addrspace(4) [[PTR_STRONG]].as |
| 37 |
|
| 38 |
; CHECK-LABEL: define spir_func void @test_strong_double |
| 39 |
; CHECK-NEXT: entry: |
| 40 |
; CHECK: [[PTR_STRONG:%expected[0-9]*]] = alloca i64, align 8 |
| 41 |
; CHECK: [[DESIRED_CAST:%[0-9]*]] = bitcast double %desired to i64 |
| 42 |
; CHECK: store i64 {{.*}}, ptr [[PTR_STRONG]] |
| 43 |
; CHECK: [[PTR_STRONG]].as = addrspacecast ptr [[PTR_STRONG]] to ptr addrspace(4) |
| 44 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicit{{.*}}(ptr {{.*}} %object, ptr {{.*}} [[PTR_STRONG]].as, i64 [[DESIRED_CAST]], i32 5, i32 5, i32 2) |
| 45 |
; CHECK: load i64, ptr addrspace(4) [[PTR_STRONG]].as |
| 46 |
|
| 47 |
; CHECK-LABEL: define spir_func void @test_weak |
| 48 |
; CHECK-NEXT: entry: |
| 49 |
; CHECK: [[PTR_WEAK:%expected[0-9]*]] = alloca i32, align 4 |
| 50 |
; CHECK: store i32 {{.*}}, ptr [[PTR_WEAK]] |
| 51 |
; CHECK: [[PTR_WEAK]].as = addrspacecast ptr [[PTR_WEAK]] to ptr addrspace(4) |
| 52 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS4VU7_AtomiciPU3AS4ii12memory_orderS4_12memory_scope{{.*}}(ptr {{.*}} %object, ptr {{.*}} [[PTR_WEAK]].as, i32 %desired, i32 5, i32 5, i32 2) |
| 53 |
; CHECK: load i32, ptr addrspace(4) [[PTR_WEAK]].as |
| 54 |
|
| 55 |
; CHECK-LABEL: define spir_func void @test_weak_float |
| 56 |
; CHECK-NEXT: entry: |
| 57 |
; CHECK: [[PTR_WEAK:%expected[0-9]*]] = alloca i32, align 4 |
| 58 |
; CHECK: [[DESIRED_CAST:%[0-9]*]] = bitcast float %desired to i32 |
| 59 |
; CHECK: store i32 {{.*}}, ptr [[PTR_WEAK]] |
| 60 |
; CHECK: [[PTR_WEAK]].as = addrspacecast ptr [[PTR_WEAK]] to ptr addrspace(4) |
| 61 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS4VU7_AtomiciPU3AS4ii12memory_orderS4_12memory_scope(ptr {{.*}} %object, ptr {{.*}} [[PTR_WEAK]].as, i32 [[DESIRED_CAST]], i32 5, i32 5, i32 2) |
| 62 |
; CHECK: load i32, ptr addrspace(4) [[PTR_WEAK]].as |
| 63 |
|
| 64 |
; CHECK-LABEL: define spir_func void @test_weak_double |
| 65 |
; CHECK-NEXT: entry: |
| 66 |
; CHECK: [[PTR_WEAK:%expected[0-9]*]] = alloca i64, align 8 |
| 67 |
; CHECK: [[DESIRED_CAST:%[0-9]*]] = bitcast double %desired to i64 |
| 68 |
; CHECK: store i64 {{.*}}, ptr [[PTR_WEAK]] |
| 69 |
; CHECK: [[PTR_WEAK]].as = addrspacecast ptr [[PTR_WEAK]] to ptr addrspace(4) |
| 70 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicitPU3AS4VU7_AtomiclPU3AS4ll12memory_orderS4_12memory_scope(ptr {{.*}} %object, ptr {{.*}} [[PTR_WEAK]].as, i64 [[DESIRED_CAST]], i32 5, i32 5, i32 2) |
| 71 |
; CHECK: load i64, ptr addrspace(4) [[PTR_WEAK]].as |
| 72 |
|
| 73 |
; Check that alloca for atomic_compare_exchange is being created in the entry block. |
| 74 |
|
| 75 |
; CHECK-LABEL: @atomic_in_loop |
| 76 |
; CHECK-LABEL: entry: |
| 77 |
; CHECK: %expected{{[0-9]*}} = alloca i32 |
| 78 |
; CHECK-LABEL: for.body: |
| 79 |
; CHECK-NOT: %expected{{[0-9]*}} = alloca i32 |
| 80 |
; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicit{{.*}}(ptr {{.*}} {{.*}}, ptr addrspace(4) {{.*}}, i32 {{.*}}, i32 5, i32 5, i32 2) |
| 81 |
|
| 82 |
; Function Attrs: nounwind |
| 83 |
define spir_func void @test_strong(ptr addrspace(4) %object, ptr addrspace(4) %expected, i32 %desired) #0 { |
| 84 |
entry: |
| 85 |
%call = tail call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(ptr addrspace(4) %object, ptr addrspace(4) %expected, i32 %desired) #2 |
| 86 |
ret void |
| 87 |
} |
| 88 |
|
| 89 |
declare spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(ptr addrspace(4), ptr addrspace(4), i32) #1 |
| 90 |
|
| 91 |
define spir_func void @test_strong_float(ptr addrspace(4) %object, ptr addrspace(4) %expected, float %desired) #0 { |
| 92 |
entry: |
| 93 |
%call = call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPU3AS1VU7_AtomicfPU3AS1ff(ptr addrspace(4) %object, ptr addrspace(4) %expected, float %desired) #2 |
| 94 |
ret void |
| 95 |
} |
| 96 |
|
| 97 |
declare spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPU3AS1VU7_AtomicfPU3AS1ff(ptr addrspace(4), ptr addrspace(4), float) |
| 98 |
|
| 99 |
define spir_func void @test_strong_double(ptr addrspace(4) %object, ptr addrspace(4) %expected, double %desired) #0 { |
| 100 |
entry: |
| 101 |
%call = call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPU3AS1VU7_AtomicdPU3AS1dd(ptr addrspace(4) %object, ptr addrspace(4) %expected, double %desired) #2 |
| 102 |
ret void |
| 103 |
} |
| 104 |
|
| 105 |
declare spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPU3AS1VU7_AtomicdPU3AS1dd(ptr addrspace(4), ptr addrspace(4), double) |
| 106 |
|
| 107 |
; Function Attrs: nounwind |
| 108 |
define spir_func void @test_weak(i32 addrspace(4)* %object, i32 addrspace(4)* %expected, i32 %desired) #0 { |
| 109 |
entry: |
| 110 |
%call2 = tail call spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)* %object, i32 addrspace(4)* %expected, i32 %desired) #2 |
| 111 |
ret void |
| 112 |
} |
| 113 |
|
| 114 |
declare spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)*, i32 addrspace(4)*, i32) #1 |
| 115 |
|
| 116 |
define spir_func void @test_weak_float(ptr addrspace(4) %object, ptr addrspace(4) %expected, float %desired) #0 { |
| 117 |
entry: |
| 118 |
%call = call spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPU3AS1VU7_AtomicfPU3AS1ff(ptr addrspace(4) %object, ptr addrspace(4) %expected, float %desired) #2 |
| 119 |
ret void |
| 120 |
} |
| 121 |
|
| 122 |
declare spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPU3AS1VU7_AtomicfPU3AS1ff(ptr addrspace(4), ptr addrspace(4), float) |
| 123 |
|
| 124 |
define spir_func void @test_weak_double(ptr addrspace(4) %object, ptr addrspace(4) %expected, double %desired) #0 { |
| 125 |
entry: |
| 126 |
%call = call spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPU3AS1VU7_AtomicdPU3AS1dd(ptr addrspace(4) %object, ptr addrspace(4) %expected, double %desired) #2 |
| 127 |
ret void |
| 128 |
} |
| 129 |
|
| 130 |
declare spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPU3AS1VU7_AtomicdPU3AS1dd(ptr addrspace(4), ptr addrspace(4), double) |
| 131 |
|
| 132 |
; Function Attrs: nounwind |
| 133 |
define spir_kernel void @atomic_in_loop(i32 addrspace(1)* %destMemory, i32 addrspace(1)* %oldValues) #0 { |
| 134 |
entry: |
| 135 |
%destMemory.addr = alloca i32 addrspace(1)*, align 8 |
| 136 |
%oldValues.addr = alloca i32 addrspace(1)*, align 8 |
| 137 |
%expected = alloca i32, align 4 |
| 138 |
%previous = alloca i32, align 4 |
| 139 |
%i = alloca i32, align 4 |
| 140 |
store i32 addrspace(1)* %destMemory, i32 addrspace(1)** %destMemory.addr, align 8 |
| 141 |
store i32 addrspace(1)* %oldValues, i32 addrspace(1)** %oldValues.addr, align 8 |
| 142 |
store i32 0, i32* %i, align 4 |
| 143 |
br label %for.cond |
| 144 |
|
| 145 |
for.cond: ; preds = %for.inc, %entry |
| 146 |
%0 = load i32, i32* %i, align 4 |
| 147 |
%cmp = icmp slt i32 %0, 100000 |
| 148 |
br i1 %cmp, label %for.body, label %for.end |
| 149 |
|
| 150 |
for.body: ; preds = %for.cond |
| 151 |
%1 = load i32 addrspace(1)*, i32 addrspace(1)** %destMemory.addr, align 8 |
| 152 |
%arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 0 |
| 153 |
%2 = addrspacecast i32 addrspace(1)* %arrayidx to i32 addrspace(4)* |
| 154 |
%3 = addrspacecast i32* %expected to i32 addrspace(4)* |
| 155 |
%4 = load i32 addrspace(1)*, i32 addrspace(1)** %oldValues.addr, align 8 |
| 156 |
%arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 0 |
| 157 |
%5 = load i32, i32 addrspace(1)* %arrayidx1, align 4 |
| 158 |
%call = call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)* %2, i32 addrspace(4)* %3, i32 %5) |
| 159 |
br label %for.inc |
| 160 |
|
| 161 |
for.inc: ; preds = %for.body |
| 162 |
%6 = load i32, i32* %i, align 4 |
| 163 |
%inc = add nsw i32 %6, 1 |
| 164 |
store i32 %inc, i32* %i, align 4 |
| 165 |
br label %for.cond |
| 166 |
|
| 167 |
for.end: ; preds = %for.cond |
| 168 |
ret void |
| 169 |
} |
| 170 |
|
| 171 |
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 172 |
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 173 |
attributes #2 = { nounwind } |
| 174 |
|
| 175 |
!opencl.enable.FP_CONTRACT = !{} |
| 176 |
!opencl.spir.version = !{!0} |
| 177 |
!opencl.ocl.version = !{!1} |
| 178 |
!opencl.used.extensions = !{!2} |
| 179 |
!opencl.used.optional.core.features = !{!2} |
| 180 |
!opencl.compiler.options = !{!2} |
| 181 |
|
| 182 |
!0 = !{i32 1, i32 2} |
| 183 |
!1 = !{i32 2, i32 0} |
| 184 |
!2 = !{} |