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 @A = common global [100 x [100 x i32]] zeroinitializer
7 @B = common global [100 x i32] zeroinitializer
9 ; Loops should not be interchanged in this case as it is not legal due to dependency.
11 ; for(int j=0;j<99;j++)
12 ; for(int i=0;i<99;i++)
13 ; A[j][i+1] = A[j+1][i]+k;
15 define void @interchange_04(i32 %k){
16 ; CHECK-LABEL: define void @interchange_04(
17 ; CHECK-SAME: i32 [[K:%.*]]) {
18 ; CHECK-NEXT: [[ENTRY:.*]]:
19 ; CHECK-NEXT: br label %[[FOR_COND1_PREHEADER:.*]]
20 ; CHECK: [[FOR_COND1_PREHEADER]]:
21 ; CHECK-NEXT: [[INDVARS_IV23:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT24:%.*]], %[[FOR_INC12:.*]] ]
22 ; CHECK-NEXT: [[INDVARS_IV_NEXT24]] = add nuw nsw i64 [[INDVARS_IV23]], 1
23 ; CHECK-NEXT: br label %[[FOR_BODY3:.*]]
24 ; CHECK: [[FOR_BODY3]]:
25 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[FOR_COND1_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY3]] ]
26 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 [[INDVARS_IV_NEXT24]], i64 [[INDVARS_IV]]
27 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX5]], align 4
28 ; CHECK-NEXT: [[ADD6:%.*]] = add nsw i32 [[TMP0]], [[K]]
29 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
30 ; CHECK-NEXT: [[ARRAYIDX11:%.*]] = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 [[INDVARS_IV23]], i64 [[INDVARS_IV_NEXT]]
31 ; CHECK-NEXT: store i32 [[ADD6]], ptr [[ARRAYIDX11]], align 4
32 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 99
33 ; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_INC12]], label %[[FOR_BODY3]]
34 ; CHECK: [[FOR_INC12]]:
35 ; CHECK-NEXT: [[EXITCOND25:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT24]], 99
36 ; CHECK-NEXT: br i1 [[EXITCOND25]], label %[[FOR_END14:.*]], label %[[FOR_COND1_PREHEADER]]
37 ; CHECK: [[FOR_END14]]:
38 ; CHECK-NEXT: ret void
41 br label %for.cond1.preheader
44 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for.inc12 ]
45 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
49 %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body3 ]
50 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 %indvars.iv.next24, i64 %indvars.iv
51 %0 = load i32, ptr %arrayidx5
52 %add6 = add nsw i32 %0, %k
53 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
54 %arrayidx11 = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 %indvars.iv23, i64 %indvars.iv.next
55 store i32 %add6, ptr %arrayidx11
56 %exitcond = icmp eq i64 %indvars.iv.next, 99
57 br i1 %exitcond, label %for.inc12, label %for.body3
60 %exitcond25 = icmp eq i64 %indvars.iv.next24, 99
61 br i1 %exitcond25, label %for.end14, label %for.cond1.preheader