Skip to content

Commit b6efd25

Browse files
committed
[InstCombine] add tests for nsw propagation; NFC
These are based on tests that were included in the abandoned D122299. Comments indicate what should or should not happen if we change behavior in Negator.
1 parent 9216baf commit b6efd25

File tree

1 file changed

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

1 file changed

+86
-0
lines changed

llvm/test/Transforms/InstCombine/nsw.ll

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,89 @@ define <vscale x 2 x i64> @mul_nuw_nsw_shuffle_constant_expr(<vscale x 2 x i8> %
140140
%t3 = mul <vscale x 2 x i64> %shuf, %xx
141141
ret <vscale x 2 x i64> %t3
142142
}
143+
144+
; This could propagate nsw.
145+
146+
define i32 @neg_sub0_sub_nsw_nsw(i32 %a, i32 %b) {
147+
; CHECK-LABEL: @neg_sub0_sub_nsw_nsw(
148+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
149+
; CHECK-NEXT: ret i32 [[C_NEG]]
150+
;
151+
%c = sub nsw i32 %a, %b
152+
%d = sub nsw i32 0, %c
153+
ret i32 %d
154+
}
155+
156+
; Must not propagate nsw.
157+
158+
define i32 @neg_sub_sub_nsw0(i32 %a, i32 %b) {
159+
; CHECK-LABEL: @neg_sub_sub_nsw0(
160+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
161+
; CHECK-NEXT: ret i32 [[C_NEG]]
162+
;
163+
%c = sub nsw i32 %a, %b
164+
%d = sub i32 0, %c
165+
ret i32 %d
166+
}
167+
168+
; Must not propagate nsw.
169+
170+
define i32 @neg_sub_sub_nsw1(i32 %a, i32 %b) {
171+
; CHECK-LABEL: @neg_sub_sub_nsw1(
172+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
173+
; CHECK-NEXT: ret i32 [[C_NEG]]
174+
;
175+
%c = sub i32 %a, %b
176+
%d = sub nsw i32 0, %c
177+
ret i32 %d
178+
}
179+
180+
; This could propagate nsw.
181+
182+
define i32 @neg_mul_sub_nsw_nsw(i32 %a, i32 %b) {
183+
; CHECK-LABEL: @neg_mul_sub_nsw_nsw(
184+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
185+
; CHECK-NEXT: ret i32 [[C_NEG]]
186+
;
187+
%c = sub nsw i32 %a, %b
188+
%d = mul nsw i32 -1, %c
189+
ret i32 %d
190+
}
191+
192+
; Must not propagate nsw.
193+
194+
define i32 @neg_mul_sub_nsw0(i32 %a, i32 %b) {
195+
; CHECK-LABEL: @neg_mul_sub_nsw0(
196+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
197+
; CHECK-NEXT: ret i32 [[C_NEG]]
198+
;
199+
%c = sub nsw i32 %a, %b
200+
%d = mul i32 -1, %c
201+
ret i32 %d
202+
}
203+
204+
; Must not propagate nsw.
205+
206+
define i32 @neg_mul_sub_nsw1(i32 %a, i32 %b) {
207+
; CHECK-LABEL: @neg_mul_sub_nsw1(
208+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i32 [[B:%.*]], [[A:%.*]]
209+
; CHECK-NEXT: ret i32 [[C_NEG]]
210+
;
211+
%c = sub i32 %a, %b
212+
%d = mul nsw i32 -1, %c
213+
ret i32 %d
214+
}
215+
216+
; Must not propagate nsw.
217+
218+
define i8 @neg_sub_sub2(i16 %a, i16 %b) {
219+
; CHECK-LABEL: @neg_sub_sub2(
220+
; CHECK-NEXT: [[C_NEG:%.*]] = sub i16 [[B:%.*]], [[A:%.*]]
221+
; CHECK-NEXT: [[D_NEG:%.*]] = trunc i16 [[C_NEG]] to i8
222+
; CHECK-NEXT: ret i8 [[D_NEG]]
223+
;
224+
%c = sub nsw i16 %a, %b
225+
%d = trunc i16 %c to i8
226+
%e = sub nsw i8 0, %d
227+
ret i8 %e
228+
}

0 commit comments

Comments
 (0)