new testcase
[oota-llvm.git] / test / Transforms / InstCombine / 2004-11-27-SetCCForCastLargerAndConstant.ll
1 ; This test case tests the InstructionCombining optimization that
2 ; reduces things like:
3 ;   %Y = cast sbyte %X to uint
4 ;   %C = setlt uint %Y, 1024
5 ; to
6 ;   %C = bool true
7 ; It includes test cases for different constant values, signedness of the
8 ; cast operands, and types of setCC operators. In all cases, the cast should
9 ; be eliminated. In many cases the setCC is also eliminated based on the
10 ; constant value and the range of the casted value.
11 ;
12 ; RUN: llvm-as %s -o - | opt -instcombine | llvm-dis | not grep 'cast.*int'
13
14 implementation   ; Functions:
15
16 bool %lt_signed_to_large_unsigned(sbyte %SB) {
17   %Y = cast sbyte %SB to uint           ; <uint> [#uses=1]
18   %C = setlt uint %Y, 1024              ; <bool> [#uses=1]
19   ret bool %C
20 }
21
22 bool %lt_signed_to_large_signed(sbyte %SB) {
23   %Y = cast sbyte %SB to int
24   %C = setlt int %Y, 1024
25   ret bool %C
26 }
27
28 bool %lt_signed_to_large_negative(sbyte %SB) {
29   %Y = cast sbyte %SB to int
30   %C = setlt int %Y, -1024
31   ret bool %C
32 }
33
34 bool %lt_signed_to_small_unsigned(sbyte %SB) {
35   %Y = cast sbyte %SB to uint           ; <uint> [#uses=1]
36   %C = setlt uint %Y, 17                ; <bool> [#uses=1]
37   ret bool %C
38 }
39
40 bool %lt_signed_to_small_signed(sbyte %SB) {
41   %Y = cast sbyte %SB to int
42   %C = setlt int %Y, 17
43   ret bool %C
44 }
45
46 bool %lt_signed_to_small_negative(sbyte %SB) {
47   %Y = cast sbyte %SB to int
48   %C = setlt int %Y, -17
49   ret bool %C
50 }
51
52 bool %lt_unsigned_to_large_unsigned(ubyte %SB) {
53   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
54   %C = setlt uint %Y, 1024              ; <bool> [#uses=1]
55   ret bool %C
56 }
57
58 bool %lt_unsigned_to_large_signed(ubyte %SB) {
59   %Y = cast ubyte %SB to int
60   %C = setlt int %Y, 1024
61   ret bool %C
62 }
63
64 bool %lt_unsigned_to_large_negative(ubyte %SB) {
65   %Y = cast ubyte %SB to int
66   %C = setlt int %Y, -1024
67   ret bool %C
68 }
69
70 bool %lt_unsigned_to_small_unsigned(ubyte %SB) {
71   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
72   %C = setlt uint %Y, 17                ; <bool> [#uses=1]
73   ret bool %C
74 }
75
76 bool %lt_unsigned_to_small_signed(ubyte %SB) {
77   %Y = cast ubyte %SB to int
78   %C = setlt int %Y, 17
79   ret bool %C
80 }
81
82 bool %lt_unsigned_to_small_negative(ubyte %SB) {
83   %Y = cast ubyte %SB to int
84   %C = setlt int %Y, -17
85   ret bool %C
86 }
87
88 bool %gt_signed_to_large_unsigned(sbyte %SB) {
89   %Y = cast sbyte %SB to uint           ; <uint> [#uses=1]
90   %C = setgt uint %Y, 1024              ; <bool> [#uses=1]
91   ret bool %C
92 }
93
94 bool %gt_signed_to_large_signed(sbyte %SB) {
95   %Y = cast sbyte %SB to int
96   %C = setgt int %Y, 1024
97   ret bool %C
98 }
99
100 bool %gt_signed_to_large_negative(sbyte %SB) {
101   %Y = cast sbyte %SB to int
102   %C = setgt int %Y, -1024
103   ret bool %C
104 }
105
106 bool %gt_signed_to_small_unsigned(sbyte %SB) {
107   %Y = cast sbyte %SB to uint           ; <uint> [#uses=1]
108   %C = setgt uint %Y, 17                ; <bool> [#uses=1]
109   ret bool %C
110 }
111
112 bool %gt_signed_to_small_signed(sbyte %SB) {
113   %Y = cast sbyte %SB to int
114   %C = setgt int %Y, 17
115   ret bool %C
116 }
117
118 bool %gt_signed_to_small_negative(sbyte %SB) {
119   %Y = cast sbyte %SB to int
120   %C = setgt int %Y, -17
121   ret bool %C
122 }
123
124 bool %gt_unsigned_to_large_unsigned(ubyte %SB) {
125   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
126   %C = setgt uint %Y, 1024              ; <bool> [#uses=1]
127   ret bool %C
128 }
129
130 bool %gt_unsigned_to_large_signed(ubyte %SB) {
131   %Y = cast ubyte %SB to int
132   %C = setgt int %Y, 1024
133   ret bool %C
134 }
135
136 bool %gt_unsigned_to_large_negative(ubyte %SB) {
137   %Y = cast ubyte %SB to int
138   %C = setgt int %Y, -1024
139   ret bool %C
140 }
141
142 bool %gt_unsigned_to_small_unsigned(ubyte %SB) {
143   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
144   %C = setgt uint %Y, 17                ; <bool> [#uses=1]
145   ret bool %C
146 }
147
148 bool %gt_unsigned_to_small_signed(ubyte %SB) {
149   %Y = cast ubyte %SB to int
150   %C = setgt int %Y, 17
151   ret bool %C
152 }
153
154 bool %gt_unsigned_to_small_negative(ubyte %SB) {
155   %Y = cast ubyte %SB to int
156   %C = setgt int %Y, -17
157   ret bool %C
158 }