@@ -188,4 +188,102 @@ exit:
188188 ret void
189189}
190190
191+ define i32 @wrapping_known_range (i8 range(i8 0 , 6 ) %arg ) {
192+ ; CHECK-LABEL: @wrapping_known_range(
193+ ; CHECK-NEXT: switch i8 [[ARG:%.*]], label [[ELSE:%.*]] [
194+ ; CHECK-NEXT: i8 0, label [[IF:%.*]]
195+ ; CHECK-NEXT: i8 4, label [[IF]]
196+ ; CHECK-NEXT: i8 5, label [[IF]]
197+ ; CHECK-NEXT: ]
198+ ; CHECK: common.ret:
199+ ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[I0:%.*]], [[IF]] ], [ [[I1:%.*]], [[ELSE]] ]
200+ ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
201+ ; CHECK: if:
202+ ; CHECK-NEXT: [[I0]] = call i32 @f(i32 0)
203+ ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
204+ ; CHECK: else:
205+ ; CHECK-NEXT: [[I1]] = call i32 @f(i32 1)
206+ ; CHECK-NEXT: br label [[COMMON_RET]]
207+ ;
208+ switch i8 %arg , label %else [
209+ i8 0 , label %if
210+ i8 4 , label %if
211+ i8 5 , label %if
212+ ]
213+
214+ if:
215+ %i0 = call i32 @f (i32 0 )
216+ ret i32 %i0
217+
218+ else:
219+ %i1 = call i32 @f (i32 1 )
220+ ret i32 %i1
221+ }
222+
223+ define i32 @wrapping_range (i8 %arg ) {
224+ ; CHECK-LABEL: @wrapping_range(
225+ ; CHECK-NEXT: switch i8 [[ARG:%.*]], label [[ELSE:%.*]] [
226+ ; CHECK-NEXT: i8 0, label [[IF:%.*]]
227+ ; CHECK-NEXT: i8 -3, label [[IF]]
228+ ; CHECK-NEXT: i8 -2, label [[IF]]
229+ ; CHECK-NEXT: i8 -1, label [[IF]]
230+ ; CHECK-NEXT: ]
231+ ; CHECK: common.ret:
232+ ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[I0:%.*]], [[IF]] ], [ [[I1:%.*]], [[ELSE]] ]
233+ ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
234+ ; CHECK: if:
235+ ; CHECK-NEXT: [[I0]] = call i32 @f(i32 0)
236+ ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
237+ ; CHECK: else:
238+ ; CHECK-NEXT: [[I1]] = call i32 @f(i32 1)
239+ ; CHECK-NEXT: br label [[COMMON_RET]]
240+ ;
241+ switch i8 %arg , label %else [
242+ i8 0 , label %if
243+ i8 -3 , label %if
244+ i8 -2 , label %if
245+ i8 -1 , label %if
246+ ]
247+
248+ if:
249+ %i0 = call i32 @f (i32 0 )
250+ ret i32 %i0
251+
252+ else:
253+ %i1 = call i32 @f (i32 1 )
254+ ret i32 %i1
255+ }
256+
257+ define i32 @no_continuous_wrapping_range (i8 %arg ) {
258+ ; CHECK-LABEL: @no_continuous_wrapping_range(
259+ ; CHECK-NEXT: switch i8 [[ARG:%.*]], label [[ELSE:%.*]] [
260+ ; CHECK-NEXT: i8 0, label [[IF:%.*]]
261+ ; CHECK-NEXT: i8 -3, label [[IF]]
262+ ; CHECK-NEXT: i8 -1, label [[IF]]
263+ ; CHECK-NEXT: ]
264+ ; CHECK: common.ret:
265+ ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[I0:%.*]], [[IF]] ], [ [[I1:%.*]], [[ELSE]] ]
266+ ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
267+ ; CHECK: if:
268+ ; CHECK-NEXT: [[I0]] = call i32 @f(i32 0)
269+ ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
270+ ; CHECK: else:
271+ ; CHECK-NEXT: [[I1]] = call i32 @f(i32 1)
272+ ; CHECK-NEXT: br label [[COMMON_RET]]
273+ ;
274+ switch i8 %arg , label %else [
275+ i8 0 , label %if
276+ i8 -3 , label %if
277+ i8 -1 , label %if
278+ ]
279+
280+ if:
281+ %i0 = call i32 @f (i32 0 )
282+ ret i32 %i0
283+
284+ else:
285+ %i1 = call i32 @f (i32 1 )
286+ ret i32 %i1
287+ }
288+
191289declare void @bar (ptr nonnull dereferenceable (4 ))
0 commit comments