File: 2004-11-27-SetCCForCastLargerAndConstant.ll

package info (click to toggle)
llvm-toolchain-6.0 1:6.0-1~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 594,652 kB
  • sloc: cpp: 3,044,500; ansic: 595,051; asm: 271,890; python: 128,923; objc: 106,554; sh: 21,854; lisp: 10,191; pascal: 6,094; ml: 5,544; perl: 5,265; makefile: 2,214; cs: 2,027; xml: 686; php: 212; csh: 117
file content (269 lines) | stat: -rw-r--r-- 6,956 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; This test case tests the InstructionCombining optimization that
; reduces things like:
;   %Y = sext i8 %X to i32
;   %C = icmp ult i32 %Y, 1024
; to
;   %C = i1 true
; It includes test cases for different constant values, signedness of the
; cast operands, and types of setCC operators. In all cases, the cast should
; be eliminated. In many cases the setCC is also eliminated based on the
; constant value and the range of the casted value.
;
; RUN: opt < %s -instcombine -S | FileCheck %s

define i1 @lt_signed_to_large_unsigned(i8 %SB) {
; CHECK-LABEL: @lt_signed_to_large_unsigned(
; CHECK-NEXT:    [[C1:%.*]] = icmp sgt i8 %SB, -1
; CHECK-NEXT:    ret i1 [[C1]]
;
  %Y = sext i8 %SB to i32
  %C = icmp ult i32 %Y, 1024
  ret i1 %C
}

; PR28011 - https://llvm.org/bugs/show_bug.cgi?id=28011
; The above transform only applies to scalar integers; it shouldn't be attempted for constant expressions or vectors.

@a = common global i32** null
@b = common global [1 x i32] zeroinitializer

define i1 @PR28011(i16 %a) {
; CHECK-LABEL: @PR28011(
; CHECK-NEXT:    [[CONV:%.*]] = sext i16 %a to i32
; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[CONV]], or (i32 zext (i1 icmp ne (i32*** bitcast ([1 x i32]* @b to i32***), i32*** @a) to i32), i32 1)
; CHECK-NEXT:    ret i1 [[CMP]]
;
  %conv = sext i16 %a to i32
  %cmp = icmp ne i32 %conv, or (i32 zext (i1 icmp ne (i32*** bitcast ([1 x i32]* @b to i32***), i32*** @a) to i32), i32 1)
  ret i1 %cmp
}

define <2 x i1> @lt_signed_to_large_unsigned_vec(<2 x i8> %SB) {
; CHECK-LABEL: @lt_signed_to_large_unsigned_vec(
; CHECK-NEXT:    [[Y:%.*]] = sext <2 x i8> %SB to <2 x i32>
; CHECK-NEXT:    [[C:%.*]] = icmp ult <2 x i32> [[Y]], <i32 1024, i32 2>
; CHECK-NEXT:    ret <2 x i1> [[C]]
;
  %Y = sext <2 x i8> %SB to <2 x i32>
  %C = icmp ult <2 x i32> %Y, <i32 1024, i32 2>
  ret <2 x i1> %C
}

define i1 @lt_signed_to_large_signed(i8 %SB) {
; CHECK-LABEL: @lt_signed_to_large_signed(
; CHECK-NEXT:    ret i1 true
;
  %Y = sext i8 %SB to i32
  %C = icmp slt i32 %Y, 1024
  ret i1 %C
}

define i1 @lt_signed_to_large_negative(i8 %SB) {
; CHECK-LABEL: @lt_signed_to_large_negative(
; CHECK-NEXT:    ret i1 false
;
  %Y = sext i8 %SB to i32
  %C = icmp slt i32 %Y, -1024
  ret i1 %C
}

define i1 @lt_signed_to_small_unsigned(i8 %SB) {
; CHECK-LABEL: @lt_signed_to_small_unsigned(
; CHECK-NEXT:    [[C:%.*]] = icmp ult i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp ult i32 %Y, 17
  ret i1 %C
}

define i1 @lt_signed_to_small_signed(i8 %SB) {
; CHECK-LABEL: @lt_signed_to_small_signed(
; CHECK-NEXT:    [[C:%.*]] = icmp slt i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp slt i32 %Y, 17
  ret i1 %C
}
define i1 @lt_signed_to_small_negative(i8 %SB) {
; CHECK-LABEL: @lt_signed_to_small_negative(
; CHECK-NEXT:    [[C:%.*]] = icmp slt i8 %SB, -17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp slt i32 %Y, -17
  ret i1 %C
}

define i1 @lt_unsigned_to_large_unsigned(i8 %SB) {
; CHECK-LABEL: @lt_unsigned_to_large_unsigned(
; CHECK-NEXT:    ret i1 true
;
  %Y = zext i8 %SB to i32
  %C = icmp ult i32 %Y, 1024
  ret i1 %C
}

define i1 @lt_unsigned_to_large_signed(i8 %SB) {
; CHECK-LABEL: @lt_unsigned_to_large_signed(
; CHECK-NEXT:    ret i1 true
;
  %Y = zext i8 %SB to i32
  %C = icmp slt i32 %Y, 1024
  ret i1 %C
}

define i1 @lt_unsigned_to_large_negative(i8 %SB) {
; CHECK-LABEL: @lt_unsigned_to_large_negative(
; CHECK-NEXT:    ret i1 false
;
  %Y = zext i8 %SB to i32
  %C = icmp slt i32 %Y, -1024
  ret i1 %C
}

define i1 @lt_unsigned_to_small_unsigned(i8 %SB) {
; CHECK-LABEL: @lt_unsigned_to_small_unsigned(
; CHECK-NEXT:    [[C:%.*]] = icmp ult i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = zext i8 %SB to i32
  %C = icmp ult i32 %Y, 17
  ret i1 %C
}

define i1 @lt_unsigned_to_small_signed(i8 %SB) {
; CHECK-LABEL: @lt_unsigned_to_small_signed(
; CHECK-NEXT:    [[C:%.*]] = icmp ult i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = zext i8 %SB to i32
  %C = icmp slt i32 %Y, 17
  ret i1 %C
}

define i1 @lt_unsigned_to_small_negative(i8 %SB) {
; CHECK-LABEL: @lt_unsigned_to_small_negative(
; CHECK-NEXT:    ret i1 false
;
  %Y = zext i8 %SB to i32
  %C = icmp slt i32 %Y, -17
  ret i1 %C
}

define i1 @gt_signed_to_large_unsigned(i8 %SB) {
; CHECK-LABEL: @gt_signed_to_large_unsigned(
; CHECK-NEXT:    [[C:%.*]] = icmp slt i8 %SB, 0
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp ugt i32 %Y, 1024
  ret i1 %C
}

define i1 @gt_signed_to_large_signed(i8 %SB) {
; CHECK-LABEL: @gt_signed_to_large_signed(
; CHECK-NEXT:    ret i1 false
;
  %Y = sext i8 %SB to i32
  %C = icmp sgt i32 %Y, 1024
  ret i1 %C
}

define i1 @gt_signed_to_large_negative(i8 %SB) {
; CHECK-LABEL: @gt_signed_to_large_negative(
; CHECK-NEXT:    ret i1 true
;
  %Y = sext i8 %SB to i32
  %C = icmp sgt i32 %Y, -1024
  ret i1 %C
}

define i1 @gt_signed_to_small_unsigned(i8 %SB) {
; CHECK-LABEL: @gt_signed_to_small_unsigned(
; CHECK-NEXT:    [[C:%.*]] = icmp ugt i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp ugt i32 %Y, 17
  ret i1 %C
}

define i1 @gt_signed_to_small_signed(i8 %SB) {
; CHECK-LABEL: @gt_signed_to_small_signed(
; CHECK-NEXT:    [[C:%.*]] = icmp sgt i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp sgt i32 %Y, 17
  ret i1 %C
}

define i1 @gt_signed_to_small_negative(i8 %SB) {
; CHECK-LABEL: @gt_signed_to_small_negative(
; CHECK-NEXT:    [[C:%.*]] = icmp sgt i8 %SB, -17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = sext i8 %SB to i32
  %C = icmp sgt i32 %Y, -17
  ret i1 %C
}

define i1 @gt_unsigned_to_large_unsigned(i8 %SB) {
; CHECK-LABEL: @gt_unsigned_to_large_unsigned(
; CHECK-NEXT:    ret i1 false
;
  %Y = zext i8 %SB to i32
  %C = icmp ugt i32 %Y, 1024
  ret i1 %C
}

define i1 @gt_unsigned_to_large_signed(i8 %SB) {
; CHECK-LABEL: @gt_unsigned_to_large_signed(
; CHECK-NEXT:    ret i1 false
;
  %Y = zext i8 %SB to i32
  %C = icmp sgt i32 %Y, 1024
  ret i1 %C
}

define i1 @gt_unsigned_to_large_negative(i8 %SB) {
; CHECK-LABEL: @gt_unsigned_to_large_negative(
; CHECK-NEXT:    ret i1 true
;
  %Y = zext i8 %SB to i32
  %C = icmp sgt i32 %Y, -1024
  ret i1 %C
}

define i1 @gt_unsigned_to_small_unsigned(i8 %SB) {
; CHECK-LABEL: @gt_unsigned_to_small_unsigned(
; CHECK-NEXT:    [[C:%.*]] = icmp ugt i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = zext i8 %SB to i32
  %C = icmp ugt i32 %Y, 17
  ret i1 %C
}

define i1 @gt_unsigned_to_small_signed(i8 %SB) {
; CHECK-LABEL: @gt_unsigned_to_small_signed(
; CHECK-NEXT:    [[C:%.*]] = icmp ugt i8 %SB, 17
; CHECK-NEXT:    ret i1 [[C]]
;
  %Y = zext i8 %SB to i32
  %C = icmp sgt i32 %Y, 17
  ret i1 %C
}

define i1 @gt_unsigned_to_small_negative(i8 %SB) {
; CHECK-LABEL: @gt_unsigned_to_small_negative(
; CHECK-NEXT:    ret i1 true
;
  %Y = zext i8 %SB to i32
  %C = icmp sgt i32 %Y, -17
  ret i1 %C
}