1 ; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t -S \
2 ; RUN: -verify-dom-info -verify-loop-info -verify-loop-lcssa 2>&1 | FileCheck -check-prefix=IR %s
3 ; RUN: FileCheck --input-file=%t %s
5 ; Inner loop only reductions are not supported currently. See discussion at
6 ; D53027 for more information on the required checks.
8 @A = common global [500 x [500 x i32]] zeroinitializer
9 @X = common global i32 0
10 @B = common global [500 x [500 x i32]] zeroinitializer
11 @Y = common global i32 0
15 ;; for( int i=1;i<N;i++)
16 ;; for( int j=1;j<N;j++)
20 ; CHECK-NEXT: Pass: loop-interchange
21 ; CHECK-NEXT: Name: UnsupportedPHI
22 ; CHECK-NEXT: Function: reduction_01
24 ; IR-LABEL: @reduction_01(
27 define void @reduction_01(i32 %N) {
29 %cmp16 = icmp sgt i32 %N, 1
30 br i1 %cmp16, label %for.body3.lr.ph, label %for.end8
32 for.body3.lr.ph: ; preds = %for.cond1.for.inc6_crit_edge, %entry
33 %indvars.iv18 = phi i64 [ %indvars.iv.next19, %for.cond1.for.inc6_crit_edge ], [ 1, %entry ]
34 %X.promoted = load i32, ptr @X
37 for.body3: ; preds = %for.body3, %for.body3.lr.ph
38 %indvars.iv = phi i64 [ 1, %for.body3.lr.ph ], [ %indvars.iv.next, %for.body3 ]
39 %add15 = phi i32 [ %X.promoted, %for.body3.lr.ph ], [ %add, %for.body3 ]
40 %arrayidx5 = getelementptr inbounds [500 x [500 x i32]], ptr @A, i64 0, i64 %indvars.iv, i64 %indvars.iv18
41 %0 = load i32, ptr %arrayidx5
42 %add = add nsw i32 %add15, %0
43 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
44 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
45 %exitcond = icmp eq i32 %lftr.wideiv, %N
46 br i1 %exitcond, label %for.cond1.for.inc6_crit_edge, label %for.body3
48 for.cond1.for.inc6_crit_edge: ; preds = %for.body3
49 %add.lcssa = phi i32 [ %add, %for.body3 ]
50 store i32 %add.lcssa, ptr @X
51 %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
52 %lftr.wideiv20 = trunc i64 %indvars.iv.next19 to i32
53 %exitcond21 = icmp eq i32 %lftr.wideiv20, %N
54 br i1 %exitcond21, label %for.end8, label %for.body3.lr.ph
56 for.end8: ; preds = %for.cond1.for.inc6_crit_edge, %entry
60 ;; Not tightly nested. Do not interchange.
61 ;; for( int i=1;i<N;i++)
62 ;; for( int j=1;j<N;j++) {
63 ;; for( int k=1;k<N;k++) {
69 ;; Not tightly nested. Do not interchange.
70 ;; Not interchanged hence the phi's in the inner loop will not be split.
73 ; CHECK-NEXT: Pass: loop-interchange
74 ; CHECK-NEXT: Name: UnsupportedPHIOuter
75 ; CHECK-NEXT: Function: reduction_03
77 ; IR-LABEL: @reduction_03(
80 define void @reduction_03(i32 %N) {
82 %cmp35 = icmp sgt i32 %N, 1
83 br i1 %cmp35, label %for.cond4.preheader.lr.ph, label %for.end19
85 for.cond4.preheader.lr.ph: ; preds = %for.cond1.for.inc17_crit_edge, %entry
86 %indvars.iv41 = phi i64 [ %indvars.iv.next42, %for.cond1.for.inc17_crit_edge ], [ 1, %entry ]
87 %Y.promoted = load i32, ptr @Y
88 br label %for.body6.lr.ph
90 for.body6.lr.ph: ; preds = %for.cond4.for.end_crit_edge, %for.cond4.preheader.lr.ph
91 %indvars.iv37 = phi i64 [ 1, %for.cond4.preheader.lr.ph ], [ %indvars.iv.next38, %for.cond4.for.end_crit_edge ]
92 %add1334 = phi i32 [ %Y.promoted, %for.cond4.preheader.lr.ph ], [ %add13, %for.cond4.for.end_crit_edge ]
93 %X.promoted = load i32, ptr @X
96 for.body6: ; preds = %for.body6, %for.body6.lr.ph
97 %indvars.iv = phi i64 [ 1, %for.body6.lr.ph ], [ %indvars.iv.next, %for.body6 ]
98 %arrayidx8 = getelementptr inbounds [500 x [500 x i32]], ptr @A, i64 0, i64 %indvars.iv, i64 %indvars.iv37
99 %0 = load i32, ptr %arrayidx8
100 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
101 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
102 %exitcond = icmp eq i32 %lftr.wideiv, %N
103 br i1 %exitcond, label %for.cond4.for.end_crit_edge, label %for.body6
105 for.cond4.for.end_crit_edge: ; preds = %for.body6
106 %arrayidx12 = getelementptr inbounds [500 x [500 x i32]], ptr @B, i64 0, i64 %indvars.iv37, i64 %indvars.iv41
107 %1 = load i32, ptr %arrayidx12
108 %add13 = add nsw i32 %add1334, %1
109 %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
110 %lftr.wideiv39 = trunc i64 %indvars.iv.next38 to i32
111 %exitcond40 = icmp eq i32 %lftr.wideiv39, %N
112 br i1 %exitcond40, label %for.cond1.for.inc17_crit_edge, label %for.body6.lr.ph
114 for.cond1.for.inc17_crit_edge: ; preds = %for.cond4.for.end_crit_edge
115 %add13.lcssa = phi i32 [ %add13, %for.cond4.for.end_crit_edge ]
116 store i32 %add13.lcssa, ptr @Y
117 %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
118 %lftr.wideiv43 = trunc i64 %indvars.iv.next42 to i32
119 %exitcond44 = icmp eq i32 %lftr.wideiv43, %N
120 br i1 %exitcond44, label %for.end19, label %for.cond4.preheader.lr.ph
122 for.end19: ; preds = %for.cond1.for.inc17_crit_edge, %entry