1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define void @idom_sign_bit_check_edge_dominates(i64 %a) {
5 ; CHECK-LABEL: @idom_sign_bit_check_edge_dominates(
7 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[A:%.*]], 0
8 ; CHECK-NEXT: br i1 [[CMP]], label [[LAND_LHS_TRUE:%.*]], label [[LOR_RHS:%.*]]
9 ; CHECK: land.lhs.true:
10 ; CHECK-NEXT: br label [[LOR_END:%.*]]
12 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i64 [[A]], 0
13 ; CHECK-NEXT: br i1 [[CMP2]], label [[LOR_END]], label [[LAND_RHS:%.*]]
15 ; CHECK-NEXT: br label [[LOR_END]]
17 ; CHECK-NEXT: ret void
20 %cmp = icmp slt i64 %a, 0
21 br i1 %cmp, label %land.lhs.true, label %lor.rhs
27 %cmp2 = icmp sgt i64 %a, 0
28 br i1 %cmp2, label %land.rhs, label %lor.end
37 define void @idom_sign_bit_check_edge_not_dominates(i64 %a) {
38 ; CHECK-LABEL: @idom_sign_bit_check_edge_not_dominates(
40 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[A:%.*]], 0
41 ; CHECK-NEXT: br i1 [[CMP]], label [[LAND_LHS_TRUE:%.*]], label [[LOR_RHS:%.*]]
42 ; CHECK: land.lhs.true:
43 ; CHECK-NEXT: br i1 undef, label [[LOR_END:%.*]], label [[LOR_RHS]]
45 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i64 [[A]], 0
46 ; CHECK-NEXT: br i1 [[CMP2]], label [[LAND_RHS:%.*]], label [[LOR_END]]
48 ; CHECK-NEXT: br label [[LOR_END]]
50 ; CHECK-NEXT: ret void
53 %cmp = icmp slt i64 %a, 0
54 br i1 %cmp, label %land.lhs.true, label %lor.rhs
57 br i1 undef, label %lor.end, label %lor.rhs
60 %cmp2 = icmp sgt i64 %a, 0
61 br i1 %cmp2, label %land.rhs, label %lor.end
70 ; TODO: cmp3 could be reduced to A != B, but we miss that
71 ; while avoiding an infinite loop with min/max canonicalization.
73 define void @idom_sign_bit_check_edge_dominates_select(i64 %a, i64 %b) {
74 ; CHECK-LABEL: @idom_sign_bit_check_edge_dominates_select(
76 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[A:%.*]], 5
77 ; CHECK-NEXT: br i1 [[CMP]], label [[LAND_LHS_TRUE:%.*]], label [[LOR_RHS:%.*]]
78 ; CHECK: land.lhs.true:
79 ; CHECK-NEXT: br label [[LOR_END:%.*]]
81 ; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i64 [[A]], 5
82 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP2]], i64 [[A]], i64 5
83 ; CHECK-NEXT: [[CMP3_NOT:%.*]] = icmp eq i64 [[SELECT]], [[B:%.*]]
84 ; CHECK-NEXT: br i1 [[CMP3_NOT]], label [[LOR_END]], label [[LAND_RHS:%.*]]
86 ; CHECK-NEXT: br label [[LOR_END]]
88 ; CHECK-NEXT: ret void
91 %cmp = icmp slt i64 %a, 5
92 br i1 %cmp, label %land.lhs.true, label %lor.rhs
98 %cmp2 = icmp sgt i64 %a, 5
99 %select = select i1 %cmp2, i64 %a, i64 5
100 %cmp3 = icmp ne i64 %select, %b
101 br i1 %cmp3, label %land.rhs, label %lor.end
110 define void @idom_zbranch(i64 %a) {
111 ; CHECK-LABEL: @idom_zbranch(
113 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[A:%.*]], 0
114 ; CHECK-NEXT: br i1 [[CMP]], label [[LOR_END:%.*]], label [[LOR_RHS:%.*]]
116 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[A]], 0
117 ; CHECK-NEXT: br i1 [[CMP2]], label [[LAND_RHS:%.*]], label [[LOR_END]]
119 ; CHECK-NEXT: br label [[LOR_END]]
121 ; CHECK-NEXT: ret void
124 %cmp = icmp sgt i64 %a, 0
125 br i1 %cmp, label %lor.end, label %lor.rhs
128 %cmp2 = icmp slt i64 %a, 0
129 br i1 %cmp2, label %land.rhs, label %lor.end
138 ; TODO: cmp2 could be reduced to A != B, but we miss that
139 ; while avoiding an infinite loop with min/max canonicalization.
141 define void @idom_not_zbranch(i32 %a, i32 %b) {
142 ; CHECK-LABEL: @idom_not_zbranch(
144 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], 0
145 ; CHECK-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END:%.*]]
147 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[A]], 0
148 ; CHECK-NEXT: [[A_:%.*]] = select i1 [[CMP1]], i32 [[A]], i32 0
149 ; CHECK-NEXT: [[CMP2_NOT:%.*]] = icmp eq i32 [[A_]], [[B:%.*]]
150 ; CHECK-NEXT: br i1 [[CMP2_NOT]], label [[RETURN]], label [[IF_THEN3:%.*]]
152 ; CHECK-NEXT: br label [[RETURN]]
154 ; CHECK-NEXT: ret void
157 %cmp = icmp sgt i32 %a, 0
158 br i1 %cmp, label %return, label %if.end
161 %cmp1 = icmp slt i32 %a, 0
162 %a. = select i1 %cmp1, i32 %a, i32 0
163 %cmp2 = icmp ne i32 %a., %b
164 br i1 %cmp2, label %if.then3, label %return
173 define void @trueblock_cmp_eq(i32 %a, i32 %b) {
174 ; CHECK-LABEL: @trueblock_cmp_eq(
176 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], 0
177 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[RETURN:%.*]]
179 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A]], 1
180 ; CHECK-NEXT: br i1 [[CMP1]], label [[IF_THEN3:%.*]], label [[RETURN]]
182 ; CHECK-NEXT: br label [[RETURN]]
184 ; CHECK-NEXT: ret void
187 %cmp = icmp sgt i32 %a, 0
188 br i1 %cmp, label %if.end, label %return
191 %cmp1 = icmp slt i32 %a, 2
192 br i1 %cmp1, label %if.then3, label %return
201 define i1 @trueblock_cmp_is_false(i32 %x, i32 %y) {
202 ; CHECK-LABEL: @trueblock_cmp_is_false(
204 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
205 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
207 ; CHECK-NEXT: ret i1 false
209 ; CHECK-NEXT: ret i1 [[CMP]]
212 %cmp = icmp sgt i32 %x, %y
213 br i1 %cmp, label %t, label %f
215 %cmp2 = icmp slt i32 %x, %y
221 define i1 @trueblock_cmp_is_false_commute(i32 %x, i32 %y) {
222 ; CHECK-LABEL: @trueblock_cmp_is_false_commute(
224 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
225 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
227 ; CHECK-NEXT: ret i1 false
229 ; CHECK-NEXT: ret i1 [[CMP]]
232 %cmp = icmp eq i32 %x, %y
233 br i1 %cmp, label %t, label %f
235 %cmp2 = icmp sgt i32 %y, %x
241 define i1 @trueblock_cmp_is_true(i32 %x, i32 %y) {
242 ; CHECK-LABEL: @trueblock_cmp_is_true(
244 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
245 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
247 ; CHECK-NEXT: ret i1 true
249 ; CHECK-NEXT: ret i1 [[CMP]]
252 %cmp = icmp ult i32 %x, %y
253 br i1 %cmp, label %t, label %f
255 %cmp2 = icmp ne i32 %x, %y
261 define i1 @trueblock_cmp_is_true_commute(i32 %x, i32 %y) {
262 ; CHECK-LABEL: @trueblock_cmp_is_true_commute(
264 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
265 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
267 ; CHECK-NEXT: ret i1 true
269 ; CHECK-NEXT: ret i1 [[CMP]]
272 %cmp = icmp ugt i32 %x, %y
273 br i1 %cmp, label %t, label %f
275 %cmp2 = icmp ne i32 %y, %x
281 define i1 @falseblock_cmp_is_false(i32 %x, i32 %y) {
282 ; CHECK-LABEL: @falseblock_cmp_is_false(
284 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]
285 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
287 ; CHECK-NEXT: ret i1 [[CMP]]
289 ; CHECK-NEXT: ret i1 false
292 %cmp = icmp sle i32 %x, %y
293 br i1 %cmp, label %t, label %f
297 %cmp2 = icmp slt i32 %x, %y
301 define i1 @falseblock_cmp_is_false_commute(i32 %x, i32 %y) {
302 ; CHECK-LABEL: @falseblock_cmp_is_false_commute(
304 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]]
305 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
307 ; CHECK-NEXT: ret i1 [[CMP]]
309 ; CHECK-NEXT: ret i1 false
312 %cmp = icmp eq i32 %x, %y
313 br i1 %cmp, label %t, label %f
317 %cmp2 = icmp eq i32 %y, %x
321 define i1 @falseblock_cmp_is_true(i32 %x, i32 %y) {
322 ; CHECK-LABEL: @falseblock_cmp_is_true(
324 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
325 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
327 ; CHECK-NEXT: ret i1 [[CMP]]
329 ; CHECK-NEXT: ret i1 true
332 %cmp = icmp ult i32 %x, %y
333 br i1 %cmp, label %t, label %f
337 %cmp2 = icmp uge i32 %x, %y
341 define i1 @falseblock_cmp_is_true_commute(i32 %x, i32 %y) {
342 ; CHECK-LABEL: @falseblock_cmp_is_true_commute(
344 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
345 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]]
347 ; CHECK-NEXT: ret i1 [[CMP]]
349 ; CHECK-NEXT: ret i1 true
352 %cmp = icmp sgt i32 %x, %y
353 br i1 %cmp, label %t, label %f
357 %cmp2 = icmp sge i32 %y, %x
361 ; This used to infinite loop because of a conflict
362 ; with min/max canonicalization.
364 define i32 @PR48900(i32 %i, i1* %p) {
365 ; CHECK-LABEL: @PR48900(
366 ; CHECK-NEXT: [[MAXCMP:%.*]] = icmp ugt i32 [[I:%.*]], 1
367 ; CHECK-NEXT: [[UMAX:%.*]] = select i1 [[MAXCMP]], i32 [[I]], i32 1
368 ; CHECK-NEXT: [[I4:%.*]] = icmp sgt i32 [[UMAX]], 0
369 ; CHECK-NEXT: br i1 [[I4]], label [[TRUELABEL:%.*]], label [[FALSELABEL:%.*]]
371 ; CHECK-NEXT: [[MINCMP:%.*]] = icmp ult i32 [[UMAX]], 2
372 ; CHECK-NEXT: [[SMIN:%.*]] = select i1 [[MINCMP]], i32 [[UMAX]], i32 2
373 ; CHECK-NEXT: ret i32 [[SMIN]]
375 ; CHECK-NEXT: ret i32 0
377 %maxcmp = icmp ugt i32 %i, 1
378 %umax = select i1 %maxcmp, i32 %i, i32 1
379 %i4 = icmp sgt i32 %umax, 0
380 br i1 %i4, label %truelabel, label %falselabel
383 %mincmp = icmp ult i32 %umax, 2
384 %smin = select i1 %mincmp, i32 %umax, i32 2
391 ; This used to infinite loop because of a conflict
392 ; with min/max canonicalization.
394 define i8 @PR48900_alt(i8 %i, i1* %p) {
395 ; CHECK-LABEL: @PR48900_alt(
396 ; CHECK-NEXT: [[MAXCMP:%.*]] = icmp sgt i8 [[I:%.*]], -127
397 ; CHECK-NEXT: [[SMAX:%.*]] = select i1 [[MAXCMP]], i8 [[I]], i8 -127
398 ; CHECK-NEXT: [[I4:%.*]] = icmp ugt i8 [[SMAX]], -128
399 ; CHECK-NEXT: br i1 [[I4]], label [[TRUELABEL:%.*]], label [[FALSELABEL:%.*]]
401 ; CHECK-NEXT: [[MINCMP:%.*]] = icmp slt i8 [[SMAX]], -126
402 ; CHECK-NEXT: [[UMIN:%.*]] = select i1 [[MINCMP]], i8 [[SMAX]], i8 -126
403 ; CHECK-NEXT: ret i8 [[UMIN]]
405 ; CHECK-NEXT: ret i8 0
407 %maxcmp = icmp sgt i8 %i, -127
408 %smax = select i1 %maxcmp, i8 %i, i8 -127
409 %i4 = icmp ugt i8 %smax, 128
410 br i1 %i4, label %truelabel, label %falselabel
413 %mincmp = icmp slt i8 %smax, -126
414 %umin = select i1 %mincmp, i8 %smax, i8 -126