Skip to content

Commit 4a68c27

Browse files
committed
[InstCombine] Add tests for nsw propagation in negator (NFC)
1 parent b51195d commit 4a68c27

File tree

1 file changed

+122
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+122
-0
lines changed

llvm/test/Transforms/InstCombine/nsw.ll

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,125 @@ define i32 @sub_sub1_nsw_nsw(i32 %a, i32 %b, i32 %c) {
252252
%s2 = sub nsw i32 %c, %s1
253253
ret i32 %s2
254254
}
255+
256+
define i8 @neg_nsw_select(i1 %c, i8 %a1, i8 %a2, i8 %b1, i8 %b2) {
257+
; CHECK-LABEL: @neg_nsw_select(
258+
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
259+
; CHECK-NEXT: [[B_NEG:%.*]] = sub i8 [[B2:%.*]], [[B1:%.*]]
260+
; CHECK-NEXT: [[SEL_NEG:%.*]] = select i1 [[C:%.*]], i8 [[A_NEG]], i8 [[B_NEG]]
261+
; CHECK-NEXT: ret i8 [[SEL_NEG]]
262+
;
263+
%a = sub nsw i8 %a1, %a2
264+
%b = sub nsw i8 %b1, %b2
265+
%sel = select i1 %c, i8 %a, i8 %b
266+
%neg = sub nsw i8 0, %sel
267+
ret i8 %neg
268+
}
269+
270+
define <4 x i8> @neg_nsw_shufflevector(<2 x i8> %a1, <2 x i8> %a2, <2 x i8> %b1, <2 x i8> %b2) {
271+
; CHECK-LABEL: @neg_nsw_shufflevector(
272+
; CHECK-NEXT: [[A_NEG:%.*]] = sub <2 x i8> [[A2:%.*]], [[A1:%.*]]
273+
; CHECK-NEXT: [[B_NEG:%.*]] = sub <2 x i8> [[B2:%.*]], [[B1:%.*]]
274+
; CHECK-NEXT: [[SHUF_NEG:%.*]] = shufflevector <2 x i8> [[A_NEG]], <2 x i8> [[B_NEG]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
275+
; CHECK-NEXT: ret <4 x i8> [[SHUF_NEG]]
276+
;
277+
%a = sub nsw <2 x i8> %a1, %a2
278+
%b = sub nsw <2 x i8> %b1, %b2
279+
%shuf = shufflevector <2 x i8> %a, <2 x i8> %b, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
280+
%neg = sub nsw <4 x i8> zeroinitializer, %shuf
281+
ret <4 x i8> %neg
282+
}
283+
284+
define i8 @neg_nsw_extractelement(<2 x i8> %a1, <2 x i8> %a2) {
285+
; CHECK-LABEL: @neg_nsw_extractelement(
286+
; CHECK-NEXT: [[A_NEG:%.*]] = sub <2 x i8> [[A2:%.*]], [[A1:%.*]]
287+
; CHECK-NEXT: [[EXTR_NEG:%.*]] = extractelement <2 x i8> [[A_NEG]], i64 0
288+
; CHECK-NEXT: ret i8 [[EXTR_NEG]]
289+
;
290+
%a = sub nsw <2 x i8> %a1, %a2
291+
%extr = extractelement <2 x i8> %a, i32 0
292+
%neg = sub nsw i8 0, %extr
293+
ret i8 %neg
294+
}
295+
296+
define <2 x i8> @neg_nsw_insertelement(<2 x i8> %a1, <2 x i8> %a2, i8 %b1, i8 %b2) {
297+
; CHECK-LABEL: @neg_nsw_insertelement(
298+
; CHECK-NEXT: [[A_NEG:%.*]] = sub <2 x i8> [[A2:%.*]], [[A1:%.*]]
299+
; CHECK-NEXT: [[B_NEG:%.*]] = sub i8 [[B2:%.*]], [[B1:%.*]]
300+
; CHECK-NEXT: [[INSERT_NEG:%.*]] = insertelement <2 x i8> [[A_NEG]], i8 [[B_NEG]], i64 0
301+
; CHECK-NEXT: ret <2 x i8> [[INSERT_NEG]]
302+
;
303+
%a = sub nsw <2 x i8> %a1, %a2
304+
%b = sub nsw i8 %b1, %b2
305+
%insert = insertelement <2 x i8> %a, i8 %b, i32 0
306+
%neg = sub nsw <2 x i8> zeroinitializer, %insert
307+
ret <2 x i8> %neg
308+
}
309+
310+
define i8 @neg_nsw_shl(i8 %a1, i8 %a2, i8 %b) {
311+
; CHECK-LABEL: @neg_nsw_shl(
312+
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
313+
; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i8 [[A_NEG]], [[B:%.*]]
314+
; CHECK-NEXT: ret i8 [[SHL_NEG]]
315+
;
316+
%a = sub nsw i8 %a1, %a2
317+
%shl = shl nsw i8 %a, %b
318+
%neg = sub nsw i8 0, %shl
319+
ret i8 %neg
320+
}
321+
322+
define i8 @neg_nsw_shl_missing_nsw_on_shl(i8 %a1, i8 %a2, i8 %b) {
323+
; CHECK-LABEL: @neg_nsw_shl_missing_nsw_on_shl(
324+
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
325+
; CHECK-NEXT: [[SHL_NEG:%.*]] = shl i8 [[A_NEG]], [[B:%.*]]
326+
; CHECK-NEXT: ret i8 [[SHL_NEG]]
327+
;
328+
%a = sub nsw i8 %a1, %a2
329+
%shl = shl i8 %a, %b
330+
%neg = sub nsw i8 0, %shl
331+
ret i8 %neg
332+
}
333+
334+
define i8 @neg_nsw_shl_to_mul(i8 %a, i8 %b) {
335+
; CHECK-LABEL: @neg_nsw_shl_to_mul(
336+
; CHECK-NEXT: [[SHL_NEG:%.*]] = mul i8 [[A:%.*]], -2
337+
; CHECK-NEXT: ret i8 [[SHL_NEG]]
338+
;
339+
%shl = shl nsw i8 %a, 1
340+
%neg = sub nsw i8 0, %shl
341+
ret i8 %neg
342+
}
343+
344+
define i8 @neg_nsw_shl_to_mul_missing_nsw_on_shl(i8 %a, i8 %b) {
345+
; CHECK-LABEL: @neg_nsw_shl_to_mul_missing_nsw_on_shl(
346+
; CHECK-NEXT: [[SHL_NEG:%.*]] = mul i8 [[A:%.*]], -2
347+
; CHECK-NEXT: ret i8 [[SHL_NEG]]
348+
;
349+
%shl = shl i8 %a, 1
350+
%neg = sub nsw i8 0, %shl
351+
ret i8 %neg
352+
}
353+
354+
define i8 @neg_nsw_mul(i8 %a1, i8 %a2, i8 %b) {
355+
; CHECK-LABEL: @neg_nsw_mul(
356+
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
357+
; CHECK-NEXT: [[SHL_NEG:%.*]] = mul i8 [[A_NEG]], [[B:%.*]]
358+
; CHECK-NEXT: ret i8 [[SHL_NEG]]
359+
;
360+
%a = sub nsw i8 %a1, %a2
361+
%shl = mul nsw i8 %a, %b
362+
%neg = sub nsw i8 0, %shl
363+
ret i8 %neg
364+
}
365+
366+
define i8 @neg_nsw_mul_missing_nsw_on_mul(i8 %a1, i8 %a2, i8 %b) {
367+
; CHECK-LABEL: @neg_nsw_mul_missing_nsw_on_mul(
368+
; CHECK-NEXT: [[A_NEG:%.*]] = sub i8 [[A2:%.*]], [[A1:%.*]]
369+
; CHECK-NEXT: [[SHL_NEG:%.*]] = mul i8 [[A_NEG]], [[B:%.*]]
370+
; CHECK-NEXT: ret i8 [[SHL_NEG]]
371+
;
372+
%a = sub nsw i8 %a1, %a2
373+
%shl = mul i8 %a, %b
374+
%neg = sub nsw i8 0, %shl
375+
ret i8 %neg
376+
}

0 commit comments

Comments
 (0)