1 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
3 ;; Support of doubles is required.
4 ; CHECK: OpCapability Float64
6 define spir_kernel void @fun01(i32 addrspace(1)* noalias %a, i32 addrspace(1)* %b, i32 %c) {
8 %a.addr = alloca i32 addrspace(1)*, align 8
9 %b.addr = alloca i32 addrspace(1)*, align 8
10 %c.addr = alloca i32, align 4
11 store i32 addrspace(1)* %a, i32 addrspace(1)** %a.addr, align 8
12 store i32 addrspace(1)* %b, i32 addrspace(1)** %b.addr, align 8
13 store i32 %c, i32* %c.addr, align 4
14 %0 = load i32 addrspace(1)*, i32 addrspace(1)** %b.addr, align 8
15 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %0, i64 0
16 %1 = load i32, i32 addrspace(1)* %arrayidx, align 4
17 %2 = load i32 addrspace(1)*, i32 addrspace(1)** %a.addr, align 8
18 %arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %2, i64 0
19 store i32 %1, i32 addrspace(1)* %arrayidx1, align 4
20 %3 = load i32 addrspace(1)*, i32 addrspace(1)** %b.addr, align 8
21 %cmp = icmp ugt i32 addrspace(1)* %3, null
22 br i1 %cmp, label %if.then, label %if.end
24 if.then: ; preds = %entry
25 %4 = load i32 addrspace(1)*, i32 addrspace(1)** %a.addr, align 8
26 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 0
27 store i32 2, i32 addrspace(1)* %arrayidx2, align 4
30 if.end: ; preds = %if.then, %entry
35 define spir_kernel void @fun02(double addrspace(1)* %a, double addrspace(1)* %b, i32 %c) {
37 %a.addr = alloca double addrspace(1)*, align 8
38 %b.addr = alloca double addrspace(1)*, align 8
39 %c.addr = alloca i32, align 4
40 store double addrspace(1)* %a, double addrspace(1)** %a.addr, align 8
41 store double addrspace(1)* %b, double addrspace(1)** %b.addr, align 8
42 store i32 %c, i32* %c.addr, align 4
43 %0 = load i32, i32* %c.addr, align 4
44 %idxprom = sext i32 %0 to i64
45 %1 = load double addrspace(1)*, double addrspace(1)** %b.addr, align 8
46 %arrayidx = getelementptr inbounds double, double addrspace(1)* %1, i64 %idxprom
47 %2 = load double, double addrspace(1)* %arrayidx, align 8
48 %3 = load i32, i32* %c.addr, align 4
49 %idxprom1 = sext i32 %3 to i64
50 %4 = load double addrspace(1)*, double addrspace(1)** %a.addr, align 8
51 %arrayidx2 = getelementptr inbounds double, double addrspace(1)* %4, i64 %idxprom1
52 store double %2, double addrspace(1)* %arrayidx2, align 8
56 ; CHECK: "test_builtin"
57 define spir_func void @test_builtin(i32 addrspace(1)* %in, i32 addrspace(1)* %out) {
59 %in.addr = alloca i32 addrspace(1)*, align 8
60 %out.addr = alloca i32 addrspace(1)*, align 8
61 %n = alloca i32, align 4
62 store i32 addrspace(1)* %in, i32 addrspace(1)** %in.addr, align 8
63 store i32 addrspace(1)* %out, i32 addrspace(1)** %out.addr, align 8
64 %call = call spir_func i64 @_Z13get_global_idj(i32 0)
65 %conv = trunc i64 %call to i32
66 store i32 %conv, i32* %n, align 4
67 %0 = load i32, i32* %n, align 4
68 %idxprom = sext i32 %0 to i64
69 %1 = load i32 addrspace(1)*, i32 addrspace(1)** %in.addr, align 8
70 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 %idxprom
71 %2 = load i32, i32 addrspace(1)* %arrayidx, align 4
72 %call1 = call spir_func i32 @_Z3absi(i32 %2)
73 %3 = load i32, i32* %n, align 4
74 %idxprom2 = sext i32 %3 to i64
75 %4 = load i32 addrspace(1)*, i32 addrspace(1)** %out.addr, align 8
76 %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 %idxprom2
77 store i32 %call1, i32 addrspace(1)* %arrayidx3, align 4
81 ; CHECK-NOT: "_Z13get_global_idj"
82 declare spir_func i64 @_Z13get_global_idj(i32)
84 ; CHECK-NOT: "_Z3absi"
85 declare spir_func i32 @_Z3absi(i32)
88 define spir_func i32 @myabs(i32 %x) {
90 %x.addr = alloca i32, align 4
91 store i32 %x, i32* %x.addr, align 4
92 %0 = load i32, i32* %x.addr, align 4
93 %call = call spir_func i32 @_Z3absi(i32 %0)
97 ; CHECK: "test_function_call"
98 define spir_func void @test_function_call(i32 addrspace(1)* %in, i32 addrspace(1)* %out) {
100 %in.addr = alloca i32 addrspace(1)*, align 8
101 %out.addr = alloca i32 addrspace(1)*, align 8
102 %n = alloca i32, align 4
103 store i32 addrspace(1)* %in, i32 addrspace(1)** %in.addr, align 8
104 store i32 addrspace(1)* %out, i32 addrspace(1)** %out.addr, align 8
105 %call = call spir_func i64 @_Z13get_global_idj(i32 0)
106 %conv = trunc i64 %call to i32
107 store i32 %conv, i32* %n, align 4
108 %0 = load i32, i32* %n, align 4
109 %idxprom = sext i32 %0 to i64
110 %1 = load i32 addrspace(1)*, i32 addrspace(1)** %in.addr, align 8
111 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 %idxprom
112 %2 = load i32, i32 addrspace(1)* %arrayidx, align 4
113 %call1 = call spir_func i32 @myabs(i32 %2)
114 %3 = load i32, i32* %n, align 4
115 %idxprom2 = sext i32 %3 to i64
116 %4 = load i32 addrspace(1)*, i32 addrspace(1)** %out.addr, align 8
117 %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 %idxprom2
118 store i32 %call1, i32 addrspace(1)* %arrayidx3, align 4