1 ; RUN: opt -S -passes=loop-fusion -loop-fusion-peel-max-count=3 < %s | FileCheck %s
3 ; Tests if we are able to fuse two guarded loops which have constant but
4 ; different trip counts. The first two iterations of the first loop should be
5 ; peeled off, and then the loops should be fused together.
7 @B = common global [1024 x i32] zeroinitializer, align 16
9 ; CHECK-LABEL: void @main(ptr noalias %A)
11 ; CHECK: br i1 %cmp4, label %for.first.entry, label %for.end
12 ; CHECK: for.first.entry
13 ; CHECK-NEXT: br label %for.first.peel.begin
14 ; CHECK: for.first.peel.begin:
15 ; CHECK-NEXT: br label %for.first.peel
16 ; CHECK: for.first.peel:
17 ; CHECK: br label %for.first.peel.next
18 ; CHECK: for.first.peel.next:
19 ; CHECK-NEXT: br label %for.first.peel2
20 ; CHECK: for.first.peel2:
21 ; CHECK: br label %for.first.peel.next1
22 ; CHECK: for.first.peel.next1:
23 ; CHECK-NEXT: br label %for.first.peel.next11
24 ; CHECK: for.first.peel.next11:
25 ; CHECK-NEXT: br label %for.first.entry.peel.newph
26 ; CHECK: for.first.entry.peel.newph:
27 ; CHECK: br label %for.first
29 ; CHECK: br i1 %cmp3, label %for.first, label %for.second.exit
30 ; CHECK: for.second.exit:
31 ; CHECK: br label %for.end
33 ; CHECK-NEXT: ret void
35 define void @main(ptr noalias %A) {
37 %cmp4 = icmp slt i64 0, 45
38 br i1 %cmp4, label %for.first.entry, label %for.second.guard
40 for.first.entry: ; preds = %entry
43 for.first: ; preds = %for.first.entry, %for.first
44 %i.05 = phi i64 [ %inc, %for.first ], [ 0, %for.first.entry ]
45 %sub = sub nsw i64 %i.05, 3
46 %add = add nsw i64 %i.05, 3
47 %mul = mul nsw i64 %sub, %add
48 %rem = srem i64 %mul, %i.05
49 %conv = trunc i64 %rem to i32
50 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %i.05
51 store i32 %conv, ptr %arrayidx, align 4
52 %inc = add nsw i64 %i.05, 1
53 %cmp = icmp slt i64 %inc, 45
54 br i1 %cmp, label %for.first, label %for.first.exit
56 for.first.exit: ; preds = %for.first
57 br label %for.second.guard
59 for.second.guard: ; preds = %for.first.exit, %entry
60 %cmp31 = icmp slt i64 2, 45
61 br i1 %cmp31, label %for.second.entry, label %for.end
63 for.second.entry: ; preds = %for.second.guard
66 for.second: ; preds = %for.second.entry, %for.second
67 %i1.02 = phi i64 [ %inc14, %for.second ], [ 2, %for.second.entry ]
68 %sub7 = sub nsw i64 %i1.02, 3
69 %add8 = add nsw i64 %i1.02, 3
70 %mul9 = mul nsw i64 %sub7, %add8
71 %rem10 = srem i64 %mul9, %i1.02
72 %conv11 = trunc i64 %rem10 to i32
73 %arrayidx12 = getelementptr inbounds [1024 x i32], ptr @B, i64 0, i64 %i1.02
74 store i32 %conv11, ptr %arrayidx12, align 4
75 %inc14 = add nsw i64 %i1.02, 1
76 %cmp3 = icmp slt i64 %inc14, 45
77 br i1 %cmp3, label %for.second, label %for.second.exit
79 for.second.exit: ; preds = %for.second
82 for.end: ; preds = %for.second.exit, %for.second.guard