| 1 |
; RUN: opt < %s -passes=loop-interchange -cache-line-size=1 -pass-remarks-output=%t -disable-output \ |
| 2 |
; RUN: -verify-dom-info -verify-loop-info |
| 3 |
; RUN: FileCheck -input-file %t %s |
| 4 |
|
| 5 |
|
| 6 |
; Test that loop-interchange doesn't undo its own transoformation. This is |
| 7 |
; the case when the cost computed by CacheCost is the same for the loop of `j` |
| 8 |
; and `k`. |
| 9 |
; |
| 10 |
; #define N 4 |
| 11 |
; int a[N*N][N*N][N*N]; |
| 12 |
; void f() { |
| 13 |
; for (int i = 0; i < N; i++) |
| 14 |
; for (int j = 1; j < 2*N; j++) |
| 15 |
; for (int k = 1; k < 2*N; k++) |
| 16 |
; a[i][k+1][j-1] -= a[i+N-1][k][j]; |
| 17 |
; } |
| 18 |
|
| 19 |
; CHECK: --- !Passed |
| 20 |
; CHECK-NEXT: Pass: loop-interchange |
| 21 |
; CHECK-NEXT: Name: Interchanged |
| 22 |
; CHECK-NEXT: Function: f |
| 23 |
; CHECK-NEXT: Args: |
| 24 |
; CHECK-NEXT: - String: Loop interchanged with enclosing loop. |
| 25 |
; CHECK-NEXT: ... |
| 26 |
; CHECK-NEXT: --- !Missed |
| 27 |
; CHECK-NEXT: Pass: loop-interchange |
| 28 |
; CHECK-NEXT: Name: Dependence |
| 29 |
; CHECK-NEXT: Function: f |
| 30 |
; CHECK-NEXT: Args: |
| 31 |
; CHECK-NEXT: - String: Cannot interchange loops due to dependences. |
| 32 |
; CHECK-NEXT: ... |
| 33 |
; CHECK-NEXT: --- !Missed |
| 34 |
; CHECK-NEXT: Pass: loop-interchange |
| 35 |
; CHECK-NEXT: Name: InterchangeNotProfitable |
| 36 |
; CHECK-NEXT: Function: f |
| 37 |
; CHECK-NEXT: Args: |
| 38 |
; CHECK-NEXT: - String: Interchanging loops is not considered to improve cache locality nor vectorization. |
| 39 |
; CHECK-NEXT: ... |
| 40 |
|
| 41 |
@a = dso_local local_unnamed_addr global [16 x [16 x [16 x i32]]] zeroinitializer, align 4 |
| 42 |
|
| 43 |
define dso_local void @f() { |
| 44 |
entry: |
| 45 |
br label %for.cond1.preheader |
| 46 |
|
| 47 |
for.cond1.preheader: |
| 48 |
%indvars.iv46 = phi i64 [ 0, %entry ], [ %indvars.iv.next47, %for.cond.cleanup3 ] |
| 49 |
%0 = add nuw nsw i64 %indvars.iv46, 3 |
| 50 |
br label %for.cond5.preheader |
| 51 |
|
| 52 |
for.cond5.preheader: |
| 53 |
%indvars.iv41 = phi i64 [ 1, %for.cond1.preheader ], [ %indvars.iv.next42, %for.cond.cleanup7 ] |
| 54 |
%1 = add nsw i64 %indvars.iv41, -1 |
| 55 |
br label %for.body8 |
| 56 |
|
| 57 |
for.cond.cleanup3: |
| 58 |
%indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1 |
| 59 |
%exitcond50 = icmp ne i64 %indvars.iv.next47, 4 |
| 60 |
br i1 %exitcond50, label %for.cond1.preheader, label %for.cond.cleanup |
| 61 |
|
| 62 |
for.cond.cleanup7: |
| 63 |
%indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1 |
| 64 |
%exitcond45 = icmp ne i64 %indvars.iv.next42, 8 |
| 65 |
br i1 %exitcond45, label %for.cond5.preheader, label %for.cond.cleanup3 |
| 66 |
|
| 67 |
for.body8: |
| 68 |
%indvars.iv = phi i64 [ 1, %for.cond5.preheader ], [ %indvars.iv.next, %for.body8 ] |
| 69 |
%arrayidx12 = getelementptr inbounds nuw [16 x [16 x [16 x i32]]], ptr @a, i64 0, i64 %0, i64 %indvars.iv, i64 %indvars.iv41 |
| 70 |
%2 = load i32, ptr %arrayidx12, align 4 |
| 71 |
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 72 |
%arrayidx20 = getelementptr inbounds [16 x [16 x [16 x i32]]], ptr @a, i64 0, i64 %indvars.iv46, i64 %indvars.iv.next, i64 %1 |
| 73 |
%3 = load i32, ptr %arrayidx20, align 4 |
| 74 |
%sub21 = sub nsw i32 %3, %2 |
| 75 |
store i32 %sub21, ptr %arrayidx20, align 4 |
| 76 |
%exitcond = icmp ne i64 %indvars.iv.next, 8 |
| 77 |
br i1 %exitcond, label %for.body8, label %for.cond.cleanup7 |
| 78 |
|
| 79 |
for.cond.cleanup: |
| 80 |
ret void |
| 81 |
} |