1 ; Tests to make sure elimination of casts is working correctly
2 ; RUN: llvm-as < %s | opt -instcombine -disable-output &&
3 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep '%c' | notcast
5 %inbuf = external global [32832 x ubyte]
10 %c1 = cast int %A to uint
11 %c2 = cast uint %c1 to int
15 ulong %test2(ubyte %A) {
16 %c1 = cast ubyte %A to ushort
17 %c2 = cast ushort %c1 to uint
18 %Ret = cast uint %c2 to ulong
22 ulong %test3(ulong %A) { ; This function should just use bitwise AND
23 %c1 = cast ulong %A to ubyte
24 %c2 = cast ubyte %c1 to ulong
28 uint %test4(int %A, int %B) {
29 %COND = setlt int %A, %B
30 %c = cast bool %COND to ubyte ; Booleans are unsigned integrals
31 %result = cast ubyte %c to uint ; for the cast elim purpose
36 %c = cast bool %B to ubyte ; This cast should get folded into
37 %result = cast ubyte %c to int ; this cast
41 int %test6(ulong %A) {
42 %c1 = cast ulong %A to uint
43 %res = cast uint %c1 to int
47 long %test7(bool %A) {
48 %c1 = cast bool %A to int
49 %res = cast int %c1 to long
53 long %test8(sbyte %A) {
54 %c1 = cast sbyte %A to ulong
55 %res = cast ulong %c1 to long
59 short %test9(short %A) {
60 %c1 = cast short %A to int
61 %c2 = cast int %c1 to short
65 short %test10(short %A) {
66 %c1 = cast short %A to uint
67 %c2 = cast uint %c1 to short
71 declare void %varargs(int, ...)
73 void %test11(int* %P) {
74 %c = cast int* %P to short*
75 call void(int, ...)* %varargs(int 5, short* %c)
80 %p = malloc [4 x sbyte]
81 %c = cast [4 x sbyte]* %p to int*
85 ubyte *%test13(long %A) {
86 %c = getelementptr [0 x ubyte]* cast ([32832 x ubyte]* %inbuf to [0 x ubyte]*), long 0, long %A
90 bool %test14(sbyte %A) {
91 %c = cast sbyte %A to ubyte
92 %X = setlt ubyte %c, 128 ; setge %A, 0
96 bool %test15(ubyte %A) {
97 %c = cast ubyte %A to sbyte
98 %X = setlt sbyte %c, 0 ; setgt %A, 127
102 bool %test16(int* %P) {
103 %c = cast int* %P to bool ;; setne P, null
107 short %test17(bool %tmp3) {
108 %c = cast bool %tmp3 to int
109 %t86 = cast int %c to short
113 short %test18(sbyte %tmp3) {
114 %c = cast sbyte %tmp3 to int
115 %t86 = cast int %c to short
119 bool %test19(int %X) {
120 %c = cast int %X to long
121 %Z = setlt long %c, 12345
125 bool %test20(bool %B) {
126 %c = cast bool %B to int
127 %D = setlt int %c, -1
131 uint %test21(uint %X) {
132 %c1 = cast uint %X to sbyte
133 %c2 = cast sbyte %c1 to uint ;; sext -> zext -> and -> nop
134 %RV = and uint %c2, 255
138 uint %test22(uint %X) {
139 %c1 = cast uint %X to sbyte
140 %c2 = cast sbyte %c1 to uint ;; sext -> zext -> and -> nop
141 %RV = shl uint %c2, ubyte 24
145 int %test23(int %X) {
146 %c1 = cast int %X to ushort ;; Turn into an AND even though X
147 %c2 = cast ushort %c1 to int ;; and Z are signed.
151 bool %test24(bool %C) {
152 %X = select bool %C, uint 14, uint 1234
153 %c = cast uint %X to bool ;; Fold cast into select
157 void %test25(int** %P) {
158 %c = cast int** %P to float**
159 store float* null, float** %c ;; Fold cast into null
163 int %test26(float %F) {
164 %c = cast float %F to double ;; no need to cast from float->double.
165 %D = cast double %c to int
169 [4 x float]* %test27([9 x [4 x float]]* %A) {
170 %c = cast [9 x [4 x float]]* %A to [4 x float]*
174 float* %test28([4 x float]* %A) {
175 %c = cast [4 x float]* %A to float*
179 uint %test29(uint %c1, uint %c2) {
180 %tmp1 = cast uint %c1 to ubyte
181 %tmp4.mask = cast uint %c2 to ubyte
182 %tmp = or ubyte %tmp4.mask, %tmp1
183 %tmp10 = cast ubyte %tmp to uint
187 uint %test30(uint %c1) {
188 %c2 = cast uint %c1 to ubyte
189 %c3 = xor ubyte %c2, 1
190 %c4 = cast ubyte %c3 to uint
194 bool %test31(ulong %A) {
195 %B = cast ulong %A to int
197 %D = seteq int %C, 10
202 void %test32(double** %tmp) {
203 %tmp8 = malloc [16 x sbyte]
204 %tmp8 = cast [16 x sbyte]* %tmp8 to double*
205 store double* %tmp8, double** %tmp
209 uint %test33(uint %c1) {
210 %x = bitcast uint %c1 to float
211 %y = bitcast float %x to uint
215 ushort %test34(ushort %a) {
216 %c1 = zext ushort %a to int
217 %tmp21 = lshr int %c1, ubyte 8
218 %c2 = trunc int %tmp21 to ushort
222 ushort %test35(ushort %a) {
223 %c1 = bitcast ushort %a to short
224 %tmp2 = lshr short %c1, ubyte 8
225 %c2 = bitcast short %tmp2 to ushort