1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info -verify-scev -verify-loop-lcssa -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info -verify-scev -verify-loop-lcssa -S | FileCheck %s
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 @A = common global [100 x [100 x i64]] zeroinitializer
8 @B = common global [100 x i64] zeroinitializer
10 ;; for(int i=0;i<100;i++)
11 ;; for(int j=0;j<100;j++)
12 ;; A[j][i] = A[j][i]+k;
14 define void @interchange_01(i64 %k, i64 %N) {
15 ; CHECK-LABEL: @interchange_01(
17 ; CHECK-NEXT: br label [[FOR2_PREHEADER:%.*]]
18 ; CHECK: for1.header.preheader:
19 ; CHECK-NEXT: br label [[FOR1_HEADER:%.*]]
21 ; CHECK-NEXT: [[J23:%.*]] = phi i64 [ [[J_NEXT24:%.*]], [[FOR1_INC10:%.*]] ], [ 0, [[FOR1_HEADER_PREHEADER:%.*]] ]
22 ; CHECK-NEXT: br label [[FOR2_SPLIT1:%.*]]
23 ; CHECK: for2.preheader:
24 ; CHECK-NEXT: br label [[FOR2:%.*]]
26 ; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[TMP0:%.*]], [[FOR2_SPLIT:%.*]] ], [ 0, [[FOR2_PREHEADER]] ]
27 ; CHECK-NEXT: br label [[FOR1_HEADER_PREHEADER]]
29 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 [[J]], i64 [[J23]]
30 ; CHECK-NEXT: [[LV:%.*]] = load i64, ptr [[ARRAYIDX5]]
31 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[LV]], [[K:%.*]]
32 ; CHECK-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX5]]
33 ; CHECK-NEXT: [[J_NEXT:%.*]] = add nuw nsw i64 [[J]], 1
34 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[J]], 99
35 ; CHECK-NEXT: br label [[FOR1_INC10]]
37 ; CHECK-NEXT: [[TMP0]] = add nuw nsw i64 [[J]], 1
38 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[J]], 99
39 ; CHECK-NEXT: br i1 [[TMP1]], label [[FOR_END12:%.*]], label [[FOR2]]
41 ; CHECK-NEXT: [[J_NEXT24]] = add nuw nsw i64 [[J23]], 1
42 ; CHECK-NEXT: [[EXITCOND26:%.*]] = icmp eq i64 [[J23]], 99
43 ; CHECK-NEXT: br i1 [[EXITCOND26]], label [[FOR2_SPLIT]], label [[FOR1_HEADER]]
45 ; CHECK-NEXT: ret void
51 %j23 = phi i64 [ 0, %entry ], [ %j.next24, %for1.inc10 ]
55 %j = phi i64 [ %j.next, %for2 ], [ 0, %for1.header ]
56 %arrayidx5 = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 %j, i64 %j23
57 %lv = load i64, ptr %arrayidx5
58 %add = add nsw i64 %lv, %k
59 store i64 %add, ptr %arrayidx5
60 %j.next = add nuw nsw i64 %j, 1
61 %exitcond = icmp eq i64 %j, 99
62 br i1 %exitcond, label %for1.inc10, label %for2
65 %j.next24 = add nuw nsw i64 %j23, 1
66 %exitcond26 = icmp eq i64 %j23, 99
67 br i1 %exitcond26, label %for.end12, label %for1.header
73 ;; for(int i=0;i<100;i++)
74 ;; for(int j=100;j>=0;j--)
75 ;; A[j][i] = A[j][i]+k;
77 define void @interchange_02(i64 %k) {
78 ; CHECK-LABEL: @interchange_02(
80 ; CHECK-NEXT: br label [[FOR3_PREHEADER:%.*]]
81 ; CHECK: for1.header.preheader:
82 ; CHECK-NEXT: br label [[FOR1_HEADER:%.*]]
84 ; CHECK-NEXT: [[J19:%.*]] = phi i64 [ [[J_NEXT20:%.*]], [[FOR1_INC10:%.*]] ], [ 0, [[FOR1_HEADER_PREHEADER:%.*]] ]
85 ; CHECK-NEXT: br label [[FOR3_SPLIT1:%.*]]
86 ; CHECK: for3.preheader:
87 ; CHECK-NEXT: br label [[FOR3:%.*]]
89 ; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[TMP1:%.*]], [[FOR3_SPLIT:%.*]] ], [ 100, [[FOR3_PREHEADER]] ]
90 ; CHECK-NEXT: br label [[FOR1_HEADER_PREHEADER]]
92 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 [[J]], i64 [[J19]]
93 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX5]]
94 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP0]], [[K:%.*]]
95 ; CHECK-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX5]]
96 ; CHECK-NEXT: [[J_NEXT:%.*]] = add nsw i64 [[J]], -1
97 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i64 [[J]], 0
98 ; CHECK-NEXT: br label [[FOR1_INC10]]
100 ; CHECK-NEXT: [[TMP1]] = add nsw i64 [[J]], -1
101 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[J]], 0
102 ; CHECK-NEXT: br i1 [[TMP2]], label [[FOR3]], label [[FOR_END11:%.*]]
104 ; CHECK-NEXT: [[J_NEXT20]] = add nuw nsw i64 [[J19]], 1
105 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[J_NEXT20]], 100
106 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR3_SPLIT]], label [[FOR1_HEADER]]
108 ; CHECK-NEXT: ret void
111 br label %for1.header
114 %j19 = phi i64 [ 0, %entry ], [ %j.next20, %for1.inc10 ]
118 %j = phi i64 [ 100, %for1.header ], [ %j.next, %for3 ]
119 %arrayidx5 = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 %j, i64 %j19
120 %0 = load i64, ptr %arrayidx5
121 %add = add nsw i64 %0, %k
122 store i64 %add, ptr %arrayidx5
123 %j.next = add nsw i64 %j, -1
124 %cmp2 = icmp sgt i64 %j, 0
125 br i1 %cmp2, label %for3, label %for1.inc10
128 %j.next20 = add nuw nsw i64 %j19, 1
129 %exitcond = icmp eq i64 %j.next20, 100
130 br i1 %exitcond, label %for.end11, label %for1.header
136 ;; Test to make sure we can handle output dependencies.
138 ;; for (int i = 1; i < 100; ++i)
139 ;; for(int j = 1; j < 99; ++j) {
143 ;; FIXME: DA misses this case after D35430
145 define void @interchange_10() {
146 ; CHECK-LABEL: @interchange_10(
148 ; CHECK-NEXT: br label [[FOR2_PREHEADER:%.*]]
149 ; CHECK: for1.header.preheader:
150 ; CHECK-NEXT: br label [[FOR1_HEADER:%.*]]
151 ; CHECK: for1.header:
152 ; CHECK-NEXT: [[J23:%.*]] = phi i64 [ [[J_NEXT24:%.*]], [[FOR1_INC10:%.*]] ], [ 1, [[FOR1_HEADER_PREHEADER:%.*]] ]
153 ; CHECK-NEXT: [[J_NEXT24]] = add nuw nsw i64 [[J23]], 1
154 ; CHECK-NEXT: br label [[FOR2_SPLIT1:%.*]]
155 ; CHECK: for2.preheader:
156 ; CHECK-NEXT: br label [[FOR2:%.*]]
158 ; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[TMP0:%.*]], [[FOR2_SPLIT:%.*]] ], [ 1, [[FOR2_PREHEADER]] ]
159 ; CHECK-NEXT: br label [[FOR1_HEADER_PREHEADER]]
160 ; CHECK: for2.split1:
161 ; CHECK-NEXT: [[J_NEXT:%.*]] = add nuw nsw i64 [[J]], 1
162 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 [[J]], i64 [[J23]]
163 ; CHECK-NEXT: store i64 [[J]], ptr [[ARRAYIDX5]]
164 ; CHECK-NEXT: [[ARRAYIDX10:%.*]] = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 [[J]], i64 [[J_NEXT24]]
165 ; CHECK-NEXT: store i64 [[J23]], ptr [[ARRAYIDX10]]
166 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[J]], 99
167 ; CHECK-NEXT: br label [[FOR1_INC10]]
169 ; CHECK-NEXT: [[TMP0]] = add nuw nsw i64 [[J]], 1
170 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[J]], 99
171 ; CHECK-NEXT: br i1 [[TMP1]], label [[FOR_END12:%.*]], label [[FOR2]]
173 ; CHECK-NEXT: [[EXITCOND26:%.*]] = icmp eq i64 [[J23]], 98
174 ; CHECK-NEXT: br i1 [[EXITCOND26]], label [[FOR2_SPLIT]], label [[FOR1_HEADER]]
176 ; CHECK-NEXT: ret void
179 br label %for1.header
182 %j23 = phi i64 [ 1, %entry ], [ %j.next24, %for1.inc10 ]
183 %j.next24 = add nuw nsw i64 %j23, 1
187 %j = phi i64 [ %j.next, %for2 ], [ 1, %for1.header ]
188 %j.next = add nuw nsw i64 %j, 1
189 %arrayidx5 = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 %j, i64 %j23
190 store i64 %j, ptr %arrayidx5
191 %arrayidx10 = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 %j, i64 %j.next24
192 store i64 %j23, ptr %arrayidx10
193 %exitcond = icmp eq i64 %j, 99
194 br i1 %exitcond, label %for1.inc10, label %for2
197 %exitcond26 = icmp eq i64 %j23, 98
198 br i1 %exitcond26, label %for.end12, label %for1.header