• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4; Fold
5;   (%x - %y) u<= %x
6; to
7;   @llvm.sub.with.overflow(%x, %y) + extractvalue + not
8
9define i1 @t0_basic(i8 %x, i8 %y) {
10; CHECK-LABEL: @t0_basic(
11; CHECK-NEXT:    [[R:%.*]] = icmp ule i8 [[Y:%.*]], [[X:%.*]]
12; CHECK-NEXT:    ret i1 [[R]]
13;
14  %t0 = sub i8 %x, %y
15  %r = icmp ule i8 %t0, %x
16  ret i1 %r
17}
18
19define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) {
20; CHECK-LABEL: @t1_vec(
21; CHECK-NEXT:    [[R:%.*]] = icmp ule <2 x i8> [[Y:%.*]], [[X:%.*]]
22; CHECK-NEXT:    ret <2 x i1> [[R]]
23;
24  %t0 = sub <2 x i8> %x, %y
25  %r = icmp ule <2 x i8> %t0, %x
26  ret <2 x i1> %r
27}
28
29; Commutativity
30
31define i1 @t2_commutative(i8 %x, i8 %y) {
32; CHECK-LABEL: @t2_commutative(
33; CHECK-NEXT:    [[R:%.*]] = icmp ule i8 [[Y:%.*]], [[X:%.*]]
34; CHECK-NEXT:    ret i1 [[R]]
35;
36  %t0 = sub i8 %x, %y
37  %r = icmp uge i8 %x, %t0 ; swapped
38  ret i1 %r
39}
40
41; Extra-use tests
42
43declare void @use8(i8)
44
45define i1 @t3_extrause0(i8 %x, i8 %y) {
46; CHECK-LABEL: @t3_extrause0(
47; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
48; CHECK-NEXT:    call void @use8(i8 [[T0]])
49; CHECK-NEXT:    [[R:%.*]] = icmp uge i8 [[X]], [[Y]]
50; CHECK-NEXT:    ret i1 [[R]]
51;
52  %t0 = sub i8 %x, %y
53  call void @use8(i8 %t0)
54  %r = icmp ule i8 %t0, %x
55  ret i1 %r
56}
57
58; Negative tests
59
60define i1 @n4_not_commutative(i8 %x, i8 %y) {
61; CHECK-LABEL: @n4_not_commutative(
62; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
63; CHECK-NEXT:    [[R:%.*]] = icmp ule i8 [[T0]], [[Y]]
64; CHECK-NEXT:    ret i1 [[R]]
65;
66  %t0 = sub i8 %x, %y
67  %r = icmp ule i8 %t0, %y ; can't check against %y.
68  ret i1 %r
69}
70
71define i1 @n5_wrong_pred0(i8 %x, i8 %y) {
72; CHECK-LABEL: @n5_wrong_pred0(
73; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
74; CHECK-NEXT:    [[R:%.*]] = icmp ult i8 [[T0]], [[X]]
75; CHECK-NEXT:    ret i1 [[R]]
76;
77  %t0 = sub i8 %x, %y
78  %r = icmp ult i8 %t0, %x
79  ret i1 %r
80}
81
82define i1 @n6_wrong_pred1(i8 %x, i8 %y) {
83; CHECK-LABEL: @n6_wrong_pred1(
84; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
85; CHECK-NEXT:    [[R:%.*]] = icmp uge i8 [[T0]], [[X]]
86; CHECK-NEXT:    ret i1 [[R]]
87;
88  %t0 = sub i8 %x, %y
89  %r = icmp uge i8 %t0, %x
90  ret i1 %r
91}
92
93define i1 @n7_wrong_pred2(i8 %x, i8 %y) {
94; CHECK-LABEL: @n7_wrong_pred2(
95; CHECK-NEXT:    [[R:%.*]] = icmp eq i8 [[Y:%.*]], 0
96; CHECK-NEXT:    ret i1 [[R]]
97;
98  %t0 = sub i8 %x, %y
99  %r = icmp eq i8 %t0, %x
100  ret i1 %r
101}
102
103define i1 @n8_wrong_pred3(i8 %x, i8 %y) {
104; CHECK-LABEL: @n8_wrong_pred3(
105; CHECK-NEXT:    [[R:%.*]] = icmp ne i8 [[Y:%.*]], 0
106; CHECK-NEXT:    ret i1 [[R]]
107;
108  %t0 = sub i8 %x, %y
109  %r = icmp ne i8 %t0, %x
110  ret i1 %r
111}
112
113define i1 @n9_wrong_pred4(i8 %x, i8 %y) {
114; CHECK-LABEL: @n9_wrong_pred4(
115; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
116; CHECK-NEXT:    [[R:%.*]] = icmp slt i8 [[T0]], [[X]]
117; CHECK-NEXT:    ret i1 [[R]]
118;
119  %t0 = sub i8 %x, %y
120  %r = icmp slt i8 %t0, %x
121  ret i1 %r
122}
123
124define i1 @n10_wrong_pred5(i8 %x, i8 %y) {
125; CHECK-LABEL: @n10_wrong_pred5(
126; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
127; CHECK-NEXT:    [[R:%.*]] = icmp sle i8 [[T0]], [[X]]
128; CHECK-NEXT:    ret i1 [[R]]
129;
130  %t0 = sub i8 %x, %y
131  %r = icmp sle i8 %t0, %x
132  ret i1 %r
133}
134
135define i1 @n11_wrong_pred6(i8 %x, i8 %y) {
136; CHECK-LABEL: @n11_wrong_pred6(
137; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
138; CHECK-NEXT:    [[R:%.*]] = icmp sgt i8 [[T0]], [[X]]
139; CHECK-NEXT:    ret i1 [[R]]
140;
141  %t0 = sub i8 %x, %y
142  %r = icmp sgt i8 %t0, %x
143  ret i1 %r
144}
145
146define i1 @n12_wrong_pred7(i8 %x, i8 %y) {
147; CHECK-LABEL: @n12_wrong_pred7(
148; CHECK-NEXT:    [[T0:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
149; CHECK-NEXT:    [[R:%.*]] = icmp sge i8 [[T0]], [[X]]
150; CHECK-NEXT:    ret i1 [[R]]
151;
152  %t0 = sub i8 %x, %y
153  %r = icmp sge i8 %t0, %x
154  ret i1 %r
155}
156