1 ; This test case tests the InstructionCombining optimization that
3 ; %Y = sext i8 %X to i32
4 ; %C = icmp ult i32 %Y, 1024
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.
12 ; RUN: opt < %s -instcombine -S | FileCheck %s
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]
18 ; CHECK: %C1 = icmp sgt i8 %SB, -1
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]
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]
36 define i1 @lt_signed_to_small_unsigned(i8 %SB) {
37 %Y = sext i8 %SB to i32
38 %C = icmp ult i32 %Y, 17
40 ; CHECK: %C = icmp ult i8 %SB, 17
44 define i1 @lt_signed_to_small_signed(i8 %SB) {
45 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
46 %C = icmp slt i32 %Y, 17 ; <i1> [#uses=1]
48 ; CHECK: %C = icmp slt i8 %SB, 17
51 define i1 @lt_signed_to_small_negative(i8 %SB) {
52 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
53 %C = icmp slt i32 %Y, -17 ; <i1> [#uses=1]
55 ; CHECK: %C = icmp slt i8 %SB, -17
59 define i1 @lt_unsigned_to_large_unsigned(i8 %SB) {
60 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
61 %C = icmp ult i32 %Y, 1024 ; <i1> [#uses=1]
66 define i1 @lt_unsigned_to_large_signed(i8 %SB) {
67 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
68 %C = icmp slt i32 %Y, 1024 ; <i1> [#uses=1]
73 define i1 @lt_unsigned_to_large_negative(i8 %SB) {
74 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
75 %C = icmp slt i32 %Y, -1024 ; <i1> [#uses=1]
80 define i1 @lt_unsigned_to_small_unsigned(i8 %SB) {
81 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
82 %C = icmp ult i32 %Y, 17 ; <i1> [#uses=1]
84 ; CHECK: %C = icmp ult i8 %SB, 17
88 define i1 @lt_unsigned_to_small_signed(i8 %SB) {
89 %Y = zext i8 %SB to i32
90 %C = icmp slt i32 %Y, 17
92 ; CHECK: %C = icmp ult i8 %SB, 17
96 define i1 @lt_unsigned_to_small_negative(i8 %SB) {
97 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
98 %C = icmp slt i32 %Y, -17 ; <i1> [#uses=1]
100 ; CHECK: ret i1 false
103 define i1 @gt_signed_to_large_unsigned(i8 %SB) {
104 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
105 %C = icmp ugt i32 %Y, 1024 ; <i1> [#uses=1]
107 ; CHECK: %C = icmp slt i8 %SB, 0
111 define i1 @gt_signed_to_large_signed(i8 %SB) {
112 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
113 %C = icmp sgt i32 %Y, 1024 ; <i1> [#uses=1]
115 ; CHECK: ret i1 false
118 define i1 @gt_signed_to_large_negative(i8 %SB) {
119 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
120 %C = icmp sgt i32 %Y, -1024 ; <i1> [#uses=1]
125 define i1 @gt_signed_to_small_unsigned(i8 %SB) {
126 %Y = sext i8 %SB to i32
127 %C = icmp ugt i32 %Y, 17
129 ; CHECK: %C = icmp ugt i8 %SB, 17
133 define i1 @gt_signed_to_small_signed(i8 %SB) {
134 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
135 %C = icmp sgt i32 %Y, 17 ; <i1> [#uses=1]
137 ; CHECK: %C = icmp sgt i8 %SB, 17
141 define i1 @gt_signed_to_small_negative(i8 %SB) {
142 %Y = sext i8 %SB to i32 ; <i32> [#uses=1]
143 %C = icmp sgt i32 %Y, -17 ; <i1> [#uses=1]
145 ; CHECK: %C = icmp sgt i8 %SB, -17
149 define i1 @gt_unsigned_to_large_unsigned(i8 %SB) {
150 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
151 %C = icmp ugt i32 %Y, 1024 ; <i1> [#uses=1]
153 ; CHECK: ret i1 false
156 define i1 @gt_unsigned_to_large_signed(i8 %SB) {
157 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
158 %C = icmp sgt i32 %Y, 1024 ; <i1> [#uses=1]
160 ; CHECK: ret i1 false
163 define i1 @gt_unsigned_to_large_negative(i8 %SB) {
164 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
165 %C = icmp sgt i32 %Y, -1024 ; <i1> [#uses=1]
170 define i1 @gt_unsigned_to_small_unsigned(i8 %SB) {
171 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
172 %C = icmp ugt i32 %Y, 17 ; <i1> [#uses=1]
174 ; CHECK: %C = icmp ugt i8 %SB, 17
178 define i1 @gt_unsigned_to_small_signed(i8 %SB) {
179 %Y = zext i8 %SB to i32
180 %C = icmp sgt i32 %Y, 17
182 ; CHECK: %C = icmp ugt i8 %SB, 17
186 define i1 @gt_unsigned_to_small_negative(i8 %SB) {
187 %Y = zext i8 %SB to i32 ; <i32> [#uses=1]
188 %C = icmp sgt i32 %Y, -17 ; <i1> [#uses=1]