• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llvm-as < %s | llvm-spirv -spirv-text -o %t
2; RUN: FileCheck < %t %s
3target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
4target triple = "spir64-unknown-unknown"
5
6; Support of doubles is required.
7; CHECK: Capability Float64
8; CHECK: "fun01"
9; Function Attrs: nounwind
10define spir_kernel void @fun01(i32 addrspace(1)* noalias %a, i32 addrspace(1)* %b, i32 %c) #0 {
11entry:
12  %a.addr = alloca i32 addrspace(1)*, align 8
13  %b.addr = alloca i32 addrspace(1)*, align 8
14  %c.addr = alloca i32, align 4
15  store i32 addrspace(1)* %a, i32 addrspace(1)** %a.addr, align 8
16  store i32 addrspace(1)* %b, i32 addrspace(1)** %b.addr, align 8
17  store i32 %c, i32* %c.addr, align 4
18  %0 = load i32 addrspace(1)*, i32 addrspace(1)** %b.addr, align 8
19  %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %0, i64 0
20  %1 = load i32, i32 addrspace(1)* %arrayidx, align 4
21  %2 = load i32 addrspace(1)*, i32 addrspace(1)** %a.addr, align 8
22  %arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %2, i64 0
23  store i32 %1, i32 addrspace(1)* %arrayidx1, align 4
24  %3 = load i32 addrspace(1)*, i32 addrspace(1)** %b.addr, align 8
25  %cmp = icmp ugt i32 addrspace(1)* %3, null
26  br i1 %cmp, label %if.then, label %if.end
27
28if.then:                                          ; preds = %entry
29  %4 = load i32 addrspace(1)*, i32 addrspace(1)** %a.addr, align 8
30  %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 0
31  store i32 2, i32 addrspace(1)* %arrayidx2, align 4
32  br label %if.end
33
34if.end:                                           ; preds = %if.then, %entry
35  ret void
36}
37
38; CHECK: "fun02"
39; Function Attrs: nounwind
40define spir_kernel void @fun02(double addrspace(1)* %a, double addrspace(1)* %b, i32 %c) #0 {
41entry:
42  %a.addr = alloca double addrspace(1)*, align 8
43  %b.addr = alloca double addrspace(1)*, align 8
44  %c.addr = alloca i32, align 4
45  store double addrspace(1)* %a, double addrspace(1)** %a.addr, align 8
46  store double addrspace(1)* %b, double addrspace(1)** %b.addr, align 8
47  store i32 %c, i32* %c.addr, align 4
48  %0 = load i32, i32* %c.addr, align 4
49  %idxprom = sext i32 %0 to i64
50  %1 = load double addrspace(1)*, double addrspace(1)** %b.addr, align 8
51  %arrayidx = getelementptr inbounds double, double addrspace(1)* %1, i64 %idxprom
52  %2 = load double, double addrspace(1)* %arrayidx, align 8
53  %3 = load i32, i32* %c.addr, align 4
54  %idxprom1 = sext i32 %3 to i64
55  %4 = load double addrspace(1)*, double addrspace(1)** %a.addr, align 8
56  %arrayidx2 = getelementptr inbounds double, double addrspace(1)* %4, i64 %idxprom1
57  store double %2, double addrspace(1)* %arrayidx2, align 8
58  ret void
59}
60
61; CHECK: "test_builtin"
62; Function Attrs: nounwind
63define spir_func void @test_builtin(i32 addrspace(1)* %in, i32 addrspace(1)* %out) #0 {
64entry:
65  %in.addr = alloca i32 addrspace(1)*, align 8
66  %out.addr = alloca i32 addrspace(1)*, align 8
67  %n = alloca i32, align 4
68  store i32 addrspace(1)* %in, i32 addrspace(1)** %in.addr, align 8
69  store i32 addrspace(1)* %out, i32 addrspace(1)** %out.addr, align 8
70  %call = call spir_func i64 @_Z13get_global_idj(i32 0) #2
71  %conv = trunc i64 %call to i32
72  store i32 %conv, i32* %n, align 4
73  %0 = load i32, i32* %n, align 4
74  %idxprom = sext i32 %0 to i64
75  %1 = load i32 addrspace(1)*, i32 addrspace(1)** %in.addr, align 8
76  %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 %idxprom
77  %2 = load i32, i32 addrspace(1)* %arrayidx, align 4
78  %call1 = call spir_func i32 @_Z3absi(i32 %2) #2
79  %3 = load i32, i32* %n, align 4
80  %idxprom2 = sext i32 %3 to i64
81  %4 = load i32 addrspace(1)*, i32 addrspace(1)** %out.addr, align 8
82  %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 %idxprom2
83  store i32 %call1, i32 addrspace(1)* %arrayidx3, align 4
84  ret void
85}
86
87; CHECK-NOT: "_Z13get_global_idj"
88; Function Attrs: nounwind readnone
89declare spir_func i64 @_Z13get_global_idj(i32) #1
90
91; CHECK-NOT: "_Z3absi"
92; Function Attrs: nounwind readnone
93declare spir_func i32 @_Z3absi(i32) #1
94
95; CHECK: "myabs"
96; Function Attrs: nounwind
97define spir_func i32 @myabs(i32 %x) #0 {
98entry:
99  %x.addr = alloca i32, align 4
100  store i32 %x, i32* %x.addr, align 4
101  %0 = load i32, i32* %x.addr, align 4
102  %call = call spir_func i32 @_Z3absi(i32 %0) #2
103  ret i32 %call
104}
105
106; CHECK: "test_function_call"
107; Function Attrs: nounwind
108define spir_func void @test_function_call(i32 addrspace(1)* %in, i32 addrspace(1)* %out) #0 {
109entry:
110  %in.addr = alloca i32 addrspace(1)*, align 8
111  %out.addr = alloca i32 addrspace(1)*, align 8
112  %n = alloca i32, align 4
113  store i32 addrspace(1)* %in, i32 addrspace(1)** %in.addr, align 8
114  store i32 addrspace(1)* %out, i32 addrspace(1)** %out.addr, align 8
115  %call = call spir_func i64 @_Z13get_global_idj(i32 0) #2
116  %conv = trunc i64 %call to i32
117  store i32 %conv, i32* %n, align 4
118  %0 = load i32, i32* %n, align 4
119  %idxprom = sext i32 %0 to i64
120  %1 = load i32 addrspace(1)*, i32 addrspace(1)** %in.addr, align 8
121  %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 %idxprom
122  %2 = load i32, i32 addrspace(1)* %arrayidx, align 4
123  %call1 = call spir_func i32 @myabs(i32 %2)
124  %3 = load i32, i32* %n, align 4
125  %idxprom2 = sext i32 %3 to i64
126  %4 = load i32 addrspace(1)*, i32 addrspace(1)** %out.addr, align 8
127  %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %4, i64 %idxprom2
128  store i32 %call1, i32 addrspace(1)* %arrayidx3, align 4
129  ret void
130}
131
132attributes #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" }
133attributes #1 = { nounwind readnone "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" }
134attributes #2 = { nounwind readnone }
135
136!opencl.kernels = !{!0, !7}
137!opencl.enable.FP_CONTRACT = !{}
138!opencl.spir.version = !{!12}
139!opencl.ocl.version = !{!12}
140!opencl.used.extensions = !{!13}
141!opencl.used.optional.core.features = !{!14}
142!opencl.compiler.options = !{!13}
143
144!0 = !{void (i32 addrspace(1)*, i32 addrspace(1)*, i32)* @fun01, !1, !2, !3, !4, !5, !6}
145!1 = !{!"kernel_arg_addr_space", i32 1, i32 1, i32 0}
146!2 = !{!"kernel_arg_access_qual", !"none", !"none", !"none"}
147!3 = !{!"kernel_arg_type", !"int*", !"int*", !"int"}
148!4 = !{!"kernel_arg_base_type", !"int*", !"int*", !"int"}
149!5 = !{!"kernel_arg_type_qual", !"restrict", !"const", !""}
150!6 = !{!"reqd_work_group_size", i32 1, i32 2, i32 3}
151!7 = !{void (double addrspace(1)*, double addrspace(1)*, i32)* @fun02, !1, !2, !8, !9, !10, !11}
152!8 = !{!"kernel_arg_type", !"double*", !"double*", !"int"}
153!9 = !{!"kernel_arg_base_type", !"double*", !"double*", !"int"}
154!10 = !{!"kernel_arg_type_qual", !"", !"", !""}
155!11 = !{!"vec_type_hint", double undef, i32 1}
156!12 = !{i32 1, i32 2}
157!13 = !{}
158!14 = !{!"cl_doubles"}
159