1; REQUIRES: asserts
2; RUN: opt -loop-unswitch -disable-output -stats -info-output-file - < %s | FileCheck --check-prefix=STATS %s
3; RUN: opt -loop-unswitch -simplifycfg -S < %s | FileCheck %s
4; PR5373
5
6; Loop unswitching shouldn't trivially unswitch the true case of condition %a
7; in the code here because it leads to an infinite loop. While this doesn't
8; contain any instructions with side effects, it's still a kind of side effect.
9; It can trivially unswitch on the false cas of condition %a though.
10
11; STATS: 2 loop-unswitch - Number of branches unswitched
12; STATS: 1 loop-unswitch - Number of unswitches that are trivial
13
14; CHECK-LABEL: @func_16(
15; CHECK-NEXT: entry:
16; CHECK-NEXT: br i1 %a, label %entry.split, label %abort0.split
17
18; CHECK: entry.split:
19; CHECK-NEXT: br i1 %b, label %cond.end.us, label %abort1
20
21; CHECK: cond.end.us:
22; CHECK-NEXT: br label %cond.end.us
23
24; CHECK: abort0.split:
25; CHECK-NEXT: call void @end0() [[NOR_NUW:#[0-9]+]]
26; CHECK-NEXT: unreachable
27
28; CHECK: abort1:
29; CHECK-NEXT: call void @end1() [[NOR_NUW]]
30; CHECK-NEXT: unreachable
31
32; CHECK: }
33
34define void @func_16(i1 %a, i1 %b) nounwind {
35entry:
36  br label %for.body
37
38for.body:
39  br i1 %a, label %cond.end, label %abort0
40
41cond.end:
42  br i1 %b, label %for.body, label %abort1
43
44abort0:
45  call void @end0() noreturn nounwind
46  unreachable
47
48abort1:
49  call void @end1() noreturn nounwind
50  unreachable
51}
52
53declare void @end0() noreturn
54declare void @end1() noreturn
55
56; CHECK: attributes #0 = { nounwind }
57; CHECK: attributes #1 = { noreturn }
58; CHECK: attributes [[NOR_NUW]] = { noreturn nounwind }
59