Skip to content

Commit a9a8caf

Browse files
committed
[InstCombine] Pre-commit tests (NFC)
1 parent fefac5d commit a9a8caf

File tree

2 files changed

+148
-4
lines changed

2 files changed

+148
-4
lines changed

llvm/test/Transforms/InstCombine/ashr-lshr.ll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,51 @@ define <2 x i8> @ashr_known_pos_exact_vec(<2 x i8> %x, <2 x i8> %y) {
604604
%r = ashr exact <2 x i8> %p, %y
605605
ret <2 x i8> %r
606606
}
607+
608+
define i32 @ashr_mul_times_3_div_2(i32 %0) {
609+
; CHECK-LABEL: @ashr_mul_times_3_div_2(
610+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[TMP0:%.*]], 3
611+
; CHECK-NEXT: [[ASHR:%.*]] = ashr i32 [[MUL]], 1
612+
; CHECK-NEXT: ret i32 [[ASHR]]
613+
;
614+
%mul = mul nsw nuw i32 %0, 3
615+
%ashr = ashr i32 %mul, 1
616+
ret i32 %ashr
617+
}
618+
619+
define i32 @ashr_mul_times_3_div_2_exact(i32 %x) {
620+
; CHECK-LABEL: @ashr_mul_times_3_div_2_exact(
621+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[X:%.*]], 3
622+
; CHECK-NEXT: [[ASHR:%.*]] = ashr exact i32 [[MUL]], 1
623+
; CHECK-NEXT: ret i32 [[ASHR]]
624+
;
625+
%mul = mul nsw i32 %x, 3
626+
%ashr = ashr exact i32 %mul, 1
627+
ret i32 %ashr
628+
}
629+
630+
define i32 @mul_times_3_div_2_multiuse(i32 %x) {
631+
; CHECK-LABEL: @mul_times_3_div_2_multiuse(
632+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
633+
; CHECK-NEXT: [[RES:%.*]] = ashr i32 [[MUL]], 1
634+
; CHECK-NEXT: call void @use(i32 [[MUL]])
635+
; CHECK-NEXT: ret i32 [[RES]]
636+
;
637+
%mul = mul nuw i32 %x, 3
638+
%res = ashr i32 %mul, 1
639+
call void @use (i32 %mul)
640+
ret i32 %res
641+
}
642+
643+
define i32 @ashr_mul_times_3_div_2_exact_2(i32 %x) {
644+
; CHECK-LABEL: @ashr_mul_times_3_div_2_exact_2(
645+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
646+
; CHECK-NEXT: [[ASHR:%.*]] = ashr exact i32 [[MUL]], 1
647+
; CHECK-NEXT: ret i32 [[ASHR]]
648+
;
649+
%mul = mul nuw i32 %x, 3
650+
%ashr = ashr exact i32 %mul, 1
651+
ret i32 %ashr
652+
}
653+
654+
declare void @use(i32)

llvm/test/Transforms/InstCombine/lshr.ll

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,79 @@ define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
360360
ret <3 x i14> %t
361361
}
362362

363-
; Negative test
363+
; Negative tests
364+
365+
define i32 @mul_times_3_div_2(i32 %x) {
366+
; CHECK-LABEL: @mul_times_3_div_2(
367+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw i32 [[X:%.*]], 3
368+
; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
369+
; CHECK-NEXT: ret i32 [[RES]]
370+
;
371+
%mul = mul nsw nuw i32 %x, 3
372+
%res = lshr i32 %mul, 1
373+
ret i32 %res
374+
}
375+
376+
define i32 @shl_add_lshr(i32 %x, i32 %c, i32 %y) {
377+
; CHECK-LABEL: @shl_add_lshr(
378+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
379+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Y:%.*]]
380+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[ADD]], [[C]]
381+
; CHECK-NEXT: ret i32 [[LSHR]]
382+
;
383+
%shl = shl nuw i32 %x, %c
384+
%add = add nuw nsw i32 %shl, %y
385+
%lshr = lshr exact i32 %add, %c
386+
ret i32 %lshr
387+
}
388+
389+
define i32 @lshr_mul_times_3_div_2_nuw(i32 %0) {
390+
; CHECK-LABEL: @lshr_mul_times_3_div_2_nuw(
391+
; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP0:%.*]], 1
392+
; CHECK-NEXT: [[LSHR:%.*]] = add nuw nsw i32 [[TMP2]], [[TMP0]]
393+
; CHECK-NEXT: ret i32 [[LSHR]]
394+
;
395+
%mul = mul nuw i32 %0, 3
396+
%lshr = lshr i32 %mul, 1
397+
ret i32 %lshr
398+
}
399+
400+
define i32 @lshr_mul_times_3_div_2_nsw(i32 %0) {
401+
; CHECK-LABEL: @lshr_mul_times_3_div_2_nsw(
402+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP0:%.*]], 3
403+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
404+
; CHECK-NEXT: ret i32 [[LSHR]]
405+
;
406+
%mul = mul nsw i32 %0, 3
407+
%lshr = lshr i32 %mul, 1
408+
ret i32 %lshr
409+
}
410+
411+
; Negative tests
412+
413+
define i32 @mul_times_3_div_2_no_flag(i32 %x) {
414+
; CHECK-LABEL: @mul_times_3_div_2_no_flag(
415+
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], 3
416+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[MUL]], 1
417+
; CHECK-NEXT: ret i32 [[LSHR]]
418+
;
419+
%mul = mul i32 %x, 3
420+
%lshr = lshr i32 %mul, 1
421+
ret i32 %lshr
422+
}
423+
424+
define i32 @shl_add_lshr_neg(i32 %x, i32 %y, i32 %z) {
425+
; CHECK-LABEL: @shl_add_lshr_neg(
426+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
427+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
428+
; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
429+
; CHECK-NEXT: ret i32 [[RES]]
430+
;
431+
%shl = shl nuw i32 %x, %y
432+
%add = add nuw nsw i32 %shl, %z
433+
%res = lshr exact i32 %add, %z
434+
ret i32 %res
435+
}
364436

365437
define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
366438
; CHECK-LABEL: @mul_splat_fold_wrong_mul_const(
@@ -373,7 +445,33 @@ define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
373445
ret i32 %t
374446
}
375447

376-
; Negative test
448+
define i32 @shl_add_lshr_multiuse(i32 %x, i32 %y, i32 %z) {
449+
; CHECK-LABEL: @shl_add_lshr_multiuse(
450+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
451+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
452+
; CHECK-NEXT: call void @use(i32 [[ADD]])
453+
; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
454+
; CHECK-NEXT: ret i32 [[RES]]
455+
;
456+
%shl = shl nuw i32 %x, %y
457+
%add = add nuw nsw i32 %shl, %z
458+
call void @use (i32 %add)
459+
%res = lshr exact i32 %add, %z
460+
ret i32 %res
461+
}
462+
463+
define i32 @mul_times_3_div_2_multiuse(i32 %x) {
464+
; CHECK-LABEL: @mul_times_3_div_2_multiuse(
465+
; CHECK-NEXT: [[MUL:%.*]] = mul nuw i32 [[X:%.*]], 3
466+
; CHECK-NEXT: [[RES:%.*]] = lshr i32 [[MUL]], 1
467+
; CHECK-NEXT: call void @use(i32 [[MUL]])
468+
; CHECK-NEXT: ret i32 [[RES]]
469+
;
470+
%mul = mul nuw i32 %x, 3
471+
%res = lshr i32 %mul, 1
472+
call void @use (i32 %mul)
473+
ret i32 %res
474+
}
377475

378476
define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
379477
; CHECK-LABEL: @mul_splat_fold_wrong_lshr_const(
@@ -386,8 +484,6 @@ define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
386484
ret i32 %t
387485
}
388486

389-
; Negative test
390-
391487
define i32 @mul_splat_fold_no_nuw(i32 %x) {
392488
; CHECK-LABEL: @mul_splat_fold_no_nuw(
393489
; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[X:%.*]], 65537

0 commit comments

Comments
 (0)