1; This test makes sure that and instructions are properly eliminated.
2; This test is for Integer BitWidth <= 64 && BitWidth % 8 != 0.
3
4; RUN: opt < %s -instcombine -S | not grep "and "
5; END.
6
7define i39 @test0(i39 %A) {
8        %B = and i39 %A, 0 ; zero result
9        ret i39 %B
10}
11
12define i47 @test1(i47 %A, i47 %B) {
13        ;; (~A & ~B) == (~(A | B)) - De Morgan's Law
14        %NotA = xor i47 %A, -1
15        %NotB = xor i47 %B, -1
16        %C1 = and i47 %NotA, %NotB
17        ret i47 %C1
18}
19
20define i15 @test2(i15 %x) {
21        %tmp.2 = and i15 %x, -1 ; noop
22        ret i15 %tmp.2
23}
24
25define i23 @test3(i23 %x) {
26        %tmp.0 = and i23 %x, 127
27        %tmp.2 = and i23 %tmp.0, 128
28        ret i23 %tmp.2
29}
30
31define i1 @test4(i37 %x) {
32        %A = and i37 %x, -2147483648
33        %B = icmp ne i37 %A, 0
34        ret i1 %B
35}
36
37define i7 @test5(i7 %A, i7* %P) {
38        %B = or i7 %A, 3
39        %C = xor i7 %B, 12
40        store i7 %C, i7* %P
41        %r = and i7 %C, 3
42        ret i7 %r
43}
44
45define i7 @test6(i7 %A, i7 %B) {
46        ;; ~(~X & Y) --> (X | ~Y)
47        %t0 = xor i7 %A, -1
48        %t1 = and i7 %t0, %B
49        %r = xor i7 %t1, -1
50        ret i7 %r
51}
52
53define i47 @test7(i47 %A) {
54        %X = ashr i47 %A, 39 ;; sign extend
55        %C1 = and i47 %X, 255
56        ret i47 %C1
57}
58