@@ -176,3 +176,85 @@ define i1 @a_false_implies_b_false2_comm(i8 %z, i1 %X, i1 %Y) {
176
176
%res = or i1 %sel , %a
177
177
ret i1 %res
178
178
}
179
+
180
+ define i1 @trunc_nuw_implies_icmp_eq (i8 %x , i1 %c ) {
181
+ ; CHECK-LABEL: @trunc_nuw_implies_icmp_eq(
182
+ ; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
183
+ ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[TRUNC]], i1 true, i1 [[C:%.*]]
184
+ ; CHECK-NEXT: ret i1 [[SEL2]]
185
+ ;
186
+ %trunc = trunc nuw i8 %x to i1
187
+ %cmp = icmp eq i8 %x , 0
188
+ %sel1 = select i1 %cmp , i1 %c , i1 false
189
+ %sel2 = select i1 %trunc , i1 true , i1 %sel1
190
+ ret i1 %sel2
191
+ }
192
+
193
+ define i1 @icmp_eq_implies_trunc_nuw (i8 %x , i1 %c ) {
194
+ ; CHECK-LABEL: @icmp_eq_implies_trunc_nuw(
195
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X:%.*]], 0
196
+ ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[CMP]], i1 true, i1 [[C:%.*]]
197
+ ; CHECK-NEXT: ret i1 [[SEL2]]
198
+ ;
199
+ %trunc = trunc nuw i8 %x to i1
200
+ %cmp = icmp eq i8 %x , 0
201
+ %sel1 = select i1 %trunc , i1 %c , i1 false
202
+ %sel2 = select i1 %cmp , i1 true , i1 %sel1
203
+ ret i1 %sel2
204
+ }
205
+
206
+ define <2 x i1 > @trunc_nuw_implies_icmp_eq_vec (<2 x i8 > %x , <2 x i1 > %c ) {
207
+ ; CHECK-LABEL: @trunc_nuw_implies_icmp_eq_vec(
208
+ ; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw <2 x i8> [[X:%.*]] to <2 x i1>
209
+ ; CHECK-NEXT: [[SEL2:%.*]] = select <2 x i1> [[TRUNC]], <2 x i1> splat (i1 true), <2 x i1> [[C:%.*]]
210
+ ; CHECK-NEXT: ret <2 x i1> [[SEL2]]
211
+ ;
212
+ %trunc = trunc nuw <2 x i8 > %x to <2 x i1 >
213
+ %cmp = icmp eq <2 x i8 > %x , splat (i8 0 )
214
+ %sel1 = select <2 x i1 > %cmp , <2 x i1 > %c , <2 x i1 > splat (i1 false )
215
+ %sel2 = select <2 x i1 > %trunc , <2 x i1 > splat (i1 true ), <2 x i1 > %sel1
216
+ ret <2 x i1 > %sel2
217
+ }
218
+
219
+ define <2 x i1 > @icmp_eq_implies_trunc_nuw_vec (<2 x i8 > %x , <2 x i1 > %c ) {
220
+ ; CHECK-LABEL: @icmp_eq_implies_trunc_nuw_vec(
221
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], zeroinitializer
222
+ ; CHECK-NEXT: [[SEL2:%.*]] = select <2 x i1> [[CMP]], <2 x i1> splat (i1 true), <2 x i1> [[C:%.*]]
223
+ ; CHECK-NEXT: ret <2 x i1> [[SEL2]]
224
+ ;
225
+ %trunc = trunc nuw <2 x i8 > %x to <2 x i1 >
226
+ %cmp = icmp eq <2 x i8 > %x , splat (i8 0 )
227
+ %sel1 = select <2 x i1 > %trunc , <2 x i1 > %c , <2 x i1 > splat (i1 false )
228
+ %sel2 = select <2 x i1 > %cmp , <2 x i1 > splat (i1 true ), <2 x i1 > %sel1
229
+ ret <2 x i1 > %sel2
230
+ }
231
+
232
+ define i1 @neg_trunc_implies_icmp_eq (i8 %x , i1 %c ) {
233
+ ; CHECK-LABEL: @neg_trunc_implies_icmp_eq(
234
+ ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
235
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], 0
236
+ ; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[CMP]], i1 [[C:%.*]], i1 false
237
+ ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[TRUNC]], i1 true, i1 [[SEL1]]
238
+ ; CHECK-NEXT: ret i1 [[SEL2]]
239
+ ;
240
+ %trunc = trunc i8 %x to i1
241
+ %cmp = icmp eq i8 %x , 0
242
+ %sel1 = select i1 %cmp , i1 %c , i1 false
243
+ %sel2 = select i1 %trunc , i1 true , i1 %sel1
244
+ ret i1 %sel2
245
+ }
246
+
247
+ define i1 @neg_icmp_eq_implies_trunc (i8 %x , i1 %c ) {
248
+ ; CHECK-LABEL: @neg_icmp_eq_implies_trunc(
249
+ ; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
250
+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], 0
251
+ ; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[TRUNC]], i1 [[C:%.*]], i1 false
252
+ ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[CMP]], i1 true, i1 [[SEL1]]
253
+ ; CHECK-NEXT: ret i1 [[SEL2]]
254
+ ;
255
+ %trunc = trunc i8 %x to i1
256
+ %cmp = icmp eq i8 %x , 0
257
+ %sel1 = select i1 %trunc , i1 %c , i1 false
258
+ %sel2 = select i1 %cmp , i1 true , i1 %sel1
259
+ ret i1 %sel2
260
+ }
0 commit comments