1 ; RUN: opt -S -passes=loop-fusion -loop-fusion-peel-max-count=3 < %s | FileCheck %s
3 ; Tests that we do not fuse these two loops together. These loops do not have
4 ; the same tripcount, and the first loop is valid candiate for peeling; however
5 ; the loops are not adjacent, hence they are not valid to be fused (after
7 ; The expected output of this test is the function below.
9 ; CHECK-LABEL: void @function(ptr noalias %arg)
10 ; CHECK-NEXT: for.first.preheader:
11 ; CHECK-NEXT: br label %for.first
13 ; CHECK: br label %for.first.latch
14 ; CHECK: for.first.latch:
15 ; CHECK: br i1 %exitcond4, label %for.first, label %for.first.exit
16 ; CHECK: for.first.exit:
17 ; CHECK-NEXT: br label %for.next
19 ; CHECK-NEXT: br label %for.second.preheader
20 ; CHECK: for.second.preheader:
21 ; CHECK: br label %for.second
23 ; CHECK: br label %for.second.latch
24 ; CHECK: for.second.latch:
25 ; CHECK: br i1 %exitcond, label %for.second, label %for.end
27 ; CHECK-NEXT: ret void
29 @B = common global [1024 x i32] zeroinitializer, align 16
31 define void @function(ptr noalias %arg) {
35 for.first: ; preds = %for.first.preheader, %for.first.latch
36 %.014 = phi i32 [ 0, %for.first.preheader ], [ %tmp15, %for.first.latch ]
37 %indvars.iv23 = phi i64 [ 0, %for.first.preheader ], [ %indvars.iv.next3, %for.first.latch ]
38 %tmp = add nsw i32 %.014, -3
39 %tmp8 = add nuw nsw i64 %indvars.iv23, 3
40 %tmp9 = trunc i64 %tmp8 to i32
41 %tmp10 = mul nsw i32 %tmp, %tmp9
42 %tmp11 = trunc i64 %indvars.iv23 to i32
43 %tmp12 = srem i32 %tmp10, %tmp11
44 %tmp13 = getelementptr inbounds i32, ptr %arg, i64 %indvars.iv23
45 store i32 %tmp12, ptr %tmp13, align 4
46 br label %for.first.latch
48 for.first.latch: ; preds = %for.first
49 %indvars.iv.next3 = add nuw nsw i64 %indvars.iv23, 1
50 %tmp15 = add nuw nsw i32 %.014, 1
51 %exitcond4 = icmp ne i64 %indvars.iv.next3, 100
52 br i1 %exitcond4, label %for.first, label %for.first.exit
54 for.first.exit: ; preds: %for.first.latch
57 for.next: ; preds = %for.first.exit
58 br label %for.second.preheader
60 for.second.preheader: ; preds = %for.next
63 for.second: ; preds = %for.second.preheader, %for.second.latch
64 %.02 = phi i32 [ 0, %for.second.preheader ], [ %tmp28, %for.second.latch ]
65 %indvars.iv1 = phi i64 [ 3, %for.second.preheader ], [ %indvars.iv.next, %for.second.latch ]
66 %tmp20 = add nsw i32 %.02, -3
67 %tmp21 = add nuw nsw i64 %indvars.iv1, 3
68 %tmp22 = trunc i64 %tmp21 to i32
69 %tmp23 = mul nsw i32 %tmp20, %tmp22
70 %tmp24 = trunc i64 %indvars.iv1 to i32
71 %tmp25 = srem i32 %tmp23, %tmp24
72 %tmp26 = getelementptr inbounds [1024 x i32], ptr @B, i64 0, i64 %indvars.iv1
73 store i32 %tmp25, ptr %tmp26, align 4
74 br label %for.second.latch
76 for.second.latch: ; preds = %for.second
77 %indvars.iv.next = add nuw nsw i64 %indvars.iv1, 1
78 %tmp28 = add nuw nsw i32 %.02, 1
79 %exitcond = icmp ne i64 %indvars.iv.next, 100
80 br i1 %exitcond, label %for.second, label %for.end
82 for.end: ; preds = %for.second.latch