1 ; RUN: opt -S -loop-fusion < %s | FileCheck %s
6 ; #define EXPENSIVE_PURE_COMPUTATION(i) ((i - 3) * (i + 3) % i)
10 ; for (int i = 0; i < 100; i++)
11 ; for (int j = 0; j < 100; j++)
12 ; A[i][j] = EXPENSIVE_PURE_COMPUTATION(i);
14 ; for (int i = 0; i < 100; i++)
15 ; for (int j = 0; j < 100; j++)
16 ; B[i][j] = EXPENSIVE_PURE_COMPUTATION(i);
19 @A = common global [1024 x [1024 x i32]] zeroinitializer, align 16
20 @B = common global [1024 x [1024 x i32]] zeroinitializer, align 16
22 ; CHECK: void @dep_free
24 ; CHECK-NEXT: br label %[[LOOP1HEADER:bb[0-9]+]]
25 ; CHECK: [[LOOP1HEADER]]
26 ; CHECK: br i1 %exitcond12, label %[[LOOP3PREHEADER:bb[0-9]+.preheader]], label %[[LOOP2HEADER:bb[0-9]+]]
27 ; CHECK: [[LOOP3PREHEADER]]
28 ; CHECK: br label %[[LOOP3HEADER:bb[0-9]+]]
29 ; CHECK: [[LOOP3HEADER]]
30 ; CHECK: br i1 %exitcond9, label %[[LOOP3BODY:bb[0-9]+]], label %[[LOOP1LATCH:bb[0-9]+]]
31 ; CHECK: [[LOOP1LATCH]]
32 ; CHECK: br label %[[LOOP2HEADER:bb[0-9]+]]
33 ; CHECK: [[LOOP2HEADER]]
34 ; CHECK: br i1 %exitcond6, label %[[LOOP4PREHEADER:bb[0-9]+.preheader]], label %[[LOOP2EXITBLOCK:bb[0-9]+]]
35 ; CHECK: [[LOOP4PREHEADER]]
36 ; CHECK: br label %[[LOOP4HEADER:bb[0-9]+]]
37 ; CHECK: [[LOOP2EXITBLOCK]]
38 ; CHECK-NEXT: br label %[[FUNCEXIT:bb[0-9]+]]
39 ; CHECK: [[LOOP4HEADER]]
40 ; CHECK: br i1 %exitcond, label %[[LOOP4BODY:bb[0-9]+]], label %[[LOOP2LATCH:bb[0-9]+]]
41 ; CHECK: [[LOOP2LATCH]]
42 ; CHECK: br label %[[LOOP1HEADER:bb[0-9]+]]
46 ; TODO: The current version of loop fusion does not allow the inner loops to be
47 ; fused because they are not control flow equivalent and adjacent. These are
48 ; limitations that can be addressed in future improvements to fusion.
49 define void @dep_free() {
53 bb13: ; preds = %bb27, %bb
54 %indvars.iv10 = phi i64 [ %indvars.iv.next11, %bb27 ], [ 0, %bb ]
55 %.0 = phi i32 [ 0, %bb ], [ %tmp28, %bb27 ]
56 %exitcond12 = icmp ne i64 %indvars.iv10, 100
57 br i1 %exitcond12, label %bb16, label %bb30
59 bb16: ; preds = %bb25, %bb13
60 %indvars.iv7 = phi i64 [ %indvars.iv.next8, %bb25 ], [ 0, %bb13 ]
61 %exitcond9 = icmp ne i64 %indvars.iv7, 100
62 br i1 %exitcond9, label %bb18, label %bb27
65 %tmp = add nsw i32 %.0, -3
66 %tmp19 = add nuw nsw i64 %indvars.iv10, 3
67 %tmp20 = trunc i64 %tmp19 to i32
68 %tmp21 = mul nsw i32 %tmp, %tmp20
69 %tmp22 = trunc i64 %indvars.iv10 to i32
70 %tmp23 = srem i32 %tmp21, %tmp22
71 %tmp24 = getelementptr inbounds [1024 x [1024 x i32]], [1024 x [1024 x i32]]* @A, i64 0, i64 %indvars.iv10, i64 %indvars.iv7
72 store i32 %tmp23, i32* %tmp24, align 4
76 %indvars.iv.next8 = add nuw nsw i64 %indvars.iv7, 1
80 %indvars.iv.next11 = add nuw nsw i64 %indvars.iv10, 1
81 %tmp28 = add nuw nsw i32 %.0, 1
84 bb30: ; preds = %bb45, %bb13
85 %indvars.iv4 = phi i64 [ %indvars.iv.next5, %bb45 ], [ 0, %bb13 ]
86 %.02 = phi i32 [ 0, %bb13 ], [ %tmp46, %bb45 ]
87 %exitcond6 = icmp ne i64 %indvars.iv4, 100
88 br i1 %exitcond6, label %bb33, label %bb31
93 bb33: ; preds = %bb43, %bb30
94 %indvars.iv = phi i64 [ %indvars.iv.next, %bb43 ], [ 0, %bb30 ]
95 %exitcond = icmp ne i64 %indvars.iv, 100
96 br i1 %exitcond, label %bb35, label %bb45
99 %tmp36 = add nsw i32 %.02, -3
100 %tmp37 = add nuw nsw i64 %indvars.iv4, 3
101 %tmp38 = trunc i64 %tmp37 to i32
102 %tmp39 = mul nsw i32 %tmp36, %tmp38
103 %tmp40 = trunc i64 %indvars.iv4 to i32
104 %tmp41 = srem i32 %tmp39, %tmp40
105 %tmp42 = getelementptr inbounds [1024 x [1024 x i32]], [1024 x [1024 x i32]]* @B, i64 0, i64 %indvars.iv4, i64 %indvars.iv
106 store i32 %tmp41, i32* %tmp42, align 4
109 bb43: ; preds = %bb35
110 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
113 bb45: ; preds = %bb33
114 %indvars.iv.next5 = add nuw nsw i64 %indvars.iv4, 1
115 %tmp46 = add nuw nsw i32 %.02, 1
118 bb47: ; preds = %bb31