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