|
| 1 | +; Copyright (C) Codeplay Software Limited |
| 2 | +; |
| 3 | +; Licensed under the Apache License, Version 2.0 (the "License") with LLVM |
| 4 | +; Exceptions; you may not use this file except in compliance with the License. |
| 5 | +; You may obtain a copy of the License at |
| 6 | +; |
| 7 | +; https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt |
| 8 | +; |
| 9 | +; Unless required by applicable law or agreed to in writing, software |
| 10 | +; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +; License for the specific language governing permissions and limitations |
| 13 | +; under the License. |
| 14 | +; |
| 15 | +; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 16 | + |
| 17 | +; REQUIRES: !llvm-19+ |
| 18 | +; RUN: veczc -k partial_linearization22 -vecz-passes="function(lowerswitch),vecz-loop-rotate,indvars,cfg-convert" -S < %s | FileCheck %s |
| 19 | + |
| 20 | +; The CFG of the following kernel is: |
| 21 | +; |
| 22 | +; a |
| 23 | +; | |
| 24 | +; b <------. |
| 25 | +; / \ | |
| 26 | +; f c <--. | |
| 27 | +; |\ / \ | | |
| 28 | +; | | d -' | |
| 29 | +; | |\ / \ | |
| 30 | +; | | | e -' |
| 31 | +; | | |\ / |
| 32 | +; | | | g |
| 33 | +; | | |/ |
| 34 | +; | | / |
| 35 | +; \|/ |
| 36 | +; h |
| 37 | +; |
| 38 | +; * where nodes b, d, and e are uniform branches, and node c is a varying |
| 39 | +; branch. |
| 40 | +; * where nodes b, d, e and f are divergent. |
| 41 | +; |
| 42 | +; With partial linearization, it will be transformed as follows: |
| 43 | +; |
| 44 | +; a |
| 45 | +; | |
| 46 | +; b <--. |
| 47 | +; /| | |
| 48 | +; f c <. | |
| 49 | +; | | | | |
| 50 | +; | d -' | |
| 51 | +; | | | |
| 52 | +; | e ---' |
| 53 | +; \| |
| 54 | +; g |
| 55 | +; | |
| 56 | +; h |
| 57 | +; |
| 58 | +; __kernel void partial_linearization22(__global int *out, int n) { |
| 59 | +; int id = get_global_id(0); |
| 60 | +; int ret = 0; |
| 61 | +; |
| 62 | +; while (1) { |
| 63 | +; if (n > 0 && n < 5) { |
| 64 | +; goto f; |
| 65 | +; } |
| 66 | +; while (1) { |
| 67 | +; if (n <= 2) { |
| 68 | +; goto f; |
| 69 | +; } else { |
| 70 | +; if (ret + id >= n) { |
| 71 | +; goto d; |
| 72 | +; } |
| 73 | +; } |
| 74 | +; if (n & 1) { |
| 75 | +; goto h; |
| 76 | +; } |
| 77 | +; |
| 78 | +; d: |
| 79 | +; if (n > 3) { |
| 80 | +; goto e; |
| 81 | +; } |
| 82 | +; } |
| 83 | +; |
| 84 | +; e: |
| 85 | +; if (n & 1) { |
| 86 | +; goto g; |
| 87 | +; } |
| 88 | +; } |
| 89 | +; |
| 90 | +; f: |
| 91 | +; if (n == 2) { |
| 92 | +; goto h; |
| 93 | +; } |
| 94 | +; |
| 95 | +; g: |
| 96 | +; for (int i = 0; i < n + 1; i++) ret++; |
| 97 | +; goto h; |
| 98 | +; |
| 99 | +; h: |
| 100 | +; out[id] = ret; |
| 101 | +; } |
| 102 | + |
| 103 | +; ModuleID = 'Unknown buffer' |
| 104 | +source_filename = "kernel.opencl" |
| 105 | +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 106 | +target triple = "spir64-unknown-unknown" |
| 107 | + |
| 108 | +; Function Attrs: convergent nounwind |
| 109 | +define spir_kernel void @partial_linearization22(i32 addrspace(1)* %out, i32 %n) #0 { |
| 110 | +entry: |
| 111 | + %call = call i64 @__mux_get_global_id(i32 0) #2 |
| 112 | + %conv = trunc i64 %call to i32 |
| 113 | + br label %while.body |
| 114 | + |
| 115 | +while.body: ; preds = %e, %entry |
| 116 | + %n.off = add i32 %n, -1 |
| 117 | + %0 = icmp ult i32 %n.off, 4 |
| 118 | + %cmp6 = icmp slt i32 %n, 3 |
| 119 | + %or.cond1 = or i1 %cmp6, %0 |
| 120 | + br i1 %or.cond1, label %f, label %if.else |
| 121 | + |
| 122 | +while.body5: ; preds = %d |
| 123 | + switch i32 %n, label %g [ |
| 124 | + i32 3, label %if.else |
| 125 | + i32 2, label %h |
| 126 | + ] |
| 127 | + |
| 128 | +if.else: ; preds = %while.body5, %while.body |
| 129 | + %cmp9 = icmp sge i32 %conv, %n |
| 130 | + %and = and i32 %n, 1 |
| 131 | + %tobool = icmp eq i32 %and, 0 |
| 132 | + %or.cond2 = or i1 %tobool, %cmp9 |
| 133 | + br i1 %or.cond2, label %d, label %h |
| 134 | + |
| 135 | +d: ; preds = %if.else |
| 136 | + %cmp16 = icmp sgt i32 %n, 3 |
| 137 | + br i1 %cmp16, label %e, label %while.body5 |
| 138 | + |
| 139 | +e: ; preds = %d |
| 140 | + %and20 = and i32 %n, 1 |
| 141 | + %tobool21 = icmp eq i32 %and20, 0 |
| 142 | + br i1 %tobool21, label %while.body, label %g |
| 143 | + |
| 144 | +f: ; preds = %while.body |
| 145 | + %cmp24 = icmp eq i32 %n, 2 |
| 146 | + br i1 %cmp24, label %h, label %g |
| 147 | + |
| 148 | +g: ; preds = %f, %e, %while.body5 |
| 149 | + br label %for.cond |
| 150 | + |
| 151 | +for.cond: ; preds = %for.body, %g |
| 152 | + %ret.0 = phi i32 [ 0, %g ], [ %inc, %for.body ] |
| 153 | + %storemerge = phi i32 [ 0, %g ], [ %inc31, %for.body ] |
| 154 | + %cmp29 = icmp sgt i32 %storemerge, %n |
| 155 | + br i1 %cmp29, label %h, label %for.body |
| 156 | + |
| 157 | +for.body: ; preds = %for.cond |
| 158 | + %inc = add nuw nsw i32 %ret.0, 1 |
| 159 | + %inc31 = add nuw nsw i32 %storemerge, 1 |
| 160 | + br label %for.cond |
| 161 | + |
| 162 | +h: ; preds = %for.cond, %f, %if.else, %while.body5 |
| 163 | + %ret.1 = phi i32 [ 0, %f ], [ %ret.0, %for.cond ], [ 0, %if.else ], [ 0, %while.body5 ] |
| 164 | + %idxprom = sext i32 %conv to i64 |
| 165 | + %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %idxprom |
| 166 | + store i32 %ret.1, i32 addrspace(1)* %arrayidx, align 4 |
| 167 | + ret void |
| 168 | +} |
| 169 | + |
| 170 | +; Function Attrs: convergent nounwind readonly |
| 171 | +declare i64 @__mux_get_global_id(i32) #1 |
| 172 | + |
| 173 | +attributes #0 = { convergent nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="0" "stackrealign" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 174 | +attributes #1 = { convergent nounwind readonly "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="0" "stackrealign" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 175 | +attributes #2 = { convergent nobuiltin nounwind readonly } |
| 176 | + |
| 177 | +!llvm.module.flags = !{!0} |
| 178 | +!opencl.ocl.version = !{!1} |
| 179 | +!opencl.spir.version = !{!1} |
| 180 | +!opencl.kernels = !{!2} |
| 181 | + |
| 182 | +!0 = !{i32 1, !"wchar_size", i32 4} |
| 183 | +!1 = !{i32 1, i32 2} |
| 184 | +!2 = !{void (i32 addrspace(1)*, i32)* @partial_linearization22, !3, !4, !5, !6, !7, !8} |
| 185 | +!3 = !{!"kernel_arg_addr_space", i32 1, i32 0} |
| 186 | +!4 = !{!"kernel_arg_access_qual", !"none", !"none"} |
| 187 | +!5 = !{!"kernel_arg_type", !"int*", !"int"} |
| 188 | +!6 = !{!"kernel_arg_base_type", !"int*", !"int"} |
| 189 | +!7 = !{!"kernel_arg_type_qual", !"", !""} |
| 190 | +!8 = !{!"kernel_arg_name", !"out", !"n"} |
| 191 | + |
| 192 | +; CHECK: spir_kernel void @__vecz_v4_partial_linearization22 |
| 193 | +; CHECK: br label %[[WHILEBODY:.+]] |
| 194 | + |
| 195 | +; CHECK: [[WHILEBODY]]: |
| 196 | +; CHECK: %[[CMP6:.+]] = icmp slt |
| 197 | +; CHECK: %[[ORCOND1:.+]] = or i1 %[[CMP6]] |
| 198 | +; CHECK: %[[F_EXIT_MASK:.+]] = select i1 |
| 199 | +; CHECK: %[[ORCOND2:.+]] = call i1 @__vecz_b_divergence_any(i1 %[[ORCOND1]]) |
| 200 | +; CHECK: br i1 %[[ORCOND2]], label %[[F:.+]], label %[[IFELSEPREHEADER:.+]] |
| 201 | + |
| 202 | +; CHECK: [[IFELSEPREHEADER]]: |
| 203 | +; CHECK: br label %[[IFELSE:.+]] |
| 204 | + |
| 205 | +; CHECK: [[LEAFBLOCK1:.*]]: |
| 206 | +; CHECK: %[[SWITCHLEAF:.+]] = icmp eq i32 %n, 3 |
| 207 | +; CHECK: br i1 %{{.+}}, label %[[IFELSE]], label %[[IFELSEPUREEXIT:.+]] |
| 208 | + |
| 209 | +; CHECK: [[IFELSEPUREEXIT]]: |
| 210 | +; CHECK: br label %[[E:.+]] |
| 211 | + |
| 212 | +; CHECK: [[IFELSE]]: |
| 213 | +; CHECK: br label %[[D:.+]] |
| 214 | + |
| 215 | +; CHECK: [[D]]: |
| 216 | +; CHECK: br label %[[LEAFBLOCK1]] |
| 217 | + |
| 218 | +; CHECK: [[E]]: |
| 219 | +; CHECK: br i1 %{{.+}}, label %[[WHILEBODY]], label %[[WHILEBODYPUREEXIT:.+]] |
| 220 | + |
| 221 | +; CHECK: [[WHILEBODYPUREEXIT]]: |
| 222 | +; CHECK: %[[CMP24MERGE:.+]] = phi i1 [ %[[G_EXIT_MASK:.+]], %[[F]] ], [ false, %[[E]] ] |
| 223 | +; CHECK: br label %[[HLOOPEXIT1:.+]] |
| 224 | + |
| 225 | +; CHECK: [[F]]: |
| 226 | +; CHECK: %[[CMP24:.+]] = icmp eq i32 %n, 2 |
| 227 | +; CHECK: %[[G_EXIT_MASK]] = select i1 %[[CMP24]], i1 false, i1 %[[F_EXIT_MASK]] |
| 228 | +; CHECK: br label %[[WHILEBODYPUREEXIT]] |
| 229 | + |
| 230 | +; CHECK: [[FELSE:.+]]: |
| 231 | +; CHECK: br label %[[G:.+]] |
| 232 | + |
| 233 | +; CHECK: [[FSPLIT:.+]]: |
| 234 | +; CHECK: %[[CMP24_ANY:.+]] = call i1 @__vecz_b_divergence_any(i1 %cmp24.merge) |
| 235 | +; CHECK: br i1 %[[CMP24_ANY]], label %[[H:.+]], label %[[G]] |
| 236 | + |
| 237 | +; CHECK: [[GLOOPEXIT:.+]]: |
| 238 | +; CHECK: br label %[[GLOOPEXITELSE:.+]] |
| 239 | + |
| 240 | +; CHECK: [[GLOOPEXITELSE]]: |
| 241 | +; CHECK: br i1 %{{.+}}, label %[[FELSE]], label %[[FSPLIT]] |
| 242 | + |
| 243 | +; CHECK: [[G]]: |
| 244 | +; CHECK: br label %[[FORCOND:.+]] |
| 245 | + |
| 246 | +; CHECK: [[FORCOND]]: |
| 247 | +; CHECK: br i1 true, label %[[HLOOPEXIT:.+]], label %[[FORBODY:.+]] |
| 248 | + |
| 249 | +; CHECK: [[FORBODY]]: |
| 250 | +; CHECK: br label %[[FORCOND]] |
| 251 | + |
| 252 | + |
| 253 | + |
| 254 | +; CHECK: [[HLOOPEXIT]]: |
| 255 | +; CHECK: br label %[[H:.+]] |
| 256 | + |
| 257 | +; CHECK: [[HLOOPEXIT1]]: |
| 258 | +; CHECK: br label %[[HLOOPEXIT1ELSE:.+]] |
| 259 | + |
| 260 | +; CHECK: [[HLOOPEXIT1ELSE]]: |
| 261 | +; CHECK: br label %[[GLOOPEXIT]] |
| 262 | + |
| 263 | +;; CHECK: [[H]]: |
| 264 | +;; CHECK: ret void |
0 commit comments