1; REQUIRES: asserts
2; RUN: opt -simple-loop-unswitch -disable-output -stats -info-output-file - < %s | FileCheck --check-prefix=STATS %s
3; RUN: opt -simple-loop-unswitch -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 simple-loop-unswitch - Number of branches unswitched
12; STATS: 2 simple-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
17
18; CHECK: entry.split:
19; CHECK-NEXT: br i1 %b, label %entry.split.split, label %abort1
20
21; CHECK: entry.split.split:
22; CHECK-NEXT: br label %for.body
23
24; CHECK: for.body:
25; CHECK-NEXT: br label %cond.end
26
27; CHECK: cond.end:
28; CHECK-NEXT: br label %for.body
29
30; CHECK: abort0:
31; CHECK-NEXT: call void @end0() [[NOR_NUW:#[0-9]+]]
32; CHECK-NEXT: unreachable
33
34; CHECK: abort1:
35; CHECK-NEXT: call void @end1() [[NOR_NUW]]
36; CHECK-NEXT: unreachable
37
38; CHECK: }
39
40define void @func_16(i1 %a, i1 %b) nounwind {
41entry:
42  br label %for.body
43
44for.body:
45  br i1 %a, label %cond.end, label %abort0
46
47cond.end:
48  br i1 %b, label %for.body, label %abort1
49
50abort0:
51  call void @end0() noreturn nounwind
52  unreachable
53
54abort1:
55  call void @end1() noreturn nounwind
56  unreachable
57}
58
59declare void @end0() noreturn
60declare void @end1() noreturn
61
62; CHECK: attributes #0 = { nounwind }
63; CHECK: attributes #1 = { noreturn }
64; CHECK: attributes [[NOR_NUW]] = { noreturn nounwind }
65