Skip to content

Commit 823ede1

Browse files
committed
Add negative tests.
1 parent 905381c commit 823ede1

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

llvm/test/Transforms/InstCombine/sub-after-sle-is-non-negative.ll

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
22
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3+
declare void @subroutine(i16)
4+
35
define void @test_as_arg(i8 %a, i8 %b) {
46
; CHECK-LABEL: define void @test_as_arg(
57
; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) {
@@ -26,8 +28,6 @@ cond.end:
2628
ret void
2729
}
2830

29-
declare void @subroutine(i16)
30-
3131
define i16 @test_as_retval(i8 %a, i8 %b) {
3232
; CHECK-LABEL: define i16 @test_as_retval(
3333
; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) {
@@ -51,3 +51,53 @@ cond.false:
5151
%conv = sext i8 %sub to i16
5252
ret i16 %conv
5353
}
54+
55+
define void @test_as_arg_neg(i8 %a, i8 %b) {
56+
; CHECK-LABEL: define void @test_as_arg_neg(
57+
; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) {
58+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[A]], [[B]]
59+
; CHECK-NEXT: br i1 [[CMP]], label %[[COND_END:.*]], label %[[COND_FALSE:.*]]
60+
; CHECK: [[COND_FALSE]]:
61+
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 [[B]], [[A]]
62+
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[SUB]] to i16
63+
; CHECK-NEXT: call void @subroutine(i16 [[CONV]])
64+
; CHECK-NEXT: br label %[[COND_END]]
65+
; CHECK: [[COND_END]]:
66+
; CHECK-NEXT: ret void
67+
;
68+
%cmp = icmp slt i8 %a, %b
69+
br i1 %cmp, label %cond.end, label %cond.false
70+
71+
cond.false:
72+
%sub = sub nsw i8 %b, %a
73+
%conv = sext i8 %sub to i16
74+
call void @subroutine(i16 %conv)
75+
br label %cond.end
76+
77+
cond.end:
78+
ret void
79+
}
80+
81+
define i16 @test_as_retval_neg(i8 %a, i8 %b) {
82+
; CHECK-LABEL: define i16 @test_as_retval_neg(
83+
; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) {
84+
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[A]], [[B]]
85+
; CHECK-NEXT: br i1 [[CMP]], label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]]
86+
; CHECK: [[COND_TRUE]]:
87+
; CHECK-NEXT: ret i16 0
88+
; CHECK: [[COND_FALSE]]:
89+
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i8 [[B]], [[A]]
90+
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[SUB]] to i16
91+
; CHECK-NEXT: ret i16 [[CONV]]
92+
;
93+
%cmp = icmp slt i8 %a, %b
94+
br i1 %cmp, label %cond.true, label %cond.false
95+
96+
cond.true:
97+
ret i16 0
98+
99+
cond.false:
100+
%sub = sub nsw i8 %b, %a
101+
%conv = sext i8 %sub to i16
102+
ret i16 %conv
103+
}

0 commit comments

Comments
 (0)