1 ; RUN: opt < %s -basicaa -loop-interchange -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t -S \
2 ; RUN: -verify-dom-info -verify-loop-info -verify-loop-lcssa -stats 2>&1 | FileCheck %s
3 ; RUN: FileCheck --input-file=%t --check-prefix=REMARKS %s
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
10 ; REMARKS-NEXT: Pass: loop-interchange
11 ; REMARKS-NEXT: Name: Interchanged
12 ; REMARKS-NEXT: Function: test1
14 define i64 @test1([100 x [100 x i64]]* %Arr) {
15 ; CHECK-LABEL: @test1(
17 ; CHECK-NEXT: br label [[FOR2_PREHEADER:%.*]]
18 ; CHECK: for1.header.preheader:
19 ; CHECK-NEXT: br label [[FOR1_HEADER:%.*]]
21 ; CHECK-NEXT: [[INDVARS_IV23:%.*]] = phi i64 [ [[INDVARS_IV_NEXT24:%.*]], [[FOR1_INC:%.*]] ], [ 0, [[FOR1_HEADER_PREHEADER:%.*]] ]
22 ; CHECK-NEXT: [[SUM_INNER:%.*]] = phi i64 [ [[SUM_INC:%.*]], [[FOR1_INC]] ], [ [[SUM_OUTER:%.*]], [[FOR1_HEADER_PREHEADER]] ]
23 ; CHECK-NEXT: br label [[FOR2_SPLIT1:%.*]]
24 ; CHECK: for2.preheader:
25 ; CHECK-NEXT: br label [[FOR2:%.*]]
27 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT_3:%.*]], [[FOR2_SPLIT:%.*]] ], [ 0, [[FOR2_PREHEADER]] ]
28 ; CHECK-NEXT: [[SUM_OUTER]] = phi i64 [ [[SUM_INC_LCSSA:%.*]], [[FOR2_SPLIT]] ], [ 0, [[FOR2_PREHEADER]] ]
29 ; CHECK-NEXT: br label [[FOR1_HEADER_PREHEADER]]
31 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [100 x [100 x i64]], [100 x [100 x i64]]* [[ARR:%.*]], i64 0, i64 [[INDVARS_IV]], i64 [[INDVARS_IV23]]
32 ; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[ARRAYIDX]], align 4
33 ; CHECK-NEXT: [[SUM_INC]] = add i64 [[SUM_INNER]], [[LV]]
34 ; CHECK-NEXT: br label [[FOR1_INC]]
36 ; CHECK-NEXT: [[SUM_INC_LCSSA]] = phi i64 [ [[SUM_INC]], %for1.inc ]
37 ; CHECK-NEXT: [[INDVARS_IV_NEXT_3]] = add nuw nsw i64 [[INDVARS_IV]], 1
38 ; CHECK-NEXT: [[EXIT1:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT_3]], 100
39 ; CHECK-NEXT: br i1 [[EXIT1]], label [[FOR1_LOOPEXIT:%.*]], label [[FOR2]]
41 ; CHECK-NEXT: [[INDVARS_IV_NEXT24]] = add nuw nsw i64 [[INDVARS_IV23]], 1
42 ; CHECK-NEXT: [[EXIT2:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT24]], 100
43 ; CHECK-NEXT: br i1 [[EXIT2]], label [[FOR2_SPLIT]], label [[FOR1_HEADER]]
44 ; CHECK: for1.loopexit:
45 ; CHECK-NEXT: [[SUM_INC_LCSSA2:%.*]] = phi i64 [ [[SUM_INC_LCSSA]], [[FOR2_SPLIT]] ]
46 ; CHECK-NEXT: ret i64 [[SUM_INC_LCSSA2]]
51 for1.header: ; preds = %for1.inc, %entry
52 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc ]
53 %sum.outer = phi i64 [ 0, %entry ], [ %sum.inc.lcssa, %for1.inc ]
56 for2: ; preds = %for2, %for1.header
57 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next.3, %for2 ]
58 %sum.inner = phi i64 [ %sum.outer, %for1.header ], [ %sum.inc, %for2 ]
59 %arrayidx = getelementptr inbounds [100 x [100 x i64]], [100 x [100 x i64]]* %Arr, i64 0, i64 %indvars.iv, i64 %indvars.iv23
60 %lv = load i64, i64* %arrayidx, align 4
61 %sum.inc = add i64 %sum.inner, %lv
62 %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 1
63 %exit1 = icmp eq i64 %indvars.iv.next.3, 100
64 br i1 %exit1, label %for1.inc, label %for2
66 for1.inc: ; preds = %for2
67 %sum.inc.lcssa = phi i64 [ %sum.inc, %for2 ]
68 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
69 %exit2 = icmp eq i64 %indvars.iv.next24, 100
70 br i1 %exit2, label %for1.loopexit, label %for1.header
72 for1.loopexit: ; preds = %for1.inc
73 %sum.inc.lcssa2 = phi i64 [ %sum.inc.lcssa, %for1.inc ]
74 ret i64 %sum.inc.lcssa2
77 ; In this test case, the inner reduction PHI %inner does not involve the outer
78 ; reduction PHI %sum.outer, do not interchange.
79 ; REMARKS: --- !Missed
80 ; REMARKS-NEXT: Pass: loop-interchange
81 ; REMARKS-NEXT: Name: UnsupportedPHIOuter
82 ; REMARKS-NEXT: Function: test2
84 define i64 @test2([100 x [100 x i64]]* %Arr) {
88 for1.header: ; preds = %for1.inc, %entry
89 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc ]
90 %sum.outer = phi i64 [ 0, %entry ], [ %sum.inc.lcssa, %for1.inc ]
93 for2: ; preds = %for2, %for1.header
94 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next.3, %for2 ]
95 %inner = phi i64 [ %indvars.iv23, %for1.header ], [ %sum.inc, %for2 ]
96 %arrayidx = getelementptr inbounds [100 x [100 x i64]], [100 x [100 x i64]]* %Arr, i64 0, i64 %indvars.iv, i64 %indvars.iv23
97 %lv = load i64, i64* %arrayidx, align 4
98 %sum.inc = add i64 %inner, %lv
99 %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 1
100 %exit1 = icmp eq i64 %indvars.iv.next.3, 100
101 br i1 %exit1, label %for1.inc, label %for2
103 for1.inc: ; preds = %for2
104 %sum.inc.lcssa = phi i64 [ %sum.inc, %for2 ]
105 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
106 %exit2 = icmp eq i64 %indvars.iv.next24, 100
107 br i1 %exit2, label %for1.loopexit, label %for1.header
109 for1.loopexit: ; preds = %for1.inc
110 %sum.inc.lcssa2 = phi i64 [ %sum.inc.lcssa, %for1.inc ]
111 ret i64 %sum.inc.lcssa2
114 ; Check that we do not interchange if there is an additional instruction
115 ; between the outer and inner reduction PHIs.
116 ; REMARKS: --- !Missed
117 ; REMARKS-NEXT: Pass: loop-interchange
118 ; REMARKS-NEXT: Name: UnsupportedPHIOuter
119 ; REMARKS-NEXT: Function: test3
121 define i64 @test3([100 x [100 x i64]]* %Arr) {
123 br label %for1.header
125 for1.header: ; preds = %for1.inc, %entry
126 %indvars.iv23 = phi i64 [ 0, %entry ], [ %indvars.iv.next24, %for1.inc ]
127 %sum.outer = phi i64 [ 0, %entry ], [ %sum.inc.lcssa, %for1.inc ]
128 %so = add i64 %sum.outer, 10
131 for2: ; preds = %for2, %for1.header
132 %indvars.iv = phi i64 [ 0, %for1.header ], [ %indvars.iv.next.3, %for2 ]
133 %sum.inner = phi i64 [ %so, %for1.header ], [ %sum.inc, %for2 ]
134 %arrayidx = getelementptr inbounds [100 x [100 x i64]], [100 x [100 x i64]]* %Arr, i64 0, i64 %indvars.iv, i64 %indvars.iv23
135 %lv = load i64, i64* %arrayidx, align 4
136 %sum.inc = add i64 %sum.inner, %lv
137 %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 1
138 %exit1 = icmp eq i64 %indvars.iv.next.3, 100
139 br i1 %exit1, label %for1.inc, label %for2
141 for1.inc: ; preds = %for2
142 %sum.inc.lcssa = phi i64 [ %sum.inc, %for2 ]
143 %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
144 %exit2 = icmp eq i64 %indvars.iv.next24, 100
145 br i1 %exit2, label %for1.loopexit, label %for1.header
147 for1.loopexit: ; preds = %for1.inc
148 %sum.inc.lcssa2 = phi i64 [ %sum.inc.lcssa, %for1.inc ]
149 ret i64 %sum.inc.lcssa2