xref: /llvm-project/llvm/test/Transforms/StructurizeCFG/loop-multiple-exits.ll (revision bf6f82a9df6a1693a5399039dcadd7fc00dab65e)
1cee313d2SEric Christopher; RUN: opt -S -structurizecfg %s -o - | FileCheck %s
2cee313d2SEric Christopher;
3cee313d2SEric Christopher; void loop(int *out, int cond_a, int cond_b) {
4cee313d2SEric Christopher;
5cee313d2SEric Christopher;   unsigned i;
6cee313d2SEric Christopher;   for (i = 0; i < cond_a; i++) {
7cee313d2SEric Christopher;     out[i] = i;
8cee313d2SEric Christopher;     if (i > cond_b) {
9cee313d2SEric Christopher;       break;
10cee313d2SEric Christopher;     }
11cee313d2SEric Christopher;     out[i + cond_a] = i;
12cee313d2SEric Christopher;   }
13cee313d2SEric Christopher; }
14cee313d2SEric Christopher
15*bf6f82a9SMatt Arsenaultdefine void @loop(ptr addrspace(1) %out, i32 %cond_a, i32 %cond_b) nounwind uwtable {
16cee313d2SEric Christopherentry:
17cee313d2SEric Christopher  br label %for.cond
18cee313d2SEric Christopher
19cee313d2SEric Christopherfor.cond:                                         ; preds = %for.inc, %entry
20cee313d2SEric Christopher  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
21cee313d2SEric Christopher  %cmp = icmp ult i32 %i.0, %cond_a
22cee313d2SEric Christopher  br i1 %cmp, label %for.body, label %for.end
23cee313d2SEric Christopher
24cee313d2SEric Christopher; CHECK: for.body:
25cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
26*bf6f82a9SMatt Arsenault  %arrayidx = getelementptr inbounds i32, ptr addrspace(1) %out, i32 %i.0
27*bf6f82a9SMatt Arsenault  store i32 %i.0, ptr addrspace(1) %arrayidx, align 4
28cee313d2SEric Christopher  %cmp1 = icmp ugt i32 %i.0, %cond_b
29c710bb44SEhud Katz; CHECK: br i1 %{{[0-9a-zA-Z_.]+}}, label %for.inc, label %[[FLOW1:[0-9a-zA-Z_]+]]
30cee313d2SEric Christopher  br i1 %cmp1, label %for.end, label %for.inc
31cee313d2SEric Christopher
32cee313d2SEric Christopher; CHECK: [[FLOW:[0-9a-zA-Z]+]]:
33c710bb44SEhud Katz; CHECK: br i1 %{{[0-9a-zA-Z_.]+}}, label %for.end, label %for.cond
34cee313d2SEric Christopher
35cee313d2SEric Christopher; CHECK: for.inc:
36cee313d2SEric Christopher; CHECK: br label %[[FLOW1]]
37cee313d2SEric Christopher
38cee313d2SEric Christopherfor.inc:                                          ; preds = %for.body
39cee313d2SEric Christopher  %0 = add i32 %cond_a, %i.0
40*bf6f82a9SMatt Arsenault  %arrayidx3 = getelementptr inbounds i32, ptr addrspace(1) %out, i32 %0
41*bf6f82a9SMatt Arsenault  store i32 %i.0, ptr addrspace(1) %arrayidx3, align 4
42cee313d2SEric Christopher  %inc = add i32 %i.0, 1
43cee313d2SEric Christopher  br label %for.cond
44cee313d2SEric Christopher
45cee313d2SEric Christopher; CHECK: [[FLOW1]]
46cee313d2SEric Christopher; CHECK: br label %[[FLOW]]
47cee313d2SEric Christopher
48cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond, %for.body
49cee313d2SEric Christopher  ret void
50cee313d2SEric Christopher}
51