1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-interchange -cache-line-size=64 -S %s | FileCheck %s
4 @global = external local_unnamed_addr global [400 x [400 x i32]], align 16
6 ; We need to move %tmp4 from the inner loop pre header to the outer loop header
7 ; before interchanging.
8 define void @test1() local_unnamed_addr #0 {
11 ; CHECK-NEXT: br label [[INNER_PH:%.*]]
12 ; CHECK: outer.header.preheader:
13 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
14 ; CHECK: outer.header:
15 ; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i64 [ [[OUTER_IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ], [ 0, [[OUTER_HEADER_PREHEADER:%.*]] ]
16 ; CHECK-NEXT: [[INNER_RED:%.*]] = phi i32 [ [[OUTER_RED:%.*]], [[OUTER_HEADER_PREHEADER]] ], [ [[RED_NEXT:%.*]], [[OUTER_LATCH]] ]
17 ; CHECK-NEXT: [[TMP4:%.*]] = add nsw i64 [[OUTER_IV]], 9
18 ; CHECK-NEXT: br label [[INNER_SPLIT1:%.*]]
20 ; CHECK-NEXT: br label [[INNER:%.*]]
22 ; CHECK-NEXT: [[INNER_IV:%.*]] = phi i64 [ 0, [[INNER_PH]] ], [ [[TMP0:%.*]], [[INNER_SPLIT:%.*]] ]
23 ; CHECK-NEXT: [[OUTER_RED]] = phi i32 [ [[RED_NEXT_LCSSA:%.*]], [[INNER_SPLIT]] ], [ 0, [[INNER_PH]] ]
24 ; CHECK-NEXT: br label [[OUTER_HEADER_PREHEADER]]
25 ; CHECK: inner.split1:
26 ; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [400 x [400 x i32]], ptr @global, i64 0, i64 [[INNER_IV]], i64 [[TMP4]]
27 ; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
28 ; CHECK-NEXT: [[RED_NEXT]] = or i32 [[INNER_RED]], 20
29 ; CHECK-NEXT: [[INNER_IV_NEXT:%.*]] = add nsw i64 [[INNER_IV]], 1
30 ; CHECK-NEXT: [[EC_1:%.*]] = icmp eq i64 [[INNER_IV_NEXT]], 400
31 ; CHECK-NEXT: br label [[OUTER_LATCH]]
33 ; CHECK-NEXT: [[RED_NEXT_LCSSA]] = phi i32 [ [[RED_NEXT]], [[OUTER_LATCH]] ]
34 ; CHECK-NEXT: [[TMP0]] = add nsw i64 [[INNER_IV]], 1
35 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[TMP0]], 400
36 ; CHECK-NEXT: br i1 [[TMP1]], label [[EXIT:%.*]], label [[INNER]]
38 ; CHECK-NEXT: [[OUTER_IV_NEXT]] = add nsw i64 [[OUTER_IV]], 1
39 ; CHECK-NEXT: [[EC_2:%.*]] = icmp eq i64 [[OUTER_IV_NEXT]], 400
40 ; CHECK-NEXT: br i1 [[EC_2]], label [[INNER_SPLIT]], label [[OUTER_HEADER]]
42 ; CHECK-NEXT: ret void
45 br label %outer.header
47 outer.header: ; preds = %bb11, %bb
48 %outer.iv = phi i64 [ 0, %bb ], [ %outer.iv.next, %outer.latch ]
49 %outer.red = phi i32 [ 0, %bb ], [ %red.next.lcssa, %outer.latch ]
52 inner.ph: ; preds = %bb1
53 %tmp4 = add nsw i64 %outer.iv, 9
56 inner: ; preds = %bb5, %bb3
57 %inner.iv = phi i64 [ 0, %inner.ph ], [ %inner.iv.next, %inner ]
58 %inner.red = phi i32 [ %outer.red, %inner.ph ], [ %red.next, %inner ]
59 %ptr = getelementptr inbounds [400 x [400 x i32]], ptr @global, i64 0, i64 %inner.iv, i64 %tmp4
61 %red.next = or i32 %inner.red, 20
62 %inner.iv.next = add nsw i64 %inner.iv, 1
63 %ec.1 = icmp eq i64 %inner.iv.next, 400
64 br i1 %ec.1, label %outer.latch, label %inner
66 outer.latch: ; preds = %bb5
67 %red.next.lcssa = phi i32 [ %red.next, %inner ]
68 %outer.iv.next = add nsw i64 %outer.iv, 1
69 %ec.2 = icmp eq i64 %outer.iv.next, 400
70 br i1 %ec.2, label %exit, label %outer.header
76 declare void @side_effect()
78 ; Cannot interchange, as the inner loop preheader contains a call to a function
81 define void @test2() {
82 ; CHECK-LABEL: @test2(
84 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
85 ; CHECK: outer.header:
86 ; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i64 [ 0, [[BB:%.*]] ], [ [[OUTER_IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
87 ; CHECK-NEXT: [[OUTER_RED:%.*]] = phi i32 [ 0, [[BB]] ], [ [[RED_NEXT_LCSSA:%.*]], [[OUTER_LATCH]] ]
88 ; CHECK-NEXT: br label [[INNER_PH:%.*]]
90 ; CHECK-NEXT: [[TMP4:%.*]] = add nsw i64 [[OUTER_IV]], 9
91 ; CHECK-NEXT: call void @side_effect()
92 ; CHECK-NEXT: br label [[INNER:%.*]]
94 ; CHECK-NEXT: [[INNER_IV:%.*]] = phi i64 [ 0, [[INNER_PH]] ], [ [[INNER_IV_NEXT:%.*]], [[INNER]] ]
95 ; CHECK-NEXT: [[INNER_RED:%.*]] = phi i32 [ [[OUTER_RED]], [[INNER_PH]] ], [ [[RED_NEXT:%.*]], [[INNER]] ]
96 ; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [400 x [400 x i32]], ptr @global, i64 0, i64 [[INNER_IV]], i64 [[TMP4]]
97 ; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
98 ; CHECK-NEXT: [[RED_NEXT]] = or i32 [[INNER_RED]], 20
99 ; CHECK-NEXT: [[INNER_IV_NEXT]] = add nsw i64 [[INNER_IV]], 1
100 ; CHECK-NEXT: [[EC_1:%.*]] = icmp eq i64 [[INNER_IV_NEXT]], 400
101 ; CHECK-NEXT: br i1 [[EC_1]], label [[OUTER_LATCH]], label [[INNER]]
102 ; CHECK: outer.latch:
103 ; CHECK-NEXT: [[RED_NEXT_LCSSA]] = phi i32 [ [[RED_NEXT]], [[INNER]] ]
104 ; CHECK-NEXT: [[OUTER_IV_NEXT]] = add nsw i64 [[OUTER_IV]], 1
105 ; CHECK-NEXT: [[EC_2:%.*]] = icmp eq i64 [[OUTER_IV_NEXT]], 400
106 ; CHECK-NEXT: br i1 [[EC_2]], label [[EXIT:%.*]], label [[OUTER_HEADER]]
108 ; CHECK-NEXT: ret void
111 br label %outer.header
113 outer.header: ; preds = %bb11, %bb
114 %outer.iv = phi i64 [ 0, %bb ], [ %outer.iv.next, %outer.latch ]
115 %outer.red = phi i32 [ 0, %bb ], [ %red.next.lcssa, %outer.latch ]
118 inner.ph: ; preds = %bb1
119 %tmp4 = add nsw i64 %outer.iv, 9
120 call void @side_effect()
123 inner: ; preds = %bb5, %bb3
124 %inner.iv = phi i64 [ 0, %inner.ph ], [ %inner.iv.next, %inner ]
125 %inner.red = phi i32 [ %outer.red, %inner.ph ], [ %red.next, %inner ]
126 %ptr = getelementptr inbounds [400 x [400 x i32]], ptr @global, i64 0, i64 %inner.iv, i64 %tmp4
127 store i32 0, ptr %ptr
128 %red.next = or i32 %inner.red, 20
129 %inner.iv.next = add nsw i64 %inner.iv, 1
130 %ec.1 = icmp eq i64 %inner.iv.next, 400
131 br i1 %ec.1, label %outer.latch, label %inner
133 outer.latch: ; preds = %bb5
134 %red.next.lcssa = phi i32 [ %red.next, %inner ]
135 %outer.iv.next = add nsw i64 %outer.iv, 1
136 %ec.2 = icmp eq i64 %outer.iv.next, 400
137 br i1 %ec.2, label %exit, label %outer.header
139 exit: ; preds = %bb11