1 ; Tests to make sure elimination of casts is working correctly
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
3 ; RUN: grep %c | notcast
6 %inbuf = external global [32832 x ubyte]
11 %c1 = cast int %A to uint
12 %c2 = cast uint %c1 to int
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
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
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
37 %c = cast bool %B to ubyte ; This cast should get folded into
38 %result = cast ubyte %c to int ; this cast
42 int %test6(ulong %A) {
43 %c1 = cast ulong %A to uint
44 %res = cast uint %c1 to int
48 long %test7(bool %A) {
49 %c1 = cast bool %A to int
50 %res = cast int %c1 to long
54 long %test8(sbyte %A) {
55 %c1 = cast sbyte %A to ulong
56 %res = cast ulong %c1 to long
60 short %test9(short %A) {
61 %c1 = cast short %A to int
62 %c2 = cast int %c1 to short
66 short %test10(short %A) {
67 %c1 = cast short %A to uint
68 %c2 = cast uint %c1 to short
72 declare void %varargs(int, ...)
74 void %test11(int* %P) {
75 %c = cast int* %P to short*
76 call void(int, ...)* %varargs(int 5, short* %c)
81 %p = malloc [4 x sbyte]
82 %c = cast [4 x sbyte]* %p to int*
86 ubyte *%test13(long %A) {
87 %c = getelementptr [0 x ubyte]* cast ([32832 x ubyte]* %inbuf to [0 x ubyte]*), long 0, long %A
91 bool %test14(sbyte %A) {
92 %c = cast sbyte %A to ubyte
93 %X = setlt ubyte %c, 128 ; setge %A, 0
97 ; This just won't occur when there's no difference between ubyte and sbyte
98 ;bool %test15(ubyte %A) {
99 ; %c = cast ubyte %A to sbyte
100 ; %X = setlt sbyte %c, 0 ; setgt %A, 127
104 bool %test16(int* %P) {
105 %c = cast int* %P to bool ;; setne P, null
109 short %test17(bool %tmp3) {
110 %c = cast bool %tmp3 to int
111 %t86 = cast int %c to short
115 short %test18(sbyte %tmp3) {
116 %c = cast sbyte %tmp3 to int
117 %t86 = cast int %c to short
121 bool %test19(int %X) {
122 %c = cast int %X to long
123 %Z = setlt long %c, 12345
127 bool %test20(bool %B) {
128 %c = cast bool %B to int
129 %D = setlt int %c, -1
133 uint %test21(uint %X) {
134 %c1 = cast uint %X to sbyte
135 %c2 = cast sbyte %c1 to uint ;; sext -> zext -> and -> nop
136 %RV = and uint %c2, 255
140 uint %test22(uint %X) {
141 %c1 = cast uint %X to sbyte
142 %c2 = cast sbyte %c1 to uint ;; sext -> zext -> and -> nop
143 %RV = shl uint %c2, ubyte 24
147 int %test23(int %X) {
148 %c1 = cast int %X to ushort ;; Turn into an AND even though X
149 %c2 = cast ushort %c1 to int ;; and Z are signed.
153 bool %test24(bool %C) {
154 %X = select bool %C, uint 14, uint 1234
155 %c = cast uint %X to bool ;; Fold cast into select
159 void %test25(int** %P) {
160 %c = cast int** %P to float**
161 store float* null, float** %c ;; Fold cast into null
165 int %test26(float %F) {
166 %c = cast float %F to double ;; no need to cast from float->double.
167 %D = cast double %c to int
171 [4 x float]* %test27([9 x [4 x float]]* %A) {
172 %c = cast [9 x [4 x float]]* %A to [4 x float]*
176 float* %test28([4 x float]* %A) {
177 %c = cast [4 x float]* %A to float*
181 uint %test29(uint %c1, uint %c2) {
182 %tmp1 = cast uint %c1 to ubyte
183 %tmp4.mask = cast uint %c2 to ubyte
184 %tmp = or ubyte %tmp4.mask, %tmp1
185 %tmp10 = cast ubyte %tmp to uint
189 uint %test30(uint %c1) {
190 %c2 = cast uint %c1 to ubyte
191 %c3 = xor ubyte %c2, 1
192 %c4 = cast ubyte %c3 to uint
196 bool %test31(ulong %A) {
197 %B = cast ulong %A to int
199 %D = seteq int %C, 10
204 void %test32(double** %tmp) {
205 %tmp8 = malloc [16 x sbyte]
206 %tmp8 = cast [16 x sbyte]* %tmp8 to double*
207 store double* %tmp8, double** %tmp
211 uint %test33(uint %c1) {
212 %x = bitcast uint %c1 to float
213 %y = bitcast float %x to uint
217 ushort %test34(ushort %a) {
218 %c1 = zext ushort %a to int
219 %tmp21 = lshr int %c1, ubyte 8
220 %c2 = trunc int %tmp21 to ushort
224 ushort %test35(ushort %a) {
225 %c1 = bitcast ushort %a to short
226 %tmp2 = lshr short %c1, ubyte 8
227 %c2 = bitcast short %tmp2 to ushort