2 ; RUN: opt < %s -loop-interchange -simplifycfg -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([1024 x i32]* 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], [1024 x i32]* %Arr, i64 %indvars.iv, i64 %indvars.iv19
22 store i32 0, i32* %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 ; Only the inner loop induction variable is used for memory accesses.
38 ; Interchanging is not beneficial.
39 ; CHECK: Name: InterchangeNotProfitable
40 ; CHECK-NEXT: Function: no_bad_order
41 define i32 @no_bad_order(i32* %Arr) {
45 for1.header: ; preds = %entry, %for1.inc
46 %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for1.inc ]
49 for2: ; preds = %for1.header, %for2
50 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next, %for2 ]
51 %arrayidx6 = getelementptr inbounds i32, i32* %Arr, i64 %indvars.iv
52 store i32 0, i32* %arrayidx6, align 4
53 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
54 %exitcond = icmp ne i64 %indvars.iv.next, 1024
55 br i1 %exitcond, label %for2, label %for1.inc
58 %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
59 %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
60 br i1 %exitcond21, label %for1.header, label %exit
62 exit: ; preds = %for1.inc
66 ; No memory access using any induction variables, interchanging not beneficial.
67 ; CHECK: Name: InterchangeNotProfitable
68 ; CHECK-NEXT: Function: no_mem_instrs
69 define i32 @no_mem_instrs(i64* %ptr) {
73 for1.header: ; preds = %entry, %for1.inc
74 %indvars.iv19 = phi i64 [ 0, %entry ], [ %indvars.iv.next20, %for1.inc ]
77 for2: ; preds = %for1.header, %for2
78 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next, %for2 ]
79 store i64 %indvars.iv, i64* %ptr, align 4
80 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
81 %exitcond = icmp ne i64 %indvars.iv.next, 1024
82 br i1 %exitcond, label %for2, label %for1.inc
85 %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
86 %exitcond21 = icmp ne i64 %indvars.iv.next20, 1024
87 br i1 %exitcond21, label %for1.header, label %exit
89 exit: ; preds = %for1.inc
94 ; Check stats, we interchanged 1 out of 3 loops.
95 ; STATS: 1 loop-interchange - Number of loops interchanged