llvm.org GIT mirror llvm / 5ea6536
[Tests] Add tests to highlight sibling loop optimization order issue for exit rewriting The issue addressed in r363180 is more broadly relevant. For the moment, we don't actually get any of these cases because we a) restrict SCEV formation due to SCEExpander needing to preserve LCSSA, and b) don't iterate between loops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363192 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 3 months ago
1 changed file(s) with 151 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
11 ; RUN: opt -S -indvars < %s | FileCheck %s
22
3 define i16 @test() {
4 ; CHECK-LABEL: @test(
3 define i16 @constant() {
4 ; CHECK-LABEL: @constant(
55 ; CHECK-NEXT: entry:
66 ; CHECK-NEXT: br label [[LOOP1:%.*]]
77 ; CHECK: loop1:
5151 ret i16 %k2.add.lcssa
5252 }
5353
54 define i16 @dom_argument(i16 %arg1, i16 %arg2) {
55 ; CHECK-LABEL: @dom_argument(
56 ; CHECK-NEXT: entry:
57 ; CHECK-NEXT: br label [[LOOP1:%.*]]
58 ; CHECK: loop1:
59 ; CHECK-NEXT: [[L1:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[L1_ADD:%.*]], [[LOOP1]] ]
60 ; CHECK-NEXT: [[SELECTOR:%.*]] = phi i16 [ [[ARG1:%.*]], [[ENTRY]] ], [ [[ARG2:%.*]], [[LOOP1]] ]
61 ; CHECK-NEXT: [[L1_ADD]] = add nuw nsw i16 [[L1]], 1
62 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i16 [[L1_ADD]], 2
63 ; CHECK-NEXT: br i1 [[CMP1]], label [[LOOP1]], label [[LOOP2_PREHEADER:%.*]]
64 ; CHECK: loop2.preheader:
65 ; CHECK-NEXT: [[K1_ADD_LCSSA:%.*]] = phi i16 [ [[SELECTOR]], [[LOOP1]] ]
66 ; CHECK-NEXT: br label [[LOOP2:%.*]]
67 ; CHECK: loop2:
68 ; CHECK-NEXT: [[K2:%.*]] = phi i16 [ [[K2_ADD:%.*]], [[LOOP2]] ], [ [[K1_ADD_LCSSA]], [[LOOP2_PREHEADER]] ]
69 ; CHECK-NEXT: [[L2:%.*]] = phi i16 [ [[L2_ADD:%.*]], [[LOOP2]] ], [ 0, [[LOOP2_PREHEADER]] ]
70 ; CHECK-NEXT: [[L2_ADD]] = add nuw nsw i16 [[L2]], 1
71 ; CHECK-NEXT: tail call void @foo(i16 [[K2]])
72 ; CHECK-NEXT: [[K2_ADD]] = add nuw nsw i16 [[K2]], 1
73 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i16 [[L2_ADD]], 2
74 ; CHECK-NEXT: br i1 [[CMP2]], label [[LOOP2]], label [[LOOP2_END:%.*]]
75 ; CHECK: loop2.end:
76 ; CHECK-NEXT: [[K2_ADD_LCSSA:%.*]] = phi i16 [ [[K2_ADD]], [[LOOP2]] ]
77 ; CHECK-NEXT: ret i16 [[K2_ADD_LCSSA]]
78 ;
79 entry:
80 br label %loop1
81
82 loop1: ; preds = %entry, %loop1
83 %k1 = phi i16 [ 100, %entry ], [ %k1.add, %loop1 ]
84 %l1 = phi i16 [ 0, %entry ], [ %l1.add, %loop1 ]
85 %selector = phi i16 [ %arg1, %entry ], [ %arg2, %loop1 ]
86 %k1.add = add nuw nsw i16 %k1, 1
87 %l1.add = add nuw nsw i16 %l1, 1
88 %cmp1 = icmp ult i16 %l1.add, 2
89 br i1 %cmp1, label %loop1, label %loop2.preheader
90
91 loop2.preheader: ; preds = %loop1
92 %k1.add.lcssa = phi i16 [ %selector, %loop1 ]
93 br label %loop2
94
95 loop2: ; preds = %loop2.preheader, %loop2
96 %k2 = phi i16 [ %k2.add, %loop2 ], [ %k1.add.lcssa, %loop2.preheader ]
97 %l2 = phi i16 [ %l2.add, %loop2 ], [ 0, %loop2.preheader ]
98 %l2.add = add nuw i16 %l2, 1
99 tail call void @foo(i16 %k2)
100 %k2.add = add nuw nsw i16 %k2, 1
101 %cmp2 = icmp ult i16 %l2.add, 2
102 br i1 %cmp2, label %loop2, label %loop2.end
103
104 loop2.end: ; preds = %loop2
105 %k2.add.lcssa = phi i16 [ %k2.add, %loop2 ]
106 ret i16 %k2.add.lcssa
107 }
108
109 define i16 @dummy_phi_outside_loop(i16 %arg) {
110 ; CHECK-LABEL: @dummy_phi_outside_loop(
111 ; CHECK-NEXT: entry:
112 ; CHECK-NEXT: br label [[LOOP2_PREHEADER:%.*]]
113 ; CHECK: loop2.preheader:
114 ; CHECK-NEXT: [[DUMMY:%.*]] = phi i16 [ [[ARG:%.*]], [[ENTRY:%.*]] ]
115 ; CHECK-NEXT: br label [[LOOP2:%.*]]
116 ; CHECK: loop2:
117 ; CHECK-NEXT: [[K2:%.*]] = phi i16 [ [[K2_ADD:%.*]], [[LOOP2]] ], [ [[DUMMY]], [[LOOP2_PREHEADER]] ]
118 ; CHECK-NEXT: [[L2:%.*]] = phi i16 [ [[L2_ADD:%.*]], [[LOOP2]] ], [ 0, [[LOOP2_PREHEADER]] ]
119 ; CHECK-NEXT: [[L2_ADD]] = add nuw nsw i16 [[L2]], 1
120 ; CHECK-NEXT: tail call void @foo(i16 [[K2]])
121 ; CHECK-NEXT: [[K2_ADD]] = add nuw nsw i16 [[K2]], 1
122 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i16 [[L2_ADD]], 2
123 ; CHECK-NEXT: br i1 [[CMP2]], label [[LOOP2]], label [[LOOP2_END:%.*]]
124 ; CHECK: loop2.end:
125 ; CHECK-NEXT: [[K2_ADD_LCSSA:%.*]] = phi i16 [ [[K2_ADD]], [[LOOP2]] ]
126 ; CHECK-NEXT: ret i16 [[K2_ADD_LCSSA]]
127 ;
128 entry:
129 br label %loop2.preheader
130
131 loop2.preheader: ; preds = %loop1
132 %dummy = phi i16 [ %arg, %entry ]
133 br label %loop2
134
135 loop2: ; preds = %loop2.preheader, %loop2
136 %k2 = phi i16 [ %k2.add, %loop2 ], [ %dummy, %loop2.preheader ]
137 %l2 = phi i16 [ %l2.add, %loop2 ], [ 0, %loop2.preheader ]
138 %l2.add = add nuw i16 %l2, 1
139 tail call void @foo(i16 %k2)
140 %k2.add = add nuw nsw i16 %k2, 1
141 %cmp2 = icmp ult i16 %l2.add, 2
142 br i1 %cmp2, label %loop2, label %loop2.end
143
144 loop2.end: ; preds = %loop2
145 %k2.add.lcssa = phi i16 [ %k2.add, %loop2 ]
146 ret i16 %k2.add.lcssa
147 }
148
149 define i16 @neg_loop_carried(i16 %arg) {
150 ; CHECK-LABEL: @neg_loop_carried(
151 ; CHECK-NEXT: entry:
152 ; CHECK-NEXT: br label [[LOOP1:%.*]]
153 ; CHECK: loop1:
154 ; CHECK-NEXT: [[L1:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[L1_ADD:%.*]], [[LOOP1]] ]
155 ; CHECK-NEXT: [[L1_ADD]] = add nuw nsw i16 [[L1]], 1
156 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i16 [[L1_ADD]], 2
157 ; CHECK-NEXT: br i1 [[CMP1]], label [[LOOP1]], label [[LOOP2_PREHEADER:%.*]]
158 ; CHECK: loop2.preheader:
159 ; CHECK-NEXT: [[TMP0:%.*]] = add i16 [[ARG:%.*]], 2
160 ; CHECK-NEXT: br label [[LOOP2:%.*]]
161 ; CHECK: loop2:
162 ; CHECK-NEXT: [[K2:%.*]] = phi i16 [ [[K2_ADD:%.*]], [[LOOP2]] ], [ [[TMP0]], [[LOOP2_PREHEADER]] ]
163 ; CHECK-NEXT: [[L2:%.*]] = phi i16 [ [[L2_ADD:%.*]], [[LOOP2]] ], [ 0, [[LOOP2_PREHEADER]] ]
164 ; CHECK-NEXT: [[L2_ADD]] = add nuw nsw i16 [[L2]], 1
165 ; CHECK-NEXT: tail call void @foo(i16 [[K2]])
166 ; CHECK-NEXT: [[K2_ADD]] = add nuw nsw i16 [[K2]], 1
167 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i16 [[L2_ADD]], 2
168 ; CHECK-NEXT: br i1 [[CMP2]], label [[LOOP2]], label [[LOOP2_END:%.*]]
169 ; CHECK: loop2.end:
170 ; CHECK-NEXT: [[K2_ADD_LCSSA:%.*]] = phi i16 [ [[K2_ADD]], [[LOOP2]] ]
171 ; CHECK-NEXT: ret i16 [[K2_ADD_LCSSA]]
172 ;
173 entry:
174 br label %loop1
175
176 loop1: ; preds = %entry, %loop1
177 %k1 = phi i16 [ %arg, %entry ], [ %k1.add, %loop1 ]
178 %l1 = phi i16 [ 0, %entry ], [ %l1.add, %loop1 ]
179 %k1.add = add nuw nsw i16 %k1, 1
180 %l1.add = add nuw nsw i16 %l1, 1
181 %cmp1 = icmp ult i16 %l1.add, 2
182 br i1 %cmp1, label %loop1, label %loop2.preheader
183
184 loop2.preheader: ; preds = %loop1
185 %k1.add.lcssa = phi i16 [ %k1.add, %loop1 ]
186 br label %loop2
187
188 loop2: ; preds = %loop2.preheader, %loop2
189 %k2 = phi i16 [ %k2.add, %loop2 ], [ %k1.add.lcssa, %loop2.preheader ]
190 %l2 = phi i16 [ %l2.add, %loop2 ], [ 0, %loop2.preheader ]
191 %l2.add = add nuw i16 %l2, 1
192 tail call void @foo(i16 %k2)
193 %k2.add = add nuw nsw i16 %k2, 1
194 %cmp2 = icmp ult i16 %l2.add, 2
195 br i1 %cmp2, label %loop2, label %loop2.end
196
197 loop2.end: ; preds = %loop2
198 %k2.add.lcssa = phi i16 [ %k2.add, %loop2 ]
199 ret i16 %k2.add.lcssa
200 }
201
202
54203 declare void @foo(i16)