1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt < %s -passes=loop-interchange -S -verify-dom-info -verify-loop-info 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
8 declare void @foo(i64 %a)
9 declare void @bar(i64 %a) readnone
11 ;;--------------------------------------Test case 02------------------------------------
12 ;; Safe to interchange, because the called function `bar` is marked as readnone,
13 ;; so it cannot introduce dependences.
15 ;; for(int i=0;i<100;i++) {
16 ;; for(int j=1;j<100;j++) {
18 ;; A[j][i] = A[j][i]+k;
22 define void @interchange_02(i32 %k) {
23 ; CHECK-LABEL: define void @interchange_02(
24 ; CHECK-SAME: i32 [[K:%.*]]) {
25 ; CHECK-NEXT: [[ENTRY:.*:]]
26 ; CHECK-NEXT: br label %[[FOR2_PREHEADER:.*]]
27 ; CHECK: [[FOR1_HEADER_PREHEADER:.*]]:
28 ; CHECK-NEXT: br label %[[FOR1_HEADER:.*]]
29 ; CHECK: [[FOR1_HEADER]]:
30 ; CHECK-NEXT: [[INDVARS_IV23:%.*]] = phi i64 [ [[INDVARS_IV_NEXT24:%.*]], %[[FOR1_INC10:.*]] ], [ 0, %[[FOR1_HEADER_PREHEADER]] ]
31 ; CHECK-NEXT: br label %[[FOR2_SPLIT1:.*]]
32 ; CHECK: [[FOR2_PREHEADER]]:
33 ; CHECK-NEXT: br label %[[FOR2:.*]]
35 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[TMP0:%.*]], %[[FOR2_SPLIT:.*]] ], [ 1, %[[FOR2_PREHEADER]] ]
36 ; CHECK-NEXT: br label %[[FOR1_HEADER_PREHEADER]]
37 ; CHECK: [[FOR2_SPLIT1]]:
38 ; CHECK-NEXT: call void @bar(i64 [[INDVARS_IV23]])
39 ; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 [[INDVARS_IV]], i64 [[INDVARS_IV23]]
40 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[ARRAYIDX5]], align 4
41 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[LV]], [[K]]
42 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX5]], align 4
43 ; CHECK-NEXT: [[INDVARS_IV_NEXT:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
44 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV]], 99
45 ; CHECK-NEXT: br label %[[FOR2_LOOPEXIT:.*]]
46 ; CHECK: [[FOR2_SPLIT]]:
47 ; CHECK-NEXT: [[TMP0]] = add nuw nsw i64 [[INDVARS_IV]], 1
48 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[INDVARS_IV]], 99
49 ; CHECK-NEXT: br i1 [[TMP1]], label %[[FOR1_LOOPEXIT:.*]], label %[[FOR2]]
50 ; CHECK: [[FOR2_LOOPEXIT]]:
51 ; CHECK-NEXT: br label %[[FOR1_INC10]]
52 ; CHECK: [[FOR1_INC10]]:
53 ; CHECK-NEXT: [[INDVARS_IV_NEXT24]] = add nuw nsw i64 [[INDVARS_IV23]], 1
54 ; CHECK-NEXT: [[EXITCOND26:%.*]] = icmp eq i64 [[INDVARS_IV23]], 99
55 ; CHECK-NEXT: br i1 [[EXITCOND26]], label %[[FOR2_SPLIT]], label %[[FOR1_HEADER]]
56 ; CHECK: [[FOR1_LOOPEXIT]]:
57 ; CHECK-NEXT: br label %[[EXIT:.*]]
59 ; CHECK-NEXT: ret void
65 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc10 ]
69 %indvars.iv = phi i64 [ %indvars.iv.next, %for2 ], [ 1, %for1.header ]
70 call void @bar(i64 %indvars.iv23)
71 %arrayidx5 = getelementptr inbounds [100 x [100 x i32]], ptr @A, i64 0, i64 %indvars.iv, i64 %indvars.iv23
72 %lv = load i32, ptr %arrayidx5
73 %add = add nsw i32 %lv, %k
74 store i32 %add, ptr %arrayidx5
75 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
76 %exitcond = icmp eq i64 %indvars.iv, 99
77 br i1 %exitcond, label %for2.loopexit , label %for2
83 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
84 %exitcond26 = icmp eq i64 %indvars.iv23, 99
85 br i1 %exitcond26, label %for1.loopexit, label %for1.header