1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt < %s -passes='loop(loop-interchange),simplifycfg' -simplifycfg-require-and-preserve-domtree=1 \
3 ; RUN: -pass-remarks=loop-interchange -pass-remarks-missed=loop-interchange -stats -S 2>&1 \
4 ; RUN: | FileCheck -check-prefix=STATS %s
6 ; no_deps_interchange just accesses a single nested array and can be interchange.
8 define i32 @no_deps_interchange(ptr nocapture %Arr) {
9 ; STATS-LABEL: define i32 @no_deps_interchange(
10 ; STATS-SAME: ptr nocapture [[ARR:%.*]]) {
11 ; STATS-NEXT: [[ENTRY:.*]]:
12 ; STATS-NEXT: br label %[[FOR2:.*]]
13 ; STATS: [[FOR1_HEADER:.*]]:
14 ; STATS-NEXT: [[INDVARS_IV19:%.*]] = phi i64 [ [[INDVARS_IV_NEXT20:%.*]], %[[FOR1_HEADER]] ], [ 0, %[[FOR2]] ]
15 ; STATS-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds [1024 x i32], ptr [[ARR]], i64 [[INDVARS_IV:%.*]], i64 [[INDVARS_IV19]]
16 ; STATS-NEXT: store i32 0, ptr [[ARRAYIDX6]], align 4
17 ; STATS-NEXT: [[INDVARS_IV_NEXT:%.*]] = add nuw nsw i64 [[INDVARS_IV]], 1
18 ; STATS-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], 1024
19 ; STATS-NEXT: [[INDVARS_IV_NEXT20]] = add nuw nsw i64 [[INDVARS_IV19]], 1
20 ; STATS-NEXT: [[EXITCOND21:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT20]], 1024
21 ; STATS-NEXT: br i1 [[EXITCOND21]], label %[[FOR1_HEADER]], label %[[FOR2_SPLIT:.*]]
23 ; STATS-NEXT: [[INDVARS_IV]] = phi i64 [ [[TMP0:%.*]], %[[FOR2_SPLIT]] ], [ 0, %[[ENTRY]] ]
24 ; STATS-NEXT: br label %[[FOR1_HEADER]]
25 ; STATS: [[FOR2_SPLIT]]:
26 ; STATS-NEXT: [[TMP0]] = add nuw nsw i64 [[INDVARS_IV]], 1
27 ; STATS-NEXT: [[TMP1:%.*]] = icmp ne i64 [[TMP0]], 1024
28 ; STATS-NEXT: br i1 [[TMP1]], label %[[FOR2]], label %[[EXIT:.*]]
30 ; STATS-NEXT: ret i32 0
36 %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for1.inc ]
40 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next, %for2 ]
41 %arrayidx6 = getelementptr inbounds [1024 x i32], ptr %Arr, i64 %indvars.iv, i64 %indvars.iv19
42 store i32 0, ptr %arrayidx6, align 4
43 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
44 %exitcond = icmp ne i64 %indvars.iv.next, 1024
45 br i1 %exitcond, label %for2, label %for1.inc
48 %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
49 %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
50 br i1 %exitcond21, label %for1.header, label %exit
57 ; No memory access using any induction variables, interchanging not beneficial.
59 define i32 @no_mem_instrs(ptr %ptr) {
60 ; STATS-LABEL: define i32 @no_mem_instrs(
61 ; STATS-SAME: ptr [[PTR:%.*]]) {
62 ; STATS-NEXT: [[ENTRY:.*]]:
63 ; STATS-NEXT: br label %[[FOR1_HEADER:.*]]
64 ; STATS: [[FOR1_HEADER]]:
65 ; STATS-NEXT: [[INDVARS_IV19:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INDVARS_IV_NEXT20:%.*]], %[[FOR1_INC:.*]] ]
66 ; STATS-NEXT: br label %[[FOR2:.*]]
68 ; STATS-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[FOR1_HEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR2]] ]
69 ; STATS-NEXT: store i64 [[INDVARS_IV]], ptr [[PTR]], align 4
70 ; STATS-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
71 ; STATS-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT]], 1024
72 ; STATS-NEXT: br i1 [[EXITCOND]], label %[[FOR2]], label %[[FOR1_INC]]
73 ; STATS: [[FOR1_INC]]:
74 ; STATS-NEXT: [[INDVARS_IV_NEXT20]] = add nuw nsw i64 [[INDVARS_IV19]], 1
75 ; STATS-NEXT: [[EXITCOND21:%.*]] = icmp ne i64 [[INDVARS_IV_NEXT20]], 1024
76 ; STATS-NEXT: br i1 [[EXITCOND21]], label %[[FOR1_HEADER]], label %[[EXIT:.*]]
78 ; STATS-NEXT: ret i32 0
84 %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for1.inc ]
88 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next, %for2 ]
89 store i64 %indvars.iv, ptr %ptr, align 4
90 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
91 %exitcond = icmp ne i64 %indvars.iv.next, 1024
92 br i1 %exitcond, label %for2, label %for1.inc
95 %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
96 %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
97 br i1 %exitcond21, label %for1.header, label %exit
99 exit: ; preds = %for1.inc