2 ; RUN: opt < %s -passes='loop(loop-interchange),simplifycfg' -cache-line-size=64 -simplifycfg-require-and-preserve-domtree=1 -pass-remarks-output=%t \
3 ; RUN: -pass-remarks=loop-interchange -pass-remarks-missed=loop-interchange -stats -S 2>&1 \
4 ; RUN: | FileCheck -check-prefix=STATS %s
5 ; RUN: FileCheck -input-file %t %s
8 ; no_deps_interchange just accesses a single nested array and can be interchange.
9 ; CHECK: Name: Interchanged
10 ; CHECK-NEXT: Function: no_deps_interchange
11 define i32 @no_deps_interchange(ptr nocapture %Arr) local_unnamed_addr #0 {
15 for1.header: ; preds = %entry, %for1.inc
16 %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for1.inc ]
19 for2: ; preds = %for1.header, %for2
20 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next, %for2 ]
21 %arrayidx6 = getelementptr inbounds [1024 x i32], ptr %Arr, i64 %indvars.iv, i64 %indvars.iv19
22 store i32 0, ptr %arrayidx6, align 4
23 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
24 %exitcond = icmp ne i64 %indvars.iv.next, 1024
25 br i1 %exitcond, label %for2, label %for1.inc
28 %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
29 %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
30 br i1 %exitcond21, label %for1.header, label %exit
32 exit: ; preds = %for1.inc
37 ; No memory access using any induction variables, interchanging not beneficial.
38 ; CHECK: Name: InterchangeNotProfitable
39 ; CHECK-NEXT: Function: no_mem_instrs
40 define i32 @no_mem_instrs(ptr %ptr) {
44 for1.header: ; preds = %entry, %for1.inc
45 %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for1.inc ]
48 for2: ; preds = %for1.header, %for2
49 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next, %for2 ]
50 store i64 %indvars.iv, ptr %ptr, align 4
51 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
52 %exitcond = icmp ne i64 %indvars.iv.next, 1024
53 br i1 %exitcond, label %for2, label %for1.inc
56 %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
57 %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
58 br i1 %exitcond21, label %for1.header, label %exit
60 exit: ; preds = %for1.inc
65 ; Check stats, we interchanged 1 out of 3 loops.
66 ; STATS: 1 loop-interchange - Number of loops interchanged