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