Use the llvm-upgrade program to upgrade llvm assembly.
[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 | not grep 'or '
13
14 int %test1(int %X, int %Y) {
15         %A = and int %X, 7
16         %B = and int %Y, 8
17         %C = or int %A, %B
18         %D = and int %C, 7  ;; This cannot include any bits from %Y!
19         ret int %D
20 }
21
22 int %test2(int %X, ubyte %Y) {
23         %B = cast ubyte %Y to int
24         %C = or int %X, %B
25         %D = and int %C, 65536  ;; This cannot include any bits from %Y!
26         ret int %D
27 }
28
29 int %test3(int %X, int %Y) {
30         %B = shl int %Y, ubyte 1
31         %C = or int %X, %B
32         %D = and int %C, 1  ;; This cannot include any bits from %Y!
33         ret int %D
34 }
35
36 uint %test4(uint %X, uint %Y) {
37         %B = shr uint %Y, ubyte 31
38         %C = or uint %X, %B
39         %D = and uint %C, 2  ;; This cannot include any bits from %Y!
40         ret uint %D
41 }
42
43 int %or_test1(int %X, int %Y) {
44         %A = and int %X, 1
45         %B = or int %A, 1     ;; This cannot include any bits from X!
46         ret int %B
47 }
48
49 ubyte %or_test2(ubyte %X, ubyte %Y) {
50         %A = shl ubyte %X, ubyte 7
51         %B = or ubyte %A, 128     ;; This cannot include any bits from X!
52         ret ubyte %B
53 }
54