Skip to content

Commit 99d7320

Browse files
committed
[InstCombine] add tests for xor-not; NFC
These tests demonstrate a missing fold that would also be needed to avoid a regression when we try to recommit rL300977. llvm-svn: 341557
1 parent 58310ec commit 99d7320

File tree

1 file changed

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

1 file changed

+72
-0
lines changed

llvm/test/Transforms/InstCombine/xor.ll

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,78 @@ define i32 @and_xor_extra_use(i32 %a, i32 %b, i32* %p) {
587587
ret i32 %r
588588
}
589589

590+
; TODO: (~X | C2) ^ C1 --> ((X & ~C2) ^ -1) ^ C1 --> (X & ~C2) ^ ~C1
591+
; The extra use (store) is here because the simpler case
592+
; may be transformed using demanded bits.
593+
594+
define i8 @xor_or_not(i8 %x, i8* %p) {
595+
; CHECK-LABEL: @xor_or_not(
596+
; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
597+
; CHECK-NEXT: store i8 [[NX]], i8* [[P:%.*]], align 1
598+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[NX]], 7
599+
; CHECK-NEXT: [[R:%.*]] = xor i8 [[OR]], 12
600+
; CHECK-NEXT: ret i8 [[R]]
601+
;
602+
%nx = xor i8 %x, -1
603+
store i8 %nx, i8* %p
604+
%or = or i8 %nx, 7
605+
%r = xor i8 %or, 12
606+
ret i8 %r
607+
}
608+
609+
; Don't do this if the 'or' has extra uses.
610+
611+
define i8 @xor_or_not_uses(i8 %x, i8* %p) {
612+
; CHECK-LABEL: @xor_or_not_uses(
613+
; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[X:%.*]], 7
614+
; CHECK-NEXT: [[OR:%.*]] = xor i8 [[TMP1]], -8
615+
; CHECK-NEXT: store i8 [[OR]], i8* [[P:%.*]], align 1
616+
; CHECK-NEXT: [[R:%.*]] = xor i8 [[TMP1]], -12
617+
; CHECK-NEXT: ret i8 [[R]]
618+
;
619+
%nx = xor i8 %x, -1
620+
%or = or i8 %nx, 7
621+
store i8 %or, i8* %p
622+
%r = xor i8 %or, 12
623+
ret i8 %r
624+
}
625+
626+
; TODO: (~X & C2) ^ C1 --> ((X | ~C2) ^ -1) ^ C1 --> (X | ~C2) ^ ~C1
627+
; The extra use (store) is here because the simpler case
628+
; may be transformed using demanded bits.
629+
630+
define i8 @xor_and_not(i8 %x, i8* %p) {
631+
; CHECK-LABEL: @xor_and_not(
632+
; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
633+
; CHECK-NEXT: store i8 [[NX]], i8* [[P:%.*]], align 1
634+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[NX]], 42
635+
; CHECK-NEXT: [[R:%.*]] = xor i8 [[AND]], 31
636+
; CHECK-NEXT: ret i8 [[R]]
637+
;
638+
%nx = xor i8 %x, -1
639+
store i8 %nx, i8* %p
640+
%and = and i8 %nx, 42
641+
%r = xor i8 %and, 31
642+
ret i8 %r
643+
}
644+
645+
; Don't do this if the 'and' has extra uses.
646+
647+
define i8 @xor_and_not_uses(i8 %x, i8* %p) {
648+
; CHECK-LABEL: @xor_and_not_uses(
649+
; CHECK-NEXT: [[NX:%.*]] = and i8 [[X:%.*]], 42
650+
; CHECK-NEXT: [[AND:%.*]] = xor i8 [[NX]], 42
651+
; CHECK-NEXT: store i8 [[AND]], i8* [[P:%.*]], align 1
652+
; CHECK-NEXT: [[R:%.*]] = xor i8 [[NX]], 53
653+
; CHECK-NEXT: ret i8 [[R]]
654+
;
655+
%nx = xor i8 %x, -1
656+
%and = and i8 %nx, 42
657+
store i8 %and, i8* %p
658+
%r = xor i8 %and, 31
659+
ret i8 %r
660+
}
661+
590662
; The tests 39-47 are related to the canonicalization:
591663
; %notx = xor i32 %x, -1
592664
; %cmp = icmp sgt i32 %notx, %y

0 commit comments

Comments
 (0)