Add some more testcases for things to get optimized away
[oota-llvm.git] / test / Transforms / InstCombine / cast.ll
1 ; Tests to make sure elimination of casts is working correctly
2
3 ; RUN: if as < %s | opt -instcombine -die | dis | grep '%c' | grep cast
4 ; RUN: then exit 1
5 ; RUN: else exit 0
6 ; RUN: fi
7
8 implementation
9
10 int %test1(int %A) {
11         %c1 = cast int %A to uint
12         %c2 = cast uint %c1 to int
13         ret int %c2
14 }
15
16 ulong %test2(ubyte %A) {
17         %c1 = cast ubyte %A to ushort
18         %c2 = cast ushort %c1 to uint
19         %Ret = cast uint %c2 to ulong
20         ret ulong %Ret
21 }
22
23 ulong %test3(ulong %A) {    ; This function should just use bitwise AND
24         %c1 = cast ulong %A to ubyte
25         %c2 = cast ubyte %c1 to ulong
26         ret ulong %c2
27 }
28
29 uint %test4(int %A, int %B) {
30         %COND = setlt int %A, %B
31         %c = cast bool %COND to ubyte     ; Booleans are unsigned integrals
32         %result = cast ubyte %c to uint   ; for the cast elim purpose
33         ret uint %result
34 }
35
36 int %test5(bool %B) {
37         %c = cast bool %B to ubyte       ; This cast should get folded into
38         %result = cast ubyte %c to int   ; this cast
39         ret int %result
40 }
41
42 int %test6(ulong %A) {
43         %c1 = cast ulong %A to uint
44         %res = cast uint %c1 to int
45         ret int %res
46 }
47
48 long %test7(bool %A) {
49         %c1 = cast bool %A to int
50         %res = cast int %c1 to long
51         ret long %res
52 }
53
54 long %test8(sbyte %A) {
55         %c1 = cast sbyte %A to ulong
56         %res = cast ulong %c1 to long
57         ret long %res
58 }
59
60 short %test9(short %A) {
61         %c1 = cast short %A to int
62         %c2 = cast int %c1 to short
63         ret short %c2
64 }
65
66 short %test10(short %A) {
67         %c1 = cast short %A to uint
68         %c2 = cast uint %c1 to short
69         ret short %c2
70 }