blob: 3d1c895edec90d1e24980bd589700a700bfe2ecf [file] [log] [blame]
Jan Wen Voung6dc30762013-03-12 16:27:52 +00001; REQUIRES: asserts
Dan Gohman0ad7d9c2010-09-01 21:46:45 +00002; 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
Chen Li145c2f52015-07-25 03:21:06 +000012; STATS: 2 loop-unswitch - Number of unswitches that are trivial
Dan Gohman0ad7d9c2010-09-01 21:46:45 +000013
Stephen Linc1c7a132013-07-14 01:42:54 +000014; CHECK-LABEL: @func_16(
Dan Gohman0ad7d9c2010-09-01 21:46:45 +000015; CHECK-NEXT: entry:
16; CHECK-NEXT: br i1 %a, label %entry.split, label %abort0.split
17
18; CHECK: entry.split:
Chen Li145c2f52015-07-25 03:21:06 +000019; CHECK-NEXT: br i1 %b, label %cond.end, label %abort1.split
Dan Gohman0ad7d9c2010-09-01 21:46:45 +000020
Chen Li145c2f52015-07-25 03:21:06 +000021; CHECK: cond.end:
22; CHECK-NEXT: br label %cond.end
Dan Gohman0ad7d9c2010-09-01 21:46:45 +000023
24; CHECK: abort0.split:
Bill Wendlinga0323742013-02-22 09:09:42 +000025; CHECK-NEXT: call void @end0() [[NOR_NUW:#[0-9]+]]
Dan Gohman0ad7d9c2010-09-01 21:46:45 +000026; CHECK-NEXT: unreachable
27
Chen Li145c2f52015-07-25 03:21:06 +000028; CHECK: abort1.split:
Bill Wendlinga0323742013-02-22 09:09:42 +000029; CHECK-NEXT: call void @end1() [[NOR_NUW]]
Dan Gohman0ad7d9c2010-09-01 21:46:45 +000030; 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
Bill Wendlinga0323742013-02-22 09:09:42 +000055
56; CHECK: attributes #0 = { nounwind }
57; CHECK: attributes #1 = { noreturn }
58; CHECK: attributes [[NOR_NUW]] = { noreturn nounwind }