1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -simplifycfg -S | FileCheck %s
3
4; s >= t, s != t, s <= t
5define void @foo1(i32 %s, i32 %t) {
6; CHECK-LABEL: @foo1(
7; CHECK-NEXT:  entry:
8; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[S:%.*]], [[T:%.*]]
9; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]]
10; CHECK:       if.then:
11; CHECK-NEXT:    call void @bar1(i32 [[S]], i32 [[T]])
12; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i32 [[S]], [[T]]
13; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]]
14; CHECK:       if.then2:
15; CHECK-NEXT:    call void @bar2(i32 [[S]], i32 [[T]])
16; CHECK-NEXT:    [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]]
17; CHECK-NEXT:    br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]]
18; CHECK:       if.then4:
19; CHECK-NEXT:    call void @bar3(i32 [[S]], i32 [[T]])
20; CHECK-NEXT:    br label [[IF_END6]]
21; CHECK:       if.end6:
22; CHECK-NEXT:    ret void
23;
24entry:
25  %cmp = icmp sge i32 %s, %t
26  br i1 %cmp, label %if.then, label %if.end6
27
28if.then:
29  call void @bar1(i32 %s, i32 %t)
30  %cmp1 = icmp ne i32 %s, %t
31  br i1 %cmp1, label %if.then2, label %if.end6
32
33if.then2:
34  call void @bar2(i32 %s, i32 %t)
35  %cmp3 = icmp sle i32 %s, %t
36  br i1 %cmp3, label %if.then4, label %if.end6
37
38if.then4:
39  call void @bar3(i32 %s, i32 %t)
40  br label %if.end6
41
42if.end6:
43  ret void
44}
45
46; s != t, s >= t, s <= t
47define void @foo11(i32 %s, i32 %t) {
48; CHECK-LABEL: @foo11(
49; CHECK-NEXT:  entry:
50; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[S:%.*]], [[T:%.*]]
51; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]]
52; CHECK:       if.then:
53; CHECK-NEXT:    call void @bar1(i32 [[S]], i32 [[T]])
54; CHECK-NEXT:    [[CMP1:%.*]] = icmp sge i32 [[S]], [[T]]
55; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]]
56; CHECK:       if.then2:
57; CHECK-NEXT:    call void @bar2(i32 [[S]], i32 [[T]])
58; CHECK-NEXT:    [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]]
59; CHECK-NEXT:    br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]]
60; CHECK:       if.then4:
61; CHECK-NEXT:    call void @bar3(i32 [[S]], i32 [[T]])
62; CHECK-NEXT:    br label [[IF_END6]]
63; CHECK:       if.end6:
64; CHECK-NEXT:    ret void
65;
66entry:
67  %cmp = icmp ne i32 %s, %t
68  br i1 %cmp, label %if.then, label %if.end6
69
70if.then:
71  call void @bar1(i32 %s, i32 %t)
72  %cmp1 = icmp sge i32 %s, %t
73  br i1 %cmp1, label %if.then2, label %if.end6
74
75if.then2:
76  call void @bar2(i32 %s, i32 %t)
77  %cmp3 = icmp sle i32 %s, %t
78  br i1 %cmp3, label %if.then4, label %if.end6
79
80if.then4:
81  call void @bar3(i32 %s, i32 %t)
82  br label %if.end6
83
84if.end6:
85  ret void
86}
87
88; s >= t, t != s, s <= t
89define void @foo2(i32 %s, i32 %t) {
90; CHECK-LABEL: @foo2(
91; CHECK-NEXT:  entry:
92; CHECK-NEXT:    [[CMP:%.*]] = icmp sge i32 [[S:%.*]], [[T:%.*]]
93; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]]
94; CHECK:       if.then:
95; CHECK-NEXT:    call void @bar1(i32 [[S]], i32 [[T]])
96; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i32 [[T]], [[S]]
97; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]]
98; CHECK:       if.then2:
99; CHECK-NEXT:    call void @bar2(i32 [[S]], i32 [[T]])
100; CHECK-NEXT:    [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]]
101; CHECK-NEXT:    br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]]
102; CHECK:       if.then4:
103; CHECK-NEXT:    call void @bar3(i32 [[S]], i32 [[T]])
104; CHECK-NEXT:    br label [[IF_END6]]
105; CHECK:       if.end6:
106; CHECK-NEXT:    ret void
107;
108entry:
109  %cmp = icmp sge i32 %s, %t
110  br i1 %cmp, label %if.then, label %if.end6
111
112if.then:
113  call void @bar1(i32 %s, i32 %t)
114  %cmp1 = icmp ne i32 %t, %s
115  br i1 %cmp1, label %if.then2, label %if.end6
116
117if.then2:
118  call void @bar2(i32 %s, i32 %t)
119  %cmp3 = icmp sle i32 %s, %t
120  br i1 %cmp3, label %if.then4, label %if.end6
121
122if.then4:
123  call void @bar3(i32 %s, i32 %t)
124  br label %if.end6
125
126if.end6:
127  ret void
128}
129
130; s != t, t <= s, s <= t
131define void @foo21(i32 %s, i32 %t) {
132; CHECK-LABEL: @foo21(
133; CHECK-NEXT:  entry:
134; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[S:%.*]], [[T:%.*]]
135; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]]
136; CHECK:       if.then:
137; CHECK-NEXT:    call void @bar1(i32 [[S]], i32 [[T]])
138; CHECK-NEXT:    [[CMP1:%.*]] = icmp sle i32 [[T]], [[S]]
139; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]]
140; CHECK:       if.then2:
141; CHECK-NEXT:    call void @bar2(i32 [[S]], i32 [[T]])
142; CHECK-NEXT:    [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]]
143; CHECK-NEXT:    br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]]
144; CHECK:       if.then4:
145; CHECK-NEXT:    call void @bar3(i32 [[S]], i32 [[T]])
146; CHECK-NEXT:    br label [[IF_END6]]
147; CHECK:       if.end6:
148; CHECK-NEXT:    ret void
149;
150entry:
151  %cmp = icmp ne i32 %s, %t
152  br i1 %cmp, label %if.then, label %if.end6
153
154if.then:
155  call void @bar1(i32 %s, i32 %t)
156  %cmp1 = icmp sle i32 %t, %s
157  br i1 %cmp1, label %if.then2, label %if.end6
158
159if.then2:
160  call void @bar2(i32 %s, i32 %t)
161  %cmp3 = icmp sle i32 %s, %t
162  br i1 %cmp3, label %if.then4, label %if.end6
163
164if.then4:
165  call void @bar3(i32 %s, i32 %t)
166  br label %if.end6
167
168if.end6:
169  ret void
170}
171
172; t <= s, t != s, s <= t
173define void @foo3(i32 %s, i32 %t) {
174; CHECK-LABEL: @foo3(
175; CHECK-NEXT:  entry:
176; CHECK-NEXT:    [[CMP:%.*]] = icmp sle i32 [[T:%.*]], [[S:%.*]]
177; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]]
178; CHECK:       if.then:
179; CHECK-NEXT:    call void @bar1(i32 [[S]], i32 [[T]])
180; CHECK-NEXT:    [[CMP1:%.*]] = icmp ne i32 [[T]], [[S]]
181; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]]
182; CHECK:       if.then2:
183; CHECK-NEXT:    call void @bar2(i32 [[S]], i32 [[T]])
184; CHECK-NEXT:    [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]]
185; CHECK-NEXT:    br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]]
186; CHECK:       if.then4:
187; CHECK-NEXT:    call void @bar3(i32 [[S]], i32 [[T]])
188; CHECK-NEXT:    br label [[IF_END6]]
189; CHECK:       if.end6:
190; CHECK-NEXT:    ret void
191;
192entry:
193  %cmp = icmp sle i32 %t, %s
194  br i1 %cmp, label %if.then, label %if.end6
195
196if.then:
197  call void @bar1(i32 %s, i32 %t)
198  %cmp1 = icmp ne i32 %t, %s
199  br i1 %cmp1, label %if.then2, label %if.end6
200
201if.then2:
202  call void @bar2(i32 %s, i32 %t)
203  %cmp3 = icmp sle i32 %s, %t
204  br i1 %cmp3, label %if.then4, label %if.end6
205
206if.then4:
207  call void @bar3(i32 %s, i32 %t)
208  br label %if.end6
209
210if.end6:
211  ret void
212}
213
214; t != s, t <= s, s <= t
215define void @foo31(i32 %s, i32 %t) {
216; CHECK-LABEL: @foo31(
217; CHECK-NEXT:  entry:
218; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[T:%.*]], [[S:%.*]]
219; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END6:%.*]]
220; CHECK:       if.then:
221; CHECK-NEXT:    call void @bar1(i32 [[S]], i32 [[T]])
222; CHECK-NEXT:    [[CMP1:%.*]] = icmp sle i32 [[T]], [[S]]
223; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN2:%.*]], label [[IF_END6]]
224; CHECK:       if.then2:
225; CHECK-NEXT:    call void @bar2(i32 [[S]], i32 [[T]])
226; CHECK-NEXT:    [[CMP3:%.*]] = icmp sle i32 [[S]], [[T]]
227; CHECK-NEXT:    br i1 [[CMP3]], label [[IF_THEN4:%.*]], label [[IF_END6]]
228; CHECK:       if.then4:
229; CHECK-NEXT:    call void @bar3(i32 [[S]], i32 [[T]])
230; CHECK-NEXT:    br label [[IF_END6]]
231; CHECK:       if.end6:
232; CHECK-NEXT:    ret void
233;
234entry:
235  %cmp = icmp ne i32 %t, %s
236  br i1 %cmp, label %if.then, label %if.end6
237
238if.then:
239  call void @bar1(i32 %s, i32 %t)
240  %cmp1 = icmp sle i32 %t, %s
241  br i1 %cmp1, label %if.then2, label %if.end6
242
243if.then2:
244  call void @bar2(i32 %s, i32 %t)
245  %cmp3 = icmp sle i32 %s, %t
246  br i1 %cmp3, label %if.then4, label %if.end6
247
248if.then4:
249  call void @bar3(i32 %s, i32 %t)
250  br label %if.end6
251
252if.end6:
253  ret void
254}
255
256declare void @bar1(i32, i32)
257declare void @bar2(i32, i32)
258declare void @bar3(i32, i32)
259
260