• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -loop-fusion -loop-fusion-peel-max-count=3 < %s | FileCheck %s
2
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
6; peeling).
7; The expected output of this test is the function below.
8
9; CHECK-LABEL: void @function(i32* noalias %arg)
10; CHECK-NEXT:  for.first.preheader:
11; CHECK-NEXT:    br label %for.first
12; CHECK:       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
18; CHECK:       for.next:
19; CHECK-NEXT:    br label %for.second.preheader
20; CHECK:       for.second.preheader:
21; CHECK:         br label %for.second
22; CHECK:       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
26; CHECK:       for.end:
27; CHECK-NEXT:    ret void
28
29@B = common global [1024 x i32] zeroinitializer, align 16
30
31define void @function(i32* noalias %arg) {
32for.first.preheader:
33  br label %for.first
34
35for.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, i32* %arg, i64 %indvars.iv23
45  store i32 %tmp12, i32* %tmp13, align 4
46  br label %for.first.latch
47
48for.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
53
54for.first.exit:                                  ; preds: %for.first.latch
55  br label %for.next
56
57for.next:                                        ; preds = %for.first.exit
58  br label %for.second.preheader
59
60for.second.preheader:                            ; preds = %for.next
61  br label %for.second
62
63for.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], [1024 x i32]* @B, i64 0, i64 %indvars.iv1
73  store i32 %tmp25, i32* %tmp26, align 4
74  br label %for.second.latch
75
76for.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
81
82for.end:                                         ; preds = %for.second.latch
83  ret void
84}
85