For PR1319:
[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-upgrade %s -o - | llvm-as | opt -instcombine | llvm-dis | \
13 ; RUN:    notcast .*int
14
15 implementation   ; Functions:
16
17 bool %lt_signed_to_large_unsigned(sbyte %SB) {
18   %Y = cast sbyte %SB to uint           ; <uint> [#uses=1]
19   %C = setlt uint %Y, 1024              ; <bool> [#uses=1]
20   ret bool %C
21 }
22
23 bool %lt_signed_to_large_signed(sbyte %SB) {
24   %Y = cast sbyte %SB to int
25   %C = setlt int %Y, 1024
26   ret bool %C
27 }
28
29 bool %lt_signed_to_large_negative(sbyte %SB) {
30   %Y = cast sbyte %SB to int
31   %C = setlt int %Y, -1024
32   ret bool %C
33 }
34
35 bool %lt_signed_to_small_signed(sbyte %SB) {
36   %Y = cast sbyte %SB to int
37   %C = setlt int %Y, 17
38   ret bool %C
39 }
40
41 bool %lt_signed_to_small_negative(sbyte %SB) {
42   %Y = cast sbyte %SB to int
43   %C = setlt int %Y, -17
44   ret bool %C
45 }
46
47 bool %lt_unsigned_to_large_unsigned(ubyte %SB) {
48   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
49   %C = setlt uint %Y, 1024              ; <bool> [#uses=1]
50   ret bool %C
51 }
52
53 bool %lt_unsigned_to_large_signed(ubyte %SB) {
54   %Y = cast ubyte %SB to int
55   %C = setlt int %Y, 1024
56   ret bool %C
57 }
58
59 bool %lt_unsigned_to_large_negative(ubyte %SB) {
60   %Y = cast ubyte %SB to int
61   %C = setlt int %Y, -1024
62   ret bool %C
63 }
64
65 bool %lt_unsigned_to_small_unsigned(ubyte %SB) {
66   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
67   %C = setlt uint %Y, 17                ; <bool> [#uses=1]
68   ret bool %C
69 }
70
71 bool %lt_unsigned_to_small_negative(ubyte %SB) {
72   %Y = cast ubyte %SB to int
73   %C = setlt int %Y, -17
74   ret bool %C
75 }
76
77 bool %gt_signed_to_large_unsigned(sbyte %SB) {
78   %Y = cast sbyte %SB to uint           ; <uint> [#uses=1]
79   %C = setgt uint %Y, 1024              ; <bool> [#uses=1]
80   ret bool %C
81 }
82
83 bool %gt_signed_to_large_signed(sbyte %SB) {
84   %Y = cast sbyte %SB to int
85   %C = setgt int %Y, 1024
86   ret bool %C
87 }
88
89 bool %gt_signed_to_large_negative(sbyte %SB) {
90   %Y = cast sbyte %SB to int
91   %C = setgt int %Y, -1024
92   ret bool %C
93 }
94
95 bool %gt_signed_to_small_signed(sbyte %SB) {
96   %Y = cast sbyte %SB to int
97   %C = setgt int %Y, 17
98   ret bool %C
99 }
100
101 bool %gt_signed_to_small_negative(sbyte %SB) {
102   %Y = cast sbyte %SB to int
103   %C = setgt int %Y, -17
104   ret bool %C
105 }
106
107 bool %gt_unsigned_to_large_unsigned(ubyte %SB) {
108   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
109   %C = setgt uint %Y, 1024              ; <bool> [#uses=1]
110   ret bool %C
111 }
112
113 bool %gt_unsigned_to_large_signed(ubyte %SB) {
114   %Y = cast ubyte %SB to int
115   %C = setgt int %Y, 1024
116   ret bool %C
117 }
118
119 bool %gt_unsigned_to_large_negative(ubyte %SB) {
120   %Y = cast ubyte %SB to int
121   %C = setgt int %Y, -1024
122   ret bool %C
123 }
124
125 bool %gt_unsigned_to_small_unsigned(ubyte %SB) {
126   %Y = cast ubyte %SB to uint           ; <uint> [#uses=1]
127   %C = setgt uint %Y, 17                ; <bool> [#uses=1]
128   ret bool %C
129 }
130
131 bool %gt_unsigned_to_small_negative(ubyte %SB) {
132   %Y = cast ubyte %SB to int
133   %C = setgt int %Y, -17
134   ret bool %C
135 }