Skip to content

Commit 160a13a

Browse files
committed
[X86] Add more tests for transform (icmp eq/ne (and X,C0),(shift X,C1)); PR71598
1 parent f112e46 commit 160a13a

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,231 @@ define <16 x i1> @shl_to_ror_eq_16xi16_s8_fail_preserve_i16(<16 x i16> %x) {
570570
ret <16 x i1> %r
571571
}
572572

573+
define i1 @shr_to_shl_eq_i32_s5_fail_doesnt_add_up(i32 %x) {
574+
; CHECK-LABEL: shr_to_shl_eq_i32_s5_fail_doesnt_add_up:
575+
; CHECK: # %bb.0:
576+
; CHECK-NEXT: movl %edi, %eax
577+
; CHECK-NEXT: andl $7, %eax
578+
; CHECK-NEXT: shrl $5, %edi
579+
; CHECK-NEXT: cmpl %edi, %eax
580+
; CHECK-NEXT: sete %al
581+
; CHECK-NEXT: retq
582+
%and = and i32 %x, 7
583+
%sh = lshr i32 %x, 5
584+
%r = icmp eq i32 %and, %sh
585+
ret i1 %r
586+
}
587+
588+
define i1 @shr_to_shl_eq_i8_s5_fail_doesnt_add_up2(i32 %x) {
589+
; CHECK-LABEL: shr_to_shl_eq_i8_s5_fail_doesnt_add_up2:
590+
; CHECK: # %bb.0:
591+
; CHECK-NEXT: movl %edi, %eax
592+
; CHECK-NEXT: andl $268435455, %eax # imm = 0xFFFFFFF
593+
; CHECK-NEXT: shrl $5, %edi
594+
; CHECK-NEXT: cmpl %edi, %eax
595+
; CHECK-NEXT: sete %al
596+
; CHECK-NEXT: retq
597+
%and = and i32 %x, 268435455
598+
%sh = lshr i32 %x, 5
599+
%r = icmp eq i32 %and, %sh
600+
ret i1 %r
601+
}
602+
603+
define i1 @shr_to_shl_eq_i8_s5_fail_doesnt_add_up3(i32 %x) {
604+
; CHECK-LABEL: shr_to_shl_eq_i8_s5_fail_doesnt_add_up3:
605+
; CHECK: # %bb.0:
606+
; CHECK-NEXT: movl %edi, %eax
607+
; CHECK-NEXT: andl $67108863, %eax # imm = 0x3FFFFFF
608+
; CHECK-NEXT: shrl $5, %edi
609+
; CHECK-NEXT: cmpl %edi, %eax
610+
; CHECK-NEXT: sete %al
611+
; CHECK-NEXT: retq
612+
%and = and i32 %x, 67108863
613+
%sh = lshr i32 %x, 5
614+
%r = icmp eq i32 %and, %sh
615+
ret i1 %r
616+
}
617+
618+
define i1 @shr_to_shl_eq_i8_s5_fail_doesnt_not_mask(i32 %x) {
619+
; CHECK-LABEL: shr_to_shl_eq_i8_s5_fail_doesnt_not_mask:
620+
; CHECK: # %bb.0:
621+
; CHECK-NEXT: movl %edi, %eax
622+
; CHECK-NEXT: andl $11, %eax
623+
; CHECK-NEXT: shrl $5, %edi
624+
; CHECK-NEXT: cmpl %edi, %eax
625+
; CHECK-NEXT: sete %al
626+
; CHECK-NEXT: retq
627+
%and = and i32 %x, 11
628+
%sh = lshr i32 %x, 5
629+
%r = icmp eq i32 %and, %sh
630+
ret i1 %r
631+
}
632+
633+
define i1 @shl_to_shr_eq_i32_s9_fail_wrong_mask(i32 %x) {
634+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_wrong_mask:
635+
; CHECK: # %bb.0:
636+
; CHECK-NEXT: movl %edi, %eax
637+
; CHECK-NEXT: andl $511, %eax # imm = 0x1FF
638+
; CHECK-NEXT: shll $9, %edi
639+
; CHECK-NEXT: cmpl %edi, %eax
640+
; CHECK-NEXT: sete %al
641+
; CHECK-NEXT: retq
642+
%and = and i32 %x, 511
643+
%sh = shl i32 %x, 9
644+
%r = icmp eq i32 %and, %sh
645+
ret i1 %r
646+
}
647+
648+
define i1 @shr_to_shl_eq_i32_s5_fail_wrong_mask(i32 %x) {
649+
; CHECK-LABEL: shr_to_shl_eq_i32_s5_fail_wrong_mask:
650+
; CHECK: # %bb.0:
651+
; CHECK-NEXT: movl %edi, %eax
652+
; CHECK-NEXT: andl $-32, %eax
653+
; CHECK-NEXT: shrl $5, %edi
654+
; CHECK-NEXT: cmpl %edi, %eax
655+
; CHECK-NEXT: sete %al
656+
; CHECK-NEXT: retq
657+
%and = and i32 %x, -32
658+
%sh = lshr i32 %x, 5
659+
%r = icmp eq i32 %and, %sh
660+
ret i1 %r
661+
}
662+
663+
define i1 @shl_to_shr_eq_i32_s9_fail_doesnt_add_up(i32 %x) {
664+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_doesnt_add_up:
665+
; CHECK: # %bb.0:
666+
; CHECK-NEXT: movl %edi, %eax
667+
; CHECK-NEXT: andl $65024, %eax # imm = 0xFE00
668+
; CHECK-NEXT: shll $9, %edi
669+
; CHECK-NEXT: cmpl %edi, %eax
670+
; CHECK-NEXT: sete %al
671+
; CHECK-NEXT: retq
672+
%and = and i32 %x, 65024
673+
%sh = shl i32 %x, 9
674+
%r = icmp eq i32 %and, %sh
675+
ret i1 %r
676+
}
677+
678+
define i1 @shl_to_shr_eq_i32_s9_fail_doesnt_add_up2(i32 %x) {
679+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_doesnt_add_up2:
680+
; CHECK: # %bb.0:
681+
; CHECK-NEXT: movl %edi, %eax
682+
; CHECK-NEXT: andl $-1024, %eax # imm = 0xFC00
683+
; CHECK-NEXT: shll $9, %edi
684+
; CHECK-NEXT: cmpl %edi, %eax
685+
; CHECK-NEXT: sete %al
686+
; CHECK-NEXT: retq
687+
%and = and i32 %x, -1024
688+
%sh = shl i32 %x, 9
689+
%r = icmp eq i32 %and, %sh
690+
ret i1 %r
691+
}
692+
693+
define i1 @shl_to_shr_eq_i32_s9_fail_doesnt_add_up3(i32 %x) {
694+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_doesnt_add_up3:
695+
; CHECK: # %bb.0:
696+
; CHECK-NEXT: movl %edi, %eax
697+
; CHECK-NEXT: andl $-256, %eax
698+
; CHECK-NEXT: shll $9, %edi
699+
; CHECK-NEXT: cmpl %edi, %eax
700+
; CHECK-NEXT: sete %al
701+
; CHECK-NEXT: retq
702+
%and = and i32 %x, -256
703+
%sh = shl i32 %x, 9
704+
%r = icmp eq i32 %and, %sh
705+
ret i1 %r
706+
}
707+
708+
define i1 @shl_to_shr_eq_i32_s9_fail_not_mask(i32 %x) {
709+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_not_mask:
710+
; CHECK: # %bb.0:
711+
; CHECK-NEXT: movl %edi, %eax
712+
; CHECK-NEXT: andl $-511, %eax # imm = 0xFE01
713+
; CHECK-NEXT: shll $9, %edi
714+
; CHECK-NEXT: cmpl %edi, %eax
715+
; CHECK-NEXT: sete %al
716+
; CHECK-NEXT: retq
717+
%and = and i32 %x, -511
718+
%sh = shl i32 %x, 9
719+
%r = icmp eq i32 %and, %sh
720+
ret i1 %r
721+
}
722+
723+
define i1 @shl_to_shr_eq_i32_s9_fail_not_mask2(i32 %x) {
724+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_not_mask2:
725+
; CHECK: # %bb.0:
726+
; CHECK-NEXT: movl %edi, %eax
727+
; CHECK-NEXT: andl $-255, %eax
728+
; CHECK-NEXT: shll $9, %edi
729+
; CHECK-NEXT: cmpl %edi, %eax
730+
; CHECK-NEXT: sete %al
731+
; CHECK-NEXT: retq
732+
%and = and i32 %x, -255
733+
%sh = shl i32 %x, 9
734+
%r = icmp eq i32 %and, %sh
735+
ret i1 %r
736+
}
737+
738+
define i1 @shl_to_shr_eq_i32_s9_fail_wrong_mask2(i32 %x) {
739+
; CHECK-LABEL: shl_to_shr_eq_i32_s9_fail_wrong_mask2:
740+
; CHECK: # %bb.0:
741+
; CHECK-NEXT: movl %edi, %eax
742+
; CHECK-NEXT: andl $8388607, %eax # imm = 0x7FFFFF
743+
; CHECK-NEXT: shll $9, %edi
744+
; CHECK-NEXT: cmpl %edi, %eax
745+
; CHECK-NEXT: sete %al
746+
; CHECK-NEXT: retq
747+
%and = and i32 %x, 8388607
748+
%sh = shl i32 %x, 9
749+
%r = icmp eq i32 %and, %sh
750+
ret i1 %r
751+
}
752+
753+
define i1 @shl_to_shr_eq_i32_s9(i32 %x) {
754+
; CHECK-LABEL: shl_to_shr_eq_i32_s9:
755+
; CHECK: # %bb.0:
756+
; CHECK-NEXT: movl %edi, %eax
757+
; CHECK-NEXT: andl $-512, %eax # imm = 0xFE00
758+
; CHECK-NEXT: shll $9, %edi
759+
; CHECK-NEXT: cmpl %edi, %eax
760+
; CHECK-NEXT: sete %al
761+
; CHECK-NEXT: retq
762+
%and = and i32 %x, -512
763+
%sh = shl i32 %x, 9
764+
%r = icmp eq i32 %and, %sh
765+
ret i1 %r
766+
}
767+
768+
define i1 @shr_to_shl_eq_i32_s5(i32 %x) {
769+
; CHECK-LABEL: shr_to_shl_eq_i32_s5:
770+
; CHECK: # %bb.0:
771+
; CHECK-NEXT: movl %edi, %eax
772+
; CHECK-NEXT: andl $134217727, %eax # imm = 0x7FFFFFF
773+
; CHECK-NEXT: shrl $5, %edi
774+
; CHECK-NEXT: cmpl %edi, %eax
775+
; CHECK-NEXT: sete %al
776+
; CHECK-NEXT: retq
777+
%and = and i32 %x, 134217727
778+
%sh = lshr i32 %x, 5
779+
%r = icmp eq i32 %and, %sh
780+
ret i1 %r
781+
}
782+
783+
define i1 @shr_to_rotate_eq_i32_s5(i32 %x) {
784+
; CHECK-LABEL: shr_to_rotate_eq_i32_s5:
785+
; CHECK: # %bb.0:
786+
; CHECK-NEXT: movl %edi, %eax
787+
; CHECK-NEXT: andl $268435455, %eax # imm = 0xFFFFFFF
788+
; CHECK-NEXT: shrl $4, %edi
789+
; CHECK-NEXT: cmpl %edi, %eax
790+
; CHECK-NEXT: sete %al
791+
; CHECK-NEXT: retq
792+
%and = and i32 %x, 268435455
793+
%sh = lshr i32 %x, 4
794+
%r = icmp eq i32 %and, %sh
795+
ret i1 %r
796+
}
797+
573798
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
574799
; CHECK-AVX: {{.*}}
575800
; CHECK-NOBMI-SSE2: {{.*}}

0 commit comments

Comments
 (0)