Skip to content

Commit 245501d

Browse files
committed
[InstCombine] Pre-commit tests (NFC)
1 parent b247776 commit 245501d

File tree

1 file changed

+231
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+231
-0
lines changed

llvm/test/Transforms/InstCombine/lshr.ll

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ define <2 x i8> @lshr_exact_splat_vec(<2 x i8> %x) {
163163
ret <2 x i8> %lshr
164164
}
165165

166+
define <2 x i8> @lshr_exact_splat_vec_nuw(<2 x i8> %x) {
167+
; CHECK-LABEL: @lshr_exact_splat_vec_nuw(
168+
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i8> [[X:%.*]], <i8 1, i8 1>
169+
; CHECK-NEXT: [[LSHR:%.*]] = and <2 x i8> [[TMP1]], <i8 63, i8 63>
170+
; CHECK-NEXT: ret <2 x i8> [[LSHR]]
171+
;
172+
%shl = shl nuw <2 x i8> %x, <i8 2, i8 2>
173+
%add = add nuw <2 x i8> %shl, <i8 4, i8 4>
174+
%lshr = lshr <2 x i8> %add, <i8 2, i8 2>
175+
ret <2 x i8> %lshr
176+
}
177+
166178
define i8 @shl_add(i8 %x, i8 %y) {
167179
; CHECK-LABEL: @shl_add(
168180
; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[Y:%.*]], 2
@@ -360,8 +372,212 @@ define <3 x i14> @mul_splat_fold_vec(<3 x i14> %x) {
360372
ret <3 x i14> %t
361373
}
362374

375+
define i32 @shl_add_lshr_flag_preservation(i32 %x, i32 %c, i32 %y) {
376+
; CHECK-LABEL: @shl_add_lshr_flag_preservation(
377+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
378+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Y:%.*]]
379+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[ADD]], [[C]]
380+
; CHECK-NEXT: ret i32 [[LSHR]]
381+
;
382+
%shl = shl nuw i32 %x, %c
383+
%add = add nuw nsw i32 %shl, %y
384+
%lshr = lshr exact i32 %add, %c
385+
ret i32 %lshr
386+
}
387+
388+
define i32 @shl_add_lshr(i32 %x, i32 %c, i32 %y) {
389+
; CHECK-LABEL: @shl_add_lshr(
390+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
391+
; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[SHL]], [[Y:%.*]]
392+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[ADD]], [[C]]
393+
; CHECK-NEXT: ret i32 [[LSHR]]
394+
;
395+
%shl = shl nuw i32 %x, %c
396+
%add = add nuw i32 %shl, %y
397+
%lshr = lshr i32 %add, %c
398+
ret i32 %lshr
399+
}
400+
401+
define i32 @shl_add_lshr_comm(i32 %x, i32 %c, i32 %y) {
402+
; CHECK-LABEL: @shl_add_lshr_comm(
403+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
404+
; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[SHL]], [[Y:%.*]]
405+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[ADD]], [[C]]
406+
; CHECK-NEXT: ret i32 [[LSHR]]
407+
;
408+
%shl = shl nuw i32 %x, %c
409+
%add = add nuw i32 %y, %shl
410+
%lshr = lshr i32 %add, %c
411+
ret i32 %lshr
412+
}
413+
414+
; Negative test
415+
416+
define i32 @shl_add_lshr_no_nuw(i32 %x, i32 %c, i32 %y) {
417+
; CHECK-LABEL: @shl_add_lshr_no_nuw(
418+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
419+
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SHL]], [[Y:%.*]]
420+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[ADD]], [[C]]
421+
; CHECK-NEXT: ret i32 [[LSHR]]
422+
;
423+
%shl = shl nuw i32 %x, %c
424+
%add = add i32 %shl, %y
425+
%lshr = lshr i32 %add, %c
426+
ret i32 %lshr
427+
}
428+
429+
; Negative test
430+
431+
define i32 @shl_sub_lshr_not_exact(i32 %x, i32 %c, i32 %y) {
432+
; CHECK-LABEL: @shl_sub_lshr_not_exact(
433+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
434+
; CHECK-NEXT: [[SUB:%.*]] = sub nuw i32 [[SHL]], [[Y:%.*]]
435+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[SUB]], [[C]]
436+
; CHECK-NEXT: ret i32 [[LSHR]]
437+
;
438+
%shl = shl nuw i32 %x, %c
439+
%sub = sub nuw i32 %shl, %y
440+
%lshr = lshr i32 %sub, %c
441+
ret i32 %lshr
442+
}
443+
444+
; Negative test
445+
446+
define i32 @shl_sub_lshr_no_nuw(i32 %x, i32 %c, i32 %y) {
447+
; CHECK-LABEL: @shl_sub_lshr_no_nuw(
448+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i32 [[X:%.*]], [[C:%.*]]
449+
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[SHL]], [[Y:%.*]]
450+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
451+
; CHECK-NEXT: ret i32 [[LSHR]]
452+
;
453+
%shl = shl nsw i32 %x, %c
454+
%sub = sub nsw i32 %shl, %y
455+
%lshr = lshr exact i32 %sub, %c
456+
ret i32 %lshr
457+
}
458+
459+
define i32 @shl_sub_lshr(i32 %x, i32 %c, i32 %y) {
460+
; CHECK-LABEL: @shl_sub_lshr(
461+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
462+
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[SHL]], [[Y:%.*]]
463+
; CHECK-NEXT: [[LSHR:%.*]] = lshr exact i32 [[SUB]], [[C]]
464+
; CHECK-NEXT: ret i32 [[LSHR]]
465+
;
466+
%shl = shl nuw i32 %x, %c
467+
%sub = sub nuw nsw i32 %shl, %y
468+
%lshr = lshr exact i32 %sub, %c
469+
ret i32 %lshr
470+
}
471+
472+
define i32 @shl_or_lshr(i32 %x, i32 %c, i32 %y) {
473+
; CHECK-LABEL: @shl_or_lshr(
474+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
475+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], [[Y:%.*]]
476+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[OR]], [[C]]
477+
; CHECK-NEXT: ret i32 [[LSHR]]
478+
;
479+
%shl = shl nuw i32 %x, %c
480+
%or = or i32 %shl, %y
481+
%lshr = lshr i32 %or, %c
482+
ret i32 %lshr
483+
}
484+
485+
define i32 @shl_or_disjoint_lshr(i32 %x, i32 %c, i32 %y) {
486+
; CHECK-LABEL: @shl_or_disjoint_lshr(
487+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
488+
; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], [[Y:%.*]]
489+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[OR]], [[C]]
490+
; CHECK-NEXT: ret i32 [[LSHR]]
491+
;
492+
%shl = shl nuw i32 %x, %c
493+
%or = or disjoint i32 %shl, %y
494+
%lshr = lshr i32 %or, %c
495+
ret i32 %lshr
496+
}
497+
498+
define i32 @shl_or_lshr_comm(i32 %x, i32 %c, i32 %y) {
499+
; CHECK-LABEL: @shl_or_lshr_comm(
500+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
501+
; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], [[Y:%.*]]
502+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[OR]], [[C]]
503+
; CHECK-NEXT: ret i32 [[LSHR]]
504+
;
505+
%shl = shl nuw i32 %x, %c
506+
%or = or i32 %y, %shl
507+
%lshr = lshr i32 %or, %c
508+
ret i32 %lshr
509+
}
510+
511+
define i32 @shl_or_disjoint_lshr_comm(i32 %x, i32 %c, i32 %y) {
512+
; CHECK-LABEL: @shl_or_disjoint_lshr_comm(
513+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
514+
; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], [[Y:%.*]]
515+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[OR]], [[C]]
516+
; CHECK-NEXT: ret i32 [[LSHR]]
517+
;
518+
%shl = shl nuw i32 %x, %c
519+
%or = or disjoint i32 %y, %shl
520+
%lshr = lshr i32 %or, %c
521+
ret i32 %lshr
522+
}
523+
524+
define i32 @shl_xor_lshr(i32 %x, i32 %c, i32 %y) {
525+
; CHECK-LABEL: @shl_xor_lshr(
526+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
527+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[SHL]], [[Y:%.*]]
528+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[XOR]], [[C]]
529+
; CHECK-NEXT: ret i32 [[LSHR]]
530+
;
531+
%shl = shl nuw i32 %x, %c
532+
%xor = xor i32 %shl, %y
533+
%lshr = lshr i32 %xor, %c
534+
ret i32 %lshr
535+
}
536+
537+
538+
define i32 @shl_xor_lshr_comm(i32 %x, i32 %c, i32 %y) {
539+
; CHECK-LABEL: @shl_xor_lshr_comm(
540+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
541+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[SHL]], [[Y:%.*]]
542+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[XOR]], [[C]]
543+
; CHECK-NEXT: ret i32 [[LSHR]]
544+
;
545+
%shl = shl nuw i32 %x, %c
546+
%xor = xor i32 %y, %shl
547+
%lshr = lshr i32 %xor, %c
548+
ret i32 %lshr
549+
}
550+
363551
; Negative test
364552

553+
define i32 @shl_and_lshr(i32 %x, i32 %c, i32 %y) {
554+
; CHECK-LABEL: @shl_and_lshr(
555+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[C:%.*]]
556+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[Y:%.*]]
557+
; CHECK-NEXT: [[LSHR:%.*]] = lshr i32 [[AND]], [[C]]
558+
; CHECK-NEXT: ret i32 [[LSHR]]
559+
;
560+
%shl = shl nuw i32 %x, %c
561+
%and = and i32 %shl, %y
562+
%lshr = lshr i32 %and, %c
563+
ret i32 %lshr
564+
}
565+
566+
; Negative test
567+
568+
define i32 @shl_add_lshr_neg(i32 %x, i32 %y, i32 %z) {
569+
; CHECK-LABEL: @shl_add_lshr_neg(
570+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
571+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
572+
; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
573+
; CHECK-NEXT: ret i32 [[RES]]
574+
;
575+
%shl = shl nuw i32 %x, %y
576+
%add = add nuw nsw i32 %shl, %z
577+
%res = lshr exact i32 %add, %z
578+
ret i32 %res
579+
}
580+
365581
define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
366582
; CHECK-LABEL: @mul_splat_fold_wrong_mul_const(
367583
; CHECK-NEXT: [[M:%.*]] = mul nuw i32 [[X:%.*]], 65538
@@ -375,6 +591,21 @@ define i32 @mul_splat_fold_wrong_mul_const(i32 %x) {
375591

376592
; Negative test
377593

594+
define i32 @shl_add_lshr_multiuse(i32 %x, i32 %y, i32 %z) {
595+
; CHECK-LABEL: @shl_add_lshr_multiuse(
596+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[X:%.*]], [[Y:%.*]]
597+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[SHL]], [[Z:%.*]]
598+
; CHECK-NEXT: call void @use(i32 [[ADD]])
599+
; CHECK-NEXT: [[RES:%.*]] = lshr exact i32 [[ADD]], [[Z]]
600+
; CHECK-NEXT: ret i32 [[RES]]
601+
;
602+
%shl = shl nuw i32 %x, %y
603+
%add = add nuw nsw i32 %shl, %z
604+
call void @use (i32 %add)
605+
%res = lshr exact i32 %add, %z
606+
ret i32 %res
607+
}
608+
378609
define i32 @mul_splat_fold_wrong_lshr_const(i32 %x) {
379610
; CHECK-LABEL: @mul_splat_fold_wrong_lshr_const(
380611
; CHECK-NEXT: [[M:%.*]] = mul nuw i32 [[X:%.*]], 65537

0 commit comments

Comments
 (0)