Skip to content

Commit 3c4d222

Browse files
committed
[InstCombine] Add more tests for unreachable code (NFC)
1 parent e95134b commit 3c4d222

File tree

1 file changed

+151
-3
lines changed

1 file changed

+151
-3
lines changed

llvm/test/Transforms/InstCombine/unreachable-code.ll

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ join:
228228
ret i32 %phi
229229
}
230230

231+
define void @non_term_unreachable_following_blocks() {
232+
; CHECK-LABEL: define void @non_term_unreachable_following_blocks() {
233+
; CHECK-NEXT: call void @dummy()
234+
; CHECK-NEXT: store i1 true, ptr poison, align 1
235+
; CHECK-NEXT: br label [[SPLIT:%.*]]
236+
; CHECK: split:
237+
; CHECK-NEXT: call void @dummy()
238+
; CHECK-NEXT: br label [[LOOP:%.*]]
239+
; CHECK: loop:
240+
; CHECK-NEXT: call void @dummy()
241+
; CHECK-NEXT: br label [[LOOP]]
242+
;
243+
call void @dummy()
244+
store i1 true, ptr poison
245+
call void @dummy()
246+
br label %split
247+
248+
split:
249+
call void @dummy()
250+
br label %loop
251+
252+
loop:
253+
call void @dummy()
254+
br label %loop
255+
}
256+
231257
define void @br_not_into_loop(i1 %x) {
232258
; CHECK-LABEL: define void @br_not_into_loop
233259
; CHECK-SAME: (i1 [[X:%.*]]) {
@@ -271,6 +297,128 @@ exit:
271297
call void @dummy()
272298
ret void
273299
}
274-
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
275-
; DEFAULT_ITER: {{.*}}
276-
; MAX1: {{.*}}
300+
301+
define void @two_br_not_into_loop(i1 %x) {
302+
; DEFAULT_ITER-LABEL: define void @two_br_not_into_loop
303+
; DEFAULT_ITER-SAME: (i1 [[X:%.*]]) {
304+
; DEFAULT_ITER-NEXT: br i1 true, label [[BB2:%.*]], label [[LOOP:%.*]]
305+
; DEFAULT_ITER: bb2:
306+
; DEFAULT_ITER-NEXT: br i1 true, label [[EXIT:%.*]], label [[LOOP]]
307+
; DEFAULT_ITER: loop:
308+
; DEFAULT_ITER-NEXT: br label [[LOOP]]
309+
; DEFAULT_ITER: exit:
310+
; DEFAULT_ITER-NEXT: call void @dummy()
311+
; DEFAULT_ITER-NEXT: ret void
312+
;
313+
; MAX1-LABEL: define void @two_br_not_into_loop
314+
; MAX1-SAME: (i1 [[X:%.*]]) {
315+
; MAX1-NEXT: br i1 true, label [[BB2:%.*]], label [[LOOP:%.*]]
316+
; MAX1: bb2:
317+
; MAX1-NEXT: br i1 true, label [[EXIT:%.*]], label [[LOOP]]
318+
; MAX1: loop:
319+
; MAX1-NEXT: call void @dummy()
320+
; MAX1-NEXT: br label [[LOOP]]
321+
; MAX1: exit:
322+
; MAX1-NEXT: call void @dummy()
323+
; MAX1-NEXT: ret void
324+
;
325+
%c = or i1 %x, true
326+
br i1 %c, label %bb2, label %loop
327+
328+
bb2:
329+
%c2 = or i1 %x, true
330+
br i1 %c2, label %exit, label %loop
331+
332+
loop:
333+
call void @dummy()
334+
br label %loop
335+
336+
exit:
337+
call void @dummy()
338+
ret void
339+
}
340+
341+
define void @one_br_into_loop_one_not(i1 %x, i1 %c2) {
342+
; CHECK-LABEL: define void @one_br_into_loop_one_not
343+
; CHECK-SAME: (i1 [[X:%.*]], i1 [[C2:%.*]]) {
344+
; CHECK-NEXT: br i1 true, label [[BB2:%.*]], label [[LOOP:%.*]]
345+
; CHECK: bb2:
346+
; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[LOOP]]
347+
; CHECK: loop:
348+
; CHECK-NEXT: call void @dummy()
349+
; CHECK-NEXT: br label [[LOOP]]
350+
; CHECK: exit:
351+
; CHECK-NEXT: call void @dummy()
352+
; CHECK-NEXT: ret void
353+
;
354+
%c = or i1 %x, true
355+
br i1 %c, label %bb2, label %loop
356+
357+
bb2:
358+
br i1 %c2, label %exit, label %loop
359+
360+
loop:
361+
call void @dummy()
362+
br label %loop
363+
364+
exit:
365+
call void @dummy()
366+
ret void
367+
}
368+
369+
define void @two_br_not_into_loop_with_split(i1 %x) {
370+
; DEFAULT_ITER-LABEL: define void @two_br_not_into_loop_with_split
371+
; DEFAULT_ITER-SAME: (i1 [[X:%.*]]) {
372+
; DEFAULT_ITER-NEXT: br i1 true, label [[BB2:%.*]], label [[SPLIT1:%.*]]
373+
; DEFAULT_ITER: bb2:
374+
; DEFAULT_ITER-NEXT: br i1 true, label [[EXIT:%.*]], label [[SPLIT2:%.*]]
375+
; DEFAULT_ITER: split1:
376+
; DEFAULT_ITER-NEXT: br label [[LOOP:%.*]]
377+
; DEFAULT_ITER: split2:
378+
; DEFAULT_ITER-NEXT: br label [[LOOP]]
379+
; DEFAULT_ITER: loop:
380+
; DEFAULT_ITER-NEXT: br label [[LOOP]]
381+
; DEFAULT_ITER: exit:
382+
; DEFAULT_ITER-NEXT: call void @dummy()
383+
; DEFAULT_ITER-NEXT: ret void
384+
;
385+
; MAX1-LABEL: define void @two_br_not_into_loop_with_split
386+
; MAX1-SAME: (i1 [[X:%.*]]) {
387+
; MAX1-NEXT: br i1 true, label [[BB2:%.*]], label [[SPLIT1:%.*]]
388+
; MAX1: bb2:
389+
; MAX1-NEXT: br i1 true, label [[EXIT:%.*]], label [[SPLIT2:%.*]]
390+
; MAX1: split1:
391+
; MAX1-NEXT: br label [[LOOP:%.*]]
392+
; MAX1: split2:
393+
; MAX1-NEXT: br label [[LOOP]]
394+
; MAX1: loop:
395+
; MAX1-NEXT: call void @dummy()
396+
; MAX1-NEXT: br label [[LOOP]]
397+
; MAX1: exit:
398+
; MAX1-NEXT: call void @dummy()
399+
; MAX1-NEXT: ret void
400+
;
401+
%c = or i1 %x, true
402+
br i1 %c, label %bb2, label %split1
403+
404+
bb2:
405+
%c2 = or i1 %x, true
406+
br i1 %c2, label %exit, label %split2
407+
408+
split1:
409+
call void @dummy()
410+
br label %loop
411+
412+
split2:
413+
call void @dummy()
414+
br label %loop
415+
416+
loop:
417+
call void @dummy()
418+
br label %loop
419+
420+
exit:
421+
call void @dummy()
422+
ret void
423+
}
424+

0 commit comments

Comments
 (0)