1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt < %s -passes=loop-interchange -verify-dom-info -verify-loop-info -S 2>&1 | FileCheck %s
4 @A = common global [100 x [100 x i64]] zeroinitializer
5 @N = dso_local local_unnamed_addr global i64 100, align 8
7 ; Inner loop induction variable exit condition depends on
8 ; an outer loop invariant, can do interchange.
10 define void @interchange_04(i64 %k) {
11 ; CHECK-LABEL: define void @interchange_04(
12 ; CHECK-SAME: i64 [[K:%.*]]) {
13 ; CHECK-NEXT: [[ENTRY:.*:]]
14 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @N, align 4
15 ; CHECK-NEXT: br label %[[FOR2_PREHEADER:.*]]
16 ; CHECK: [[FOR1_HEADER_PREHEADER:.*]]:
17 ; CHECK-NEXT: br label %[[FOR1_HEADER:.*]]
18 ; CHECK: [[FOR1_HEADER]]:
19 ; CHECK-NEXT: [[I:%.*]] = phi i64 [ [[I_NEXT:%.*]], %[[FOR1_INC10:.*]] ], [ 0, %[[FOR1_HEADER_PREHEADER]] ]
20 ; CHECK-NEXT: br label %[[FOR2_SPLIT1:.*]]
21 ; CHECK: [[FOR2_PREHEADER]]:
22 ; CHECK-NEXT: br label %[[FOR2:.*]]
24 ; CHECK-NEXT: [[J:%.*]] = phi i64 [ [[TMP1:%.*]], %[[FOR2_SPLIT:.*]] ], [ 0, %[[FOR2_PREHEADER]] ]
25 ; CHECK-NEXT: br label %[[FOR1_HEADER_PREHEADER]]
26 ; CHECK: [[FOR2_SPLIT1]]:
27 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 [[J]], i64 [[I]]
28 ; CHECK-NEXT: [[LV:%.*]] = load i64, ptr [[ARRAYIDX5]], align 4
29 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[LV]], [[K]]
30 ; CHECK-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX5]], align 4
31 ; CHECK-NEXT: [[J_NEXT:%.*]] = add nuw nsw i64 [[J]], 1
32 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[TMP0]], [[J]]
33 ; CHECK-NEXT: br label %[[FOR1_INC10]]
34 ; CHECK: [[FOR2_SPLIT]]:
35 ; CHECK-NEXT: [[TMP1]] = add nuw nsw i64 [[J]], 1
36 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i64 [[TMP0]], [[J]]
37 ; CHECK-NEXT: br i1 [[TMP2]], label %[[FOR2]], label %[[FOR_END12:.*]]
38 ; CHECK: [[FOR1_INC10]]:
39 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i64 [[I]], 1
40 ; CHECK-NEXT: [[EXITCOND26:%.*]] = icmp eq i64 [[I]], 99
41 ; CHECK-NEXT: br i1 [[EXITCOND26]], label %[[FOR2_SPLIT]], label %[[FOR1_HEADER]]
42 ; CHECK: [[FOR_END12]]:
43 ; CHECK-NEXT: ret void
46 %0 = load i64, ptr @N, align 4
50 %i = phi i64 [ 0, %entry ], [ %i.next, %for1.inc10 ]
54 %j = phi i64 [ %j.next, %for2 ], [ 0, %for1.header ]
55 %arrayidx5 = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 %j, i64 %i
56 %lv = load i64, ptr %arrayidx5
57 %add = add nsw i64 %lv, %k
58 store i64 %add, ptr %arrayidx5
59 %j.next = add nuw nsw i64 %j, 1
60 %exitcond = icmp ne i64 %0, %j
61 br i1 %exitcond, label %for2, label %for1.inc10
64 %i.next = add nuw nsw i64 %i, 1
65 %exitcond26 = icmp eq i64 %i, 99
66 br i1 %exitcond26, label %for.end12, label %for1.header