1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info -S 2>&1 | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6 @D = common global [100 x [100 x [100 x i32]]] zeroinitializer
8 ; Test for interchange in loop nest greater than 2.
10 ; for(int i=0;i<100;i++)
11 ; for(int j=0;j<100;j++)
12 ; for(int k=0;k<100;k++)
13 ; D[i][k][j] = D[i][k][j]+t;
15 ; Loops InnerLoopId = 2 and OuterLoopId = 1 should be interchanged, but not
16 ; loops InnerLoopId = 1 and OuterLoopId = 0 as that is not profitable.
18 define void @interchange_08(i32 %t){
19 ; CHECK-LABEL: define void @interchange_08(
20 ; CHECK-SAME: i32 [[T:%.*]]) {
21 ; CHECK-NEXT: [[ENTRY:.*]]:
22 ; CHECK-NEXT: br label %[[FOR_COND1_PREHEADER:.*]]
23 ; CHECK: [[FOR_COND1_PREHEADER]]:
24 ; CHECK-NEXT: [[I_028:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INC16:%.*]], %[[FOR_INC15:.*]] ]
25 ; CHECK-NEXT: br label %[[FOR_BODY6_PREHEADER:.*]]
26 ; CHECK: [[FOR_COND4_PREHEADER_PREHEADER:.*]]:
27 ; CHECK-NEXT: br label %[[FOR_COND4_PREHEADER:.*]]
28 ; CHECK: [[FOR_COND4_PREHEADER]]:
29 ; CHECK-NEXT: [[J_027:%.*]] = phi i64 [ [[INC13:%.*]], %[[FOR_INC12:.*]] ], [ 0, %[[FOR_COND4_PREHEADER_PREHEADER]] ]
30 ; CHECK-NEXT: br label %[[FOR_BODY6_SPLIT1:.*]]
31 ; CHECK: [[FOR_BODY6_PREHEADER]]:
32 ; CHECK-NEXT: br label %[[FOR_BODY6:.*]]
33 ; CHECK: [[FOR_BODY6]]:
34 ; CHECK-NEXT: [[K_026:%.*]] = phi i64 [ [[TMP1:%.*]], %[[FOR_BODY6_SPLIT:.*]] ], [ 0, %[[FOR_BODY6_PREHEADER]] ]
35 ; CHECK-NEXT: br label %[[FOR_COND4_PREHEADER_PREHEADER]]
36 ; CHECK: [[FOR_BODY6_SPLIT1]]:
37 ; CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds [100 x [100 x [100 x i32]]], ptr @D, i32 0, i64 [[I_028]], i64 [[K_026]], i64 [[J_027]]
38 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX8]], align 4
39 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], [[T]]
40 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX8]], align 4
41 ; CHECK-NEXT: [[INC:%.*]] = add nuw nsw i64 [[K_026]], 1
42 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INC]], 100
43 ; CHECK-NEXT: br label %[[FOR_INC12]]
44 ; CHECK: [[FOR_BODY6_SPLIT]]:
45 ; CHECK-NEXT: [[TMP1]] = add nuw nsw i64 [[K_026]], 1
46 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 100
47 ; CHECK-NEXT: br i1 [[TMP2]], label %[[FOR_INC15]], label %[[FOR_BODY6]]
48 ; CHECK: [[FOR_INC12]]:
49 ; CHECK-NEXT: [[INC13]] = add nuw nsw i64 [[J_027]], 1
50 ; CHECK-NEXT: [[EXITCOND29:%.*]] = icmp eq i64 [[INC13]], 100
51 ; CHECK-NEXT: br i1 [[EXITCOND29]], label %[[FOR_BODY6_SPLIT]], label %[[FOR_COND4_PREHEADER]]
52 ; CHECK: [[FOR_INC15]]:
53 ; CHECK-NEXT: [[INC16]] = add nuw nsw i64 [[I_028]], 1
54 ; CHECK-NEXT: [[EXITCOND30:%.*]] = icmp eq i64 [[INC16]], 100
55 ; CHECK-NEXT: br i1 [[EXITCOND30]], label %[[FOR_END17:.*]], label %[[FOR_COND1_PREHEADER]]
56 ; CHECK: [[FOR_END17]]:
57 ; CHECK-NEXT: ret void
60 br label %for.cond1.preheader
62 for.cond1.preheader: ; preds = %for.inc15, %entry
63 %i.028 = phi i64 [ 0, %entry ], [ %inc16, %for.inc15 ]
64 br label %for.cond4.preheader
66 for.cond4.preheader: ; preds = %for.inc12, %for.cond1.preheader
67 %j.027 = phi i64 [ 0, %for.cond1.preheader ], [ %inc13, %for.inc12 ]
70 for.body6: ; preds = %for.body6, %for.cond4.preheader
71 %k.026 = phi i64 [ 0, %for.cond4.preheader ], [ %inc, %for.body6 ]
72 %arrayidx8 = getelementptr inbounds [100 x [100 x [100 x i32]]], ptr @D, i32 0, i64 %i.028, i64 %k.026, i64 %j.027
73 %0 = load i32, ptr %arrayidx8
74 %add = add nsw i32 %0, %t
75 store i32 %add, ptr %arrayidx8
76 %inc = add nuw nsw i64 %k.026, 1
77 %exitcond = icmp eq i64 %inc, 100
78 br i1 %exitcond, label %for.inc12, label %for.body6
80 for.inc12: ; preds = %for.body6
81 %inc13 = add nuw nsw i64 %j.027, 1
82 %exitcond29 = icmp eq i64 %inc13, 100
83 br i1 %exitcond29, label %for.inc15, label %for.cond4.preheader
85 for.inc15: ; preds = %for.inc12
86 %inc16 = add nuw nsw i64 %i.028, 1
87 %exitcond30 = icmp eq i64 %inc16, 100
88 br i1 %exitcond30, label %for.end17, label %for.cond1.preheader
90 for.end17: ; preds = %for.inc15