Fix integer cast code to handle vector types.
[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 = sext i8 %X to i32 
4 ;   %C = icmp ult i32 %Y, 1024
5 ; to
6 ;   %C = i1 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: opt < %s -instcombine -S | FileCheck %s
13 ; END.
14 define i1 @lt_signed_to_large_unsigned(i8 %SB) {
15         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
16         %C = icmp ult i32 %Y, 1024              ; <i1> [#uses=1]
17         ret i1 %C
18 ; CHECK: %C1 = icmp sgt i8 %SB, -1
19 ; CHECK: ret i1 %C1
20 }
21
22 define i1 @lt_signed_to_large_signed(i8 %SB) {
23         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
24         %C = icmp slt i32 %Y, 1024              ; <i1> [#uses=1]
25         ret i1 %C
26 ; CHECK: ret i1 true
27 }
28
29 define i1 @lt_signed_to_large_negative(i8 %SB) {
30         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
31         %C = icmp slt i32 %Y, -1024             ; <i1> [#uses=1]
32         ret i1 %C
33 ; CHECK: ret i1 false
34 }
35
36 define i1 @lt_signed_to_small_signed(i8 %SB) {
37         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
38         %C = icmp slt i32 %Y, 17                ; <i1> [#uses=1]
39         ret i1 %C
40 ; CHECK: %C = icmp slt i8 %SB, 17
41 ; CHECK: ret i1 %C
42 }
43 define i1 @lt_signed_to_small_negative(i8 %SB) {
44         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
45         %C = icmp slt i32 %Y, -17               ; <i1> [#uses=1]
46         ret i1 %C
47 ; CHECK: %C = icmp slt i8 %SB, -17
48 ; CHECK: ret i1 %C
49 }
50
51 define i1 @lt_unsigned_to_large_unsigned(i8 %SB) {
52         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
53         %C = icmp ult i32 %Y, 1024              ; <i1> [#uses=1]
54         ret i1 %C
55 ; CHECK: ret i1 true
56 }
57
58 define i1 @lt_unsigned_to_large_signed(i8 %SB) {
59         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
60         %C = icmp slt i32 %Y, 1024              ; <i1> [#uses=1]
61         ret i1 %C
62 ; CHECK: ret i1 true
63 }
64
65 define i1 @lt_unsigned_to_large_negative(i8 %SB) {
66         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
67         %C = icmp slt i32 %Y, -1024             ; <i1> [#uses=1]
68         ret i1 %C
69 ; CHECK: ret i1 false
70 }
71
72 define i1 @lt_unsigned_to_small_unsigned(i8 %SB) {
73         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
74         %C = icmp ult i32 %Y, 17                ; <i1> [#uses=1]
75         ret i1 %C
76 ; CHECK: %C = icmp ult i8 %SB, 17
77 ; CHECK: ret i1 %C
78 }
79
80 define i1 @lt_unsigned_to_small_negative(i8 %SB) {
81         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
82         %C = icmp slt i32 %Y, -17               ; <i1> [#uses=1]
83         ret i1 %C
84 ; CHECK: ret i1 false
85 }
86
87 define i1 @gt_signed_to_large_unsigned(i8 %SB) {
88         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
89         %C = icmp ugt i32 %Y, 1024              ; <i1> [#uses=1]
90         ret i1 %C
91 ; CHECK: %C = icmp slt i8 %SB, 0
92 ; CHECK: ret i1 %C
93 }
94
95 define i1 @gt_signed_to_large_signed(i8 %SB) {
96         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
97         %C = icmp sgt i32 %Y, 1024              ; <i1> [#uses=1]
98         ret i1 %C
99 ; CHECK: ret i1 false
100 }
101
102 define i1 @gt_signed_to_large_negative(i8 %SB) {
103         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
104         %C = icmp sgt i32 %Y, -1024             ; <i1> [#uses=1]
105         ret i1 %C
106 ; CHECK: ret i1 true
107 }
108
109 define i1 @gt_signed_to_small_signed(i8 %SB) {
110         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
111         %C = icmp sgt i32 %Y, 17                ; <i1> [#uses=1]
112         ret i1 %C
113 ; CHECK: %C = icmp sgt i8 %SB, 17
114 ; CHECK: ret i1 %C
115 }
116
117 define i1 @gt_signed_to_small_negative(i8 %SB) {
118         %Y = sext i8 %SB to i32         ; <i32> [#uses=1]
119         %C = icmp sgt i32 %Y, -17               ; <i1> [#uses=1]
120         ret i1 %C
121 ; CHECK: %C = icmp sgt i8 %SB, -17
122 ; CHECK: ret i1 %C
123 }
124
125 define i1 @gt_unsigned_to_large_unsigned(i8 %SB) {
126         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
127         %C = icmp ugt i32 %Y, 1024              ; <i1> [#uses=1]
128         ret i1 %C
129 ; CHECK: ret i1 false
130 }
131
132 define i1 @gt_unsigned_to_large_signed(i8 %SB) {
133         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
134         %C = icmp sgt i32 %Y, 1024              ; <i1> [#uses=1]
135         ret i1 %C
136 ; CHECK: ret i1 false
137 }
138
139 define i1 @gt_unsigned_to_large_negative(i8 %SB) {
140         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
141         %C = icmp sgt i32 %Y, -1024             ; <i1> [#uses=1]
142         ret i1 %C
143 ; CHECK: ret i1 true
144 }
145
146 define i1 @gt_unsigned_to_small_unsigned(i8 %SB) {
147         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
148         %C = icmp ugt i32 %Y, 17                ; <i1> [#uses=1]
149         ret i1 %C
150 ; CHECK: %C = icmp ugt i8 %SB, 17
151 ; CHECK: ret i1 %C
152 }
153
154 define i1 @gt_unsigned_to_small_negative(i8 %SB) {
155         %Y = zext i8 %SB to i32         ; <i32> [#uses=1]
156         %C = icmp sgt i32 %Y, -17               ; <i1> [#uses=1]
157         ret i1 %C
158 ; CHECK: ret i1 true
159 }
160