1; ModuleID = '' 2target 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" 3target 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 %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; Function Attrs: nounwind 13 14; CHECK-LABEL: define spir_func void @test_strong 15; CHECK-NEXT: entry: 16; CHECK: [[PTR_STRONG:%expected[0-9]*]] = alloca i32, align 4 17; CHECK: store i32 {{.*}}, i32* [[PTR_STRONG]] 18; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicit{{.*}}(i32 {{.*}}* %object, i32* [[PTR_STRONG]], i32 %desired, i32 4, i32 4, i32 2) 19; CHECK: load i32, i32* [[PTR_STRONG]] 20 21; CHECK-LABEL: define spir_func void @test_weak 22; CHECK-NEXT: entry: 23; CHECK: [[PTR_WEAK:%expected[0-9]*]] = alloca i32, align 4 24; CHECK: store i32 {{.*}}, i32* [[PTR_WEAK]] 25; CHECK: call spir_func i1 @_Z37atomic_compare_exchange_weak_explicitPVU3AS4U7_AtomiciPiiiii{{.*}}(i32 {{.*}}* %object, i32* [[PTR_WEAK]], i32 %desired, i32 4, i32 4, i32 2) 26; CHECK: load i32, i32* [[PTR_WEAK]] 27 28; Check that alloca for atomic_compare_exchange is being created in the entry block. 29 30; CHECK-LABEL: @atomic_in_loop 31; CHECK-LABEL: entry: 32; CHECK: %expected{{[0-9]*}} = alloca i32 33; CHECK-LABEL: for.body: 34; CHECK-NOT: %expected{{[0-9]*}} = alloca i32 35; CHECK: call spir_func i1 @_Z39atomic_compare_exchange_strong_explicit{{.*}}(i32 {{.*}}* {{.*}}, i32* {{.*}}, i32 {{.*}}, i32 4, i32 4, i32 2) 36 37; Function Attrs: nounwind 38define spir_func void @test_strong(i32 addrspace(4)* %object, i32 addrspace(4)* %expected, i32 %desired) #0 { 39entry: 40 %call = tail call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)* %object, i32 addrspace(4)* %expected, i32 %desired) #2 41 ret void 42} 43 44declare spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)*, i32 addrspace(4)*, i32) #1 45 46; Function Attrs: nounwind 47define spir_func void @test_weak(i32 addrspace(4)* %object, i32 addrspace(4)* %expected, i32 %desired) #0 { 48entry: 49 %call2 = tail call spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)* %object, i32 addrspace(4)* %expected, i32 %desired) #2 50 ret void 51} 52 53declare spir_func zeroext i1 @_Z28atomic_compare_exchange_weakPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)*, i32 addrspace(4)*, i32) #1 54 55; Function Attrs: nounwind 56define spir_kernel void @atomic_in_loop(i32 addrspace(1)* %destMemory, i32 addrspace(1)* %oldValues) #0 { 57entry: 58 %destMemory.addr = alloca i32 addrspace(1)*, align 8 59 %oldValues.addr = alloca i32 addrspace(1)*, align 8 60 %expected = alloca i32, align 4 61 %previous = alloca i32, align 4 62 %i = alloca i32, align 4 63 store i32 addrspace(1)* %destMemory, i32 addrspace(1)** %destMemory.addr, align 8 64 store i32 addrspace(1)* %oldValues, i32 addrspace(1)** %oldValues.addr, align 8 65 store i32 0, i32* %i, align 4 66 br label %for.cond 67 68for.cond: ; preds = %for.inc, %entry 69 %0 = load i32, i32* %i, align 4 70 %cmp = icmp slt i32 %0, 100000 71 br i1 %cmp, label %for.body, label %for.end 72 73for.body: ; preds = %for.cond 74 %1 = load i32 addrspace(1)*, i32 addrspace(1)** %destMemory.addr, align 8 75 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 0 76 %2 = addrspacecast i32 addrspace(1)* %arrayidx to i32 addrspace(4)* 77 %3 = addrspacecast i32* %expected to i32 addrspace(4)* 78 %4 = load i32 addrspace(1)*, i32 addrspace(1)** %oldValues.addr, align 8 79 %arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 0 80 %5 = load i32, i32 addrspace(1)* %arrayidx1, align 4 81 %call = call spir_func zeroext i1 @_Z30atomic_compare_exchange_strongPVU3AS4U7_AtomiciPU3AS4ii(i32 addrspace(4)* %2, i32 addrspace(4)* %3, i32 %5) 82 br label %for.inc 83 84for.inc: ; preds = %for.body 85 %6 = load i32, i32* %i, align 4 86 %inc = add nsw i32 %6, 1 87 store i32 %inc, i32* %i, align 4 88 br label %for.cond 89 90for.end: ; preds = %for.cond 91 ret void 92} 93 94attributes #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" } 95attributes #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" } 96attributes #2 = { nounwind } 97 98!opencl.enable.FP_CONTRACT = !{} 99!opencl.spir.version = !{!0} 100!opencl.ocl.version = !{!1} 101!opencl.used.extensions = !{!2} 102!opencl.used.optional.core.features = !{!2} 103!opencl.compiler.options = !{!2} 104 105!0 = !{i32 1, i32 2} 106!1 = !{i32 2, i32 0} 107!2 = !{} 108