blob: dc1eea1a2d08e69ecb85abd330fb873cf2ce9ccc [file] [log] [blame]
Chris Lattner584e3832005-01-01 16:14:18 +00001; 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
Reid Spencer91948d42007-04-14 20:13:02 +000012; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
13; RUN: not grep {or }
Chris Lattner584e3832005-01-01 16:14:18 +000014
15int %test1(int %X, int %Y) {
16 %A = and int %X, 7
17 %B = and int %Y, 8
18 %C = or int %A, %B
19 %D = and int %C, 7 ;; This cannot include any bits from %Y!
20 ret int %D
21}
22
23int %test2(int %X, ubyte %Y) {
24 %B = cast ubyte %Y to int
25 %C = or int %X, %B
26 %D = and int %C, 65536 ;; This cannot include any bits from %Y!
27 ret int %D
28}
29
30int %test3(int %X, int %Y) {
31 %B = shl int %Y, ubyte 1
32 %C = or int %X, %B
33 %D = and int %C, 1 ;; This cannot include any bits from %Y!
34 ret int %D
35}
36
37uint %test4(uint %X, uint %Y) {
38 %B = shr uint %Y, ubyte 31
39 %C = or uint %X, %B
40 %D = and uint %C, 2 ;; This cannot include any bits from %Y!
41 ret uint %D
42}
43
44int %or_test1(int %X, int %Y) {
45 %A = and int %X, 1
46 %B = or int %A, 1 ;; This cannot include any bits from X!
47 ret int %B
48}
49
50ubyte %or_test2(ubyte %X, ubyte %Y) {
51 %A = shl ubyte %X, ubyte 7
52 %B = or ubyte %A, 128 ;; This cannot include any bits from X!
53 ret ubyte %B
54}
55