Fix InstCombine/2007-10-31-StringCrash.ll by removing an obvious
[oota-llvm.git] / test / Transforms / InstCombine / and-or-and.ll
1 ; If we have an 'and' of the result of an 'or', and one of the 'or' operands
2 ; cannot have contributed any of the resultant bits, delete the or.  This
3 ; occurs for very common C/C++ code like this:
4 ;
5 ; struct foo { int A : 16; int B : 16; };
6 ; void test(struct foo *F, int X, int Y) {
7 ;        F->A = X; F->B = Y;
8 ; }
9 ;
10 ; Which corresponds to test1.
11
12 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
13 ; RUN:   not grep {or }
14 ; END.
15
16 int %test1(int %X, int %Y) {
17         %A = and int %X, 7
18         %B = and int %Y, 8
19         %C = or int %A, %B
20         %D = and int %C, 7  ;; This cannot include any bits from %Y!
21         ret int %D
22 }
23
24 int %test2(int %X, ubyte %Y) {
25         %B = cast ubyte %Y to int
26         %C = or int %X, %B
27         %D = and int %C, 65536  ;; This cannot include any bits from %Y!
28         ret int %D
29 }
30
31 int %test3(int %X, int %Y) {
32         %B = shl int %Y, ubyte 1
33         %C = or int %X, %B
34         %D = and int %C, 1  ;; This cannot include any bits from %Y!
35         ret int %D
36 }
37
38 uint %test4(uint %X, uint %Y) {
39         %B = shr uint %Y, ubyte 31
40         %C = or uint %X, %B
41         %D = and uint %C, 2  ;; This cannot include any bits from %Y!
42         ret uint %D
43 }
44
45 int %or_test1(int %X, int %Y) {
46         %A = and int %X, 1
47         %B = or int %A, 1     ;; This cannot include any bits from X!
48         ret int %B
49 }
50
51 ubyte %or_test2(ubyte %X, ubyte %Y) {
52         %A = shl ubyte %X, ubyte 7
53         %B = or ubyte %A, 128     ;; This cannot include any bits from X!
54         ret ubyte %B
55 }
56