1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>),loop-mssa(simple-loop-unswitch<nontrivial>),verify<loops>' -S < %s | FileCheck %s
4 ; Below bugs have caused endless unswitch.
6 ; https://bugs.llvm.org/show_bug.cgi?id=50279
7 ; https://bugs.llvm.org/show_bug.cgi?id=50302
9 ; This test's loop should be unswitched only one time even though we run
10 ; SimpleLoopUnswitch pass two times.
12 @a = dso_local local_unnamed_addr global i32 0, align 4
13 @c = dso_local local_unnamed_addr global i32 0, align 4
14 @b = dso_local local_unnamed_addr global i8 0, align 1
16 ; Function Attrs: nofree norecurse nosync nounwind uwtable
17 define dso_local void @d() {
20 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
22 ; CHECK-NEXT: br i1 false, label [[FOR_END:%.*]], label [[FOR_COND]]
24 ; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr null, align 2
25 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i16 [[TMP0]], 0
26 ; CHECK-NEXT: br i1 [[TMP1]], label [[FOR_END_SPLIT:%.*]], label [[FOR_END_SPLIT_US:%.*]]
27 ; CHECK: for.end.split.us:
28 ; CHECK-NEXT: br label [[G_US:%.*]]
30 ; CHECK-NEXT: br label [[G_SPLIT_US6:%.*]]
31 ; CHECK: for.cond1.us1:
32 ; CHECK-NEXT: [[TMP2:%.*]] = load i16, ptr null, align 2
33 ; CHECK-NEXT: [[TOBOOL4_NOT_US:%.*]] = icmp eq i16 [[TMP2]], 0
34 ; CHECK-NEXT: br i1 [[TOBOOL4_NOT_US]], label [[FOR_COND5_PREHEADER_US4:%.*]], label [[G_LOOPEXIT_US:%.*]]
35 ; CHECK: for.cond5.us2:
36 ; CHECK-NEXT: br i1 false, label [[FOR_COND1_LOOPEXIT_US5:%.*]], label [[FOR_INC_US3:%.*]]
38 ; CHECK-NEXT: store i8 0, ptr @b, align 1
39 ; CHECK-NEXT: br label [[FOR_COND5_US2:%.*]]
40 ; CHECK: for.cond5.preheader.us4:
41 ; CHECK-NEXT: br label [[FOR_COND5_US2]]
42 ; CHECK: for.cond1.loopexit.us5:
43 ; CHECK-NEXT: br label [[FOR_COND1_US1:%.*]], !llvm.loop [[LOOP0:![0-9]+]]
44 ; CHECK: g.loopexit.us:
45 ; CHECK-NEXT: br label [[G_US]]
47 ; CHECK-NEXT: br label [[FOR_COND1_US1]]
48 ; CHECK: for.end.split:
49 ; CHECK-NEXT: br label [[G:%.*]]
51 ; CHECK-NEXT: br label [[G]], !llvm.loop [[LOOP2:![0-9]+]]
53 ; CHECK-NEXT: [[TMP3:%.*]] = load i16, ptr null, align 2
54 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i16 [[TMP3]], 0
55 ; CHECK-NEXT: br i1 [[TMP4]], label [[G_SPLIT_US:%.*]], label [[G_SPLIT:%.*]]
57 ; CHECK-NEXT: br label [[FOR_COND1_US:%.*]]
58 ; CHECK: for.cond1.us:
59 ; CHECK-NEXT: br label [[FOR_COND5_PREHEADER_US:%.*]]
60 ; CHECK: for.cond5.us:
61 ; CHECK-NEXT: br i1 false, label [[FOR_COND1_LOOPEXIT_US:%.*]], label [[FOR_INC_US:%.*]]
63 ; CHECK-NEXT: store i8 0, ptr @b, align 1
64 ; CHECK-NEXT: br label [[FOR_COND5_US:%.*]]
65 ; CHECK: for.cond5.preheader.us:
66 ; CHECK-NEXT: br label [[FOR_COND5_US]]
67 ; CHECK: for.cond1.loopexit.us:
68 ; CHECK-NEXT: br label [[FOR_COND1_US]]
70 ; CHECK-NEXT: br label [[FOR_COND1:%.*]]
71 ; CHECK: for.cond1.loopexit:
72 ; CHECK-NEXT: br label [[FOR_COND1]], !llvm.loop [[LOOP0]]
74 ; CHECK-NEXT: [[TMP5:%.*]] = load i16, ptr null, align 2
75 ; CHECK-NEXT: [[TOBOOL4_NOT:%.*]] = icmp eq i16 [[TMP5]], 0
76 ; CHECK-NEXT: br i1 [[TOBOOL4_NOT]], label [[FOR_COND5_PREHEADER:%.*]], label [[G_LOOPEXIT:%.*]]
77 ; CHECK: for.cond5.preheader:
78 ; CHECK-NEXT: br label [[FOR_COND5:%.*]]
80 ; CHECK-NEXT: br i1 false, label [[FOR_COND1_LOOPEXIT:%.*]], label [[FOR_INC:%.*]]
82 ; CHECK-NEXT: store i8 0, ptr @b, align 1
83 ; CHECK-NEXT: br label [[FOR_COND5]]
88 for.cond: ; preds = %for.cond, %entry
89 br i1 false, label %for.end, label %for.cond
91 for.end: ; preds = %for.cond
94 g: ; preds = %for.cond1, %for.end
97 for.cond1: ; preds = %for.cond5, %g
98 %0 = load i16, ptr null, align 2
99 %tobool4.not = icmp eq i16 %0, 0
100 br i1 %tobool4.not, label %for.cond5, label %g
102 for.cond5: ; preds = %for.inc, %for.cond1
103 br i1 false, label %for.cond1, label %for.inc
105 for.inc: ; preds = %for.cond5
106 store i8 0, ptr @b, align 1