| 1 |
; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 \ |
| 2 |
; RUN: -pass-remarks-output=%t -disable-output |
| 3 |
; RUN: FileCheck -input-file %t --check-prefix=PROFIT-CACHE %s |
| 4 |
|
| 5 |
; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 \ |
| 6 |
; RUN: -pass-remarks-output=%t -disable-output -loop-interchange-profitabilities=vectorize,cache,instorder |
| 7 |
; RUN: FileCheck -input-file %t --check-prefix=PROFIT-VEC %s |
| 8 |
|
| 9 |
@A = dso_local global [256 x [256 x float]] zeroinitializer |
| 10 |
@B = dso_local global [256 x [256 x float]] zeroinitializer |
| 11 |
@C = dso_local global [256 x [256 x float]] zeroinitializer |
| 12 |
@D = dso_local global [256 x [256 x float]] zeroinitializer |
| 13 |
@E = dso_local global [256 x [256 x float]] zeroinitializer |
| 14 |
@F = dso_local global [256 x [256 x float]] zeroinitializer |
| 15 |
|
| 16 |
; Check the behavior of the LoopInterchange cost-model. In the below code, |
| 17 |
; exchanging the loops is not profitable in terms of cache, but it is necessary |
| 18 |
; to vectorize the innermost loop. |
| 19 |
; |
| 20 |
; for (int i = 0; i < 256; i++) |
| 21 |
; for (int j = 1; j < 256; j++) |
| 22 |
; A[j][i] = A[j-1][i] + B[j][i] + C[i][j] + D[i][j] + E[i][j] + F[i][j]; |
| 23 |
; |
| 24 |
|
| 25 |
; PROFIT-CACHE: --- !Missed |
| 26 |
; PROFIT-CACHE-NEXT: Pass: loop-interchange |
| 27 |
; PROFIT-CACHE-NEXT: Name: InterchangeNotProfitable |
| 28 |
; PROFIT-CACHE-NEXT: Function: f |
| 29 |
; PROFIT-CACHE-NEXT: Args: |
| 30 |
; PROFIT-CACHE-NEXT: - String: Interchanging loops is not considered to improve cache locality nor vectorization. |
| 31 |
; PROFIT-CACHE-NEXT: ... |
| 32 |
|
| 33 |
; PROFIT-VEC: --- !Passed |
| 34 |
; PROFIT-VEC-NEXT: Pass: loop-interchange |
| 35 |
; PROFIT-VEC-NEXT: Name: Interchanged |
| 36 |
; PROFIT-VEC-NEXT: Function: f |
| 37 |
; PROFIT-VEC-NEXT: Args: |
| 38 |
; PROFIT-VEC-NEXT: - String: Loop interchanged with enclosing loop. |
| 39 |
; PROFIT-VEC-NEXT: ... |
| 40 |
define void @f() { |
| 41 |
entry: |
| 42 |
br label %for.i.header |
| 43 |
|
| 44 |
for.i.header: |
| 45 |
%i = phi i64 [ 0, %entry ], [ %i.next, %for.i.inc ] |
| 46 |
br label %for.j.body |
| 47 |
|
| 48 |
for.j.body: |
| 49 |
%j = phi i64 [ 1, %for.i.header ], [ %j.next, %for.j.body ] |
| 50 |
%j.dec = add nsw i64 %j, -1 |
| 51 |
%a.0.index = getelementptr nuw inbounds [256 x [256 x float]], ptr @A, i64 0, i64 %j.dec, i64 %i |
| 52 |
%b.index = getelementptr nuw inbounds [256 x [256 x float]], ptr @B, i64 0, i64 %j, i64 %i |
| 53 |
%c.index = getelementptr nuw inbounds [256 x [256 x float]], ptr @C, i64 0, i64 %i, i64 %j |
| 54 |
%d.index = getelementptr nuw inbounds [256 x [256 x float]], ptr @D, i64 0, i64 %i, i64 %j |
| 55 |
%e.index = getelementptr nuw inbounds [256 x [256 x float]], ptr @E, i64 0, i64 %i, i64 %j |
| 56 |
%f.index = getelementptr nuw inbounds [256 x [256 x float]], ptr @F, i64 0, i64 %i, i64 %j |
| 57 |
%a.0 = load float, ptr %a.0.index, align 4 |
| 58 |
%b = load float, ptr %b.index, align 4 |
| 59 |
%c = load float, ptr %c.index, align 4 |
| 60 |
%d = load float, ptr %d.index, align 4 |
| 61 |
%e = load float, ptr %e.index, align 4 |
| 62 |
%f = load float, ptr %f.index, align 4 |
| 63 |
%add.0 = fadd float %a.0, %b |
| 64 |
%add.1 = fadd float %add.0, %c |
| 65 |
%add.2 = fadd float %add.1, %d |
| 66 |
%add.3 = fadd float %add.2, %e |
| 67 |
%add.4 = fadd float %add.3, %f |
| 68 |
%a.1.index = getelementptr nuw inbounds [256 x float], ptr @A, i64 %j, i64 %i |
| 69 |
store float %add.4, ptr %a.1.index, align 4 |
| 70 |
%j.next = add nuw nsw i64 %j, 1 |
| 71 |
%cmp.j = icmp eq i64 %j.next, 256 |
| 72 |
br i1 %cmp.j, label %for.i.inc, label %for.j.body |
| 73 |
|
| 74 |
for.i.inc: |
| 75 |
%i.next = add nuw nsw i64 %i, 1 |
| 76 |
%cmp.i = icmp eq i64 %i.next, 256 |
| 77 |
br i1 %cmp.i, label %exit, label %for.i.header |
| 78 |
|
| 79 |
exit: |
| 80 |
ret void |
| 81 |
} |