• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Test optimization remarks generated by the LoopInterchange pass.
2;
3; RUN: opt < %s -basicaa -loop-interchange -verify-dom-info -verify-loop-info \
4; RUN:     -pass-remarks-output=%t -pass-remarks-missed='loop-interchange' \
5; RUN:     -pass-remarks='loop-interchange' -S
6; RUN: cat %t |  FileCheck %s
7
8@A = common global [100 x [100 x i32]] zeroinitializer
9@B = common global [100 x [100 x i32]] zeroinitializer
10@C = common global [100 x i32] zeroinitializer
11
12;;---------------------------------------Test case 01---------------------------------
13;; Loops interchange is not profitable.
14;;   for(int i=1;i<N;i++)
15;;     for(int j=1;j<N;j++)
16;;       A[i-1][j-1] = A[i - 1][j-1] + B[i][j];
17
18define void @test01(i32 %N){
19entry:
20  %cmp31 = icmp sgt i32 %N, 1
21  br i1 %cmp31, label %for.cond1.preheader.lr.ph, label %for.end19
22
23for.cond1.preheader.lr.ph:
24  %0 = add i32 %N, -1
25  br label %for.body3.lr.ph
26
27for.body3.lr.ph:
28  %indvars.iv34 = phi i64 [ 1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next35, %for.inc17 ]
29  %1 = add nsw i64 %indvars.iv34, -1
30  br label %for.body3
31
32for.body3:
33  %indvars.iv = phi i64 [ 1, %for.body3.lr.ph ], [ %indvars.iv.next, %for.body3 ]
34  %2 = add nsw i64 %indvars.iv, -1
35  %arrayidx6 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %1, i64 %2
36  %3 = load i32, i32* %arrayidx6
37  %arrayidx10 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @B, i64 0, i64 %indvars.iv34, i64 %indvars.iv
38  %4 = load i32, i32* %arrayidx10
39  %add = add nsw i32 %4, %3
40  store i32 %add, i32* %arrayidx6
41  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
42  %lftr.wideiv = trunc i64 %indvars.iv to i32
43  %exitcond = icmp eq i32 %lftr.wideiv, %0
44  br i1 %exitcond, label %for.inc17, label %for.body3
45
46for.inc17:
47  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
48  %lftr.wideiv37 = trunc i64 %indvars.iv34 to i32
49  %exitcond38 = icmp eq i32 %lftr.wideiv37, %0
50  br i1 %exitcond38, label %for.end19, label %for.body3.lr.ph
51
52for.end19:
53  ret void
54}
55
56; CHECK: --- !Missed
57; CHECK-NEXT: Pass:            loop-interchange
58; CHECK-NEXT: Name:            Dependence
59; CHECK-NEXT: Function:        test01
60; CHECK-NEXT: Args:
61; CHECK-NEXT:   - String:          Cannot interchange loops due to dependences.
62; CHECK-NEXT: ...
63
64;;--------------------------------------Test case 02------------------------------------
65;; [FIXME] This loop though valid is currently not interchanged due to the
66;; limitation that we cannot split the inner loop latch due to multiple use of inner induction
67;; variable.(used to increment the loop counter and to access A[j+1][i+1]
68;;  for(int i=0;i<N-1;i++)
69;;    for(int j=1;j<N-1;j++)
70;;      A[j+1][i+1] = A[j+1][i+1] + k;
71
72define void @test02(i32 %k, i32 %N) {
73 entry:
74   %sub = add nsw i32 %N, -1
75   %cmp26 = icmp sgt i32 %N, 1
76   br i1 %cmp26, label %for.cond1.preheader.lr.ph, label %for.end17
77
78 for.cond1.preheader.lr.ph:
79   %cmp324 = icmp sgt i32 %sub, 1
80   %0 = add i32 %N, -2
81   %1 = sext i32 %sub to i64
82   br label %for.cond1.preheader
83
84 for.cond.loopexit:
85   %cmp = icmp slt i64 %indvars.iv.next29, %1
86   br i1 %cmp, label %for.cond1.preheader, label %for.end17
87
88 for.cond1.preheader:
89   %indvars.iv28 = phi i64 [ 0, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next29, %for.cond.loopexit ]
90   %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
91   br i1 %cmp324, label %for.body4, label %for.cond.loopexit
92
93 for.body4:
94   %indvars.iv = phi i64 [ %indvars.iv.next, %for.body4 ], [ 1, %for.cond1.preheader ]
95   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
96   %arrayidx7 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next29
97   %2 = load i32, i32* %arrayidx7
98   %add8 = add nsw i32 %2, %k
99   store i32 %add8, i32* %arrayidx7
100   %lftr.wideiv = trunc i64 %indvars.iv to i32
101   %exitcond = icmp eq i32 %lftr.wideiv, %0
102   br i1 %exitcond, label %for.cond.loopexit, label %for.body4
103
104 for.end17:
105   ret void
106}
107
108; CHECK: --- !Missed
109; CHECK-NEXT: Pass:            loop-interchange
110; CHECK-NEXT: Name:            Dependence
111; CHECK-NEXT: Function:        test02
112; CHECK-NEXT: Args:
113; CHECK-NEXT:   - String:          Cannot interchange loops due to dependences.
114; CHECK-NEXT: ...
115
116;;-----------------------------------Test case 03-------------------------------
117;; Test to make sure we can handle output dependencies.
118;;
119;;  for (int i = 0; i < 2; ++i)
120;;    for(int j = 0; j < 3; ++j) {
121;;      A[j][i] = i;
122;;      A[j][i+1] = j;
123;;    }
124
125@A10 = local_unnamed_addr global [3 x [3 x i32]] zeroinitializer, align 16
126
127define void @test03() {
128entry:
129  br label %for.cond1.preheader
130
131for.cond.loopexit:                                ; preds = %for.body4
132  %exitcond28 = icmp ne i64 %indvars.iv.next27, 2
133  br i1 %exitcond28, label %for.cond1.preheader, label %for.cond.cleanup
134
135for.cond1.preheader:                              ; preds = %for.cond.loopexit, %entry
136  %indvars.iv26 = phi i64 [ 0, %entry ], [ %indvars.iv.next27, %for.cond.loopexit ]
137  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
138  br label %for.body4
139
140for.cond.cleanup:                                 ; preds = %for.cond.loopexit
141  ret void
142
143for.body4:                                        ; preds = %for.body4, %for.cond1.preheader
144  %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body4 ]
145  %arrayidx6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv26
146  %tmp = trunc i64 %indvars.iv26 to i32
147  store i32 %tmp, i32* %arrayidx6, align 4
148  %arrayidx10 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @A10, i64 0, i64 %indvars.iv, i64 %indvars.iv.next27
149  %tmp1 = trunc i64 %indvars.iv to i32
150  store i32 %tmp1, i32* %arrayidx10, align 4
151  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
152  %exitcond = icmp ne i64 %indvars.iv.next, 3
153  br i1 %exitcond, label %for.body4, label %for.cond.loopexit
154}
155
156; CHECK: --- !Missed
157; CHECK-NEXT: Pass:            loop-interchange
158; CHECK-NEXT: Name:            Dependence
159; CHECK-NEXT: Function:        test03
160; CHECK-NEXT: Args:
161; CHECK-NEXT:   - String:          Cannot interchange loops due to dependences.
162; CHECK-NEXT: ...
163
164;;--------------------------------------Test case 04-------------------------------------
165;; Loops not tightly nested are not interchanged
166;;  for(int j=0;j<N;j++) {
167;;    B[j] = j+k;
168;;    for(int i=0;i<N;i++)
169;;      A[j][i] = A[j][i]+B[j];
170;;  }
171
172define void @test04(i32 %k, i32 %N){
173entry:
174  %cmp30 = icmp sgt i32 %N, 0
175  br i1 %cmp30, label %for.body.lr.ph, label %for.end17
176
177for.body.lr.ph:
178  %0 = add i32 %N, -1
179  %1 = zext i32 %k to i64
180  br label %for.body
181
182for.body:
183  %indvars.iv32 = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next33, %for.inc15 ]
184  %2 = add nsw i64 %indvars.iv32, %1
185  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* @C, i64 0, i64 %indvars.iv32
186  %3 = trunc i64 %2 to i32
187  store i32 %3, i32* %arrayidx
188  br label %for.body3
189
190for.body3:
191  %indvars.iv = phi i64 [ 0, %for.body ], [ %indvars.iv.next, %for.body3 ]
192  %arrayidx7 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* @A, i64 0, i64 %indvars.iv32, i64 %indvars.iv
193  %4 = load i32, i32* %arrayidx7
194  %add10 = add nsw i32 %3, %4
195  store i32 %add10, i32* %arrayidx7
196  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
197  %lftr.wideiv = trunc i64 %indvars.iv to i32
198  %exitcond = icmp eq i32 %lftr.wideiv, %0
199  br i1 %exitcond, label %for.inc15, label %for.body3
200
201for.inc15:
202  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
203  %lftr.wideiv35 = trunc i64 %indvars.iv32 to i32
204  %exitcond36 = icmp eq i32 %lftr.wideiv35, %0
205  br i1 %exitcond36, label %for.end17, label %for.body
206
207for.end17:
208  ret void
209}
210
211; CHECK: --- !Missed
212; CHECK-NEXT: Pass:            loop-interchange
213; CHECK-NEXT: Name:            Dependence
214; CHECK-NEXT: Function:        test04
215; CHECK-NEXT: Args:
216; CHECK-NEXT:   - String:          Cannot interchange loops due to dependences.
217; CHECK-NEXT: ...
218