Add test case for testing InstCombine with arbitrary precision integer
[oota-llvm.git] / test / Transforms / InstCombine / apint-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 ; This tests arbitrary precision integers.
13
14 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep 'or '
15
16 define i17 @test1(i17 %X, i17 %Y) {
17         %A = and i17 %X, 7
18         %B = and i17 %Y, 8
19         %C = or i17 %A, %B
20         %D = and i17 %C, 7  ;; This cannot include any bits from %Y!
21         ret i17 %D
22 }
23
24 define i49 @test3(i49 %X, i49 %Y) {
25         %B = shl i49 %Y, 1
26         %C = or i49 %X, %B
27         %D = and i49 %C, 1  ;; This cannot include any bits from %Y!
28         ret i49 %D
29 }
30
31 define i67 @test4(i67 %X, i67 %Y) {
32         %B = lshr i67 %Y, 66
33         %C = or i67 %X, %B
34         %D = and i67 %C, 2  ;; This cannot include any bits from %Y!
35         ret i67 %D
36 }
37
38 define i231 @or_test1(i231 %X, i231 %Y) {
39         %A = and i231 %X, 1
40         %B = or i231 %A, 1     ;; This cannot include any bits from X!
41         ret i231 %B
42 }
43
44 define i7 @or_test2(i7 %X, i7 %Y) {
45         %A = shl i7 %X, 6
46         %B = or i7 %A, 64     ;; This cannot include any bits from X!
47         ret i7 %B
48 }
49