| 1 |
; Remove 'S' Scalar Dependencies #119345 |
| 2 |
; Scalar dependencies are not handled correctly, so they were removed to avoid |
| 3 |
; miscompiles. The loop nest in this test case used to be interchanged, but it's |
| 4 |
; no longer triggering. XFAIL'ing this test to indicate that this test should |
| 5 |
; interchanged if scalar deps are handled correctly. |
| 6 |
; |
| 7 |
; XFAIL: * |
| 8 |
|
| 9 |
; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info -pass-remarks-output=%t -disable-output |
| 10 |
; RUN: FileCheck -input-file %t %s |
| 11 |
|
| 12 |
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 13 |
|
| 14 |
@A = common global [100 x [100 x i32]] zeroinitializer |
| 15 |
@B = common global [100 x i32] zeroinitializer |
| 16 |
@C = common global [100 x [100 x i32]] zeroinitializer |
| 17 |
@D = common global [100 x [100 x [100 x i32]]] zeroinitializer |
| 18 |
@T = internal global [100 x double] zeroinitializer, align 4 |
| 19 |
@Arr = internal global [1000 x [1000 x i32]] zeroinitializer, align 4 |
| 20 |
|
| 21 |
; Test that a flow dependency in outer loop doesn't prevent interchange in |
| 22 |
; loops i and j. |
| 23 |
; |
| 24 |
; for (int k = 0; k < 100; ++k) { |
| 25 |
; T[k] = fn1(); |
| 26 |
; for (int i = 0; i < 1000; ++i) |
| 27 |
; for(int j = 1; j < 1000; ++j) |
| 28 |
; Arr[j][i] = Arr[j][i]+k; |
| 29 |
; fn2(T[k]); |
| 30 |
; } |
| 31 |
; |
| 32 |
; So, loops InnerLoopId = 2 and OuterLoopId = 1 should be interchanged, |
| 33 |
; but not InnerLoopId = 1 and OuterLoopId = 0. |
| 34 |
; |
| 35 |
; CHECK: --- !Passed |
| 36 |
; CHECK-NEXT: Pass: loop-interchange |
| 37 |
; CHECK-NEXT: Name: Interchanged |
| 38 |
; CHECK-NEXT: Function: interchange_09 |
| 39 |
; CHECK-NEXT: Args: |
| 40 |
; CHECK-NEXT: - String: Loop interchanged with enclosing loop. |
| 41 |
; CHECK-NEXT: ... |
| 42 |
; CHECK-NEXT: --- !Missed |
| 43 |
; CHECK-NEXT: Pass: loop-interchange |
| 44 |
; CHECK-NEXT: Name: NotTightlyNested |
| 45 |
; CHECK-NEXT: Function: interchange_09 |
| 46 |
; CHECK-NEXT: Args: |
| 47 |
; CHECK-NEXT: - String: Cannot interchange loops because they are not tightly nested. |
| 48 |
; CHECK-NEXT: ... |
| 49 |
; CHECK-NEXT: --- !Missed |
| 50 |
; CHECK-NEXT: Pass: loop-interchange |
| 51 |
; CHECK-NEXT: Name: InterchangeNotProfitable |
| 52 |
; CHECK-NEXT: Function: interchange_09 |
| 53 |
; CHECK-NEXT: Args: |
| 54 |
; CHECK-NEXT: - String: Interchanging loops is not considered to improve cache locality nor vectorization. |
| 55 |
; CHECK-NEXT: ... |
| 56 |
|
| 57 |
define void @interchange_09(i32 %k) { |
| 58 |
entry: |
| 59 |
br label %for.body |
| 60 |
|
| 61 |
for.cond.cleanup: ; preds = %for.cond.cleanup4 |
| 62 |
ret void |
| 63 |
|
| 64 |
for.body: ; preds = %for.cond.cleanup4, %entry |
| 65 |
%indvars.iv45 = phi i64 [ 0, %entry ], [ %indvars.iv.next46, %for.cond.cleanup4 ] |
| 66 |
%call = call double @fn1() |
| 67 |
%arrayidx = getelementptr inbounds [100 x double], ptr @T, i64 0, i64 %indvars.iv45 |
| 68 |
store double %call, ptr %arrayidx, align 8 |
| 69 |
br label %for.cond6.preheader |
| 70 |
|
| 71 |
for.cond6.preheader: ; preds = %for.cond.cleanup8, %for.body |
| 72 |
%indvars.iv42 = phi i64 [ 0, %for.body ], [ %indvars.iv.next43, %for.cond.cleanup8 ] |
| 73 |
br label %for.body9 |
| 74 |
|
| 75 |
for.cond.cleanup4: ; preds = %for.cond.cleanup8 |
| 76 |
%tmp = load double, ptr %arrayidx, align 8 |
| 77 |
call void @fn2(double %tmp) |
| 78 |
%indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1 |
| 79 |
%exitcond47 = icmp ne i64 %indvars.iv.next46, 100 |
| 80 |
br i1 %exitcond47, label %for.body, label %for.cond.cleanup |
| 81 |
|
| 82 |
for.cond.cleanup8: ; preds = %for.body9 |
| 83 |
%indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1 |
| 84 |
%exitcond44 = icmp ne i64 %indvars.iv.next43, 1000 |
| 85 |
br i1 %exitcond44, label %for.cond6.preheader, label %for.cond.cleanup4 |
| 86 |
|
| 87 |
for.body9: ; preds = %for.body9, %for.cond6.preheader |
| 88 |
%indvars.iv = phi i64 [ 1, %for.cond6.preheader ], [ %indvars.iv.next, %for.body9 ] |
| 89 |
%arrayidx13 = getelementptr inbounds [1000 x [1000 x i32]], ptr @Arr, i64 0, i64 %indvars.iv, i64 %indvars.iv42 |
| 90 |
%t1 = load i32, ptr %arrayidx13, align 4 |
| 91 |
%t2 = trunc i64 %indvars.iv45 to i32 |
| 92 |
%add = add nsw i32 %t1, %t2 |
| 93 |
store i32 %add, ptr %arrayidx13, align 4 |
| 94 |
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 95 |
%exitcond = icmp ne i64 %indvars.iv.next, 1000 |
| 96 |
br i1 %exitcond, label %for.body9, label %for.cond.cleanup8 |
| 97 |
} |
| 98 |
|
| 99 |
declare double @fn1() readnone |
| 100 |
declare void @fn2(double) readnone |