1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
4 define i1 @wrapping_add_unknown_1(i8 %a) {
5 ; CHECK-LABEL: @wrapping_add_unknown_1(
7 ; CHECK-NEXT: [[SUB:%.*]] = add i8 [[A:%.*]], -1
8 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[SUB]], 0
9 ; CHECK-NEXT: ret i1 [[CMP]]
13 %cmp = icmp eq i8 %sub, 0
17 define i1 @wrapping_add_known_1(i8 %a) {
18 ; CHECK-LABEL: @wrapping_add_known_1(
20 ; CHECK-NEXT: [[PRE:%.*]] = icmp eq i8 [[A:%.*]], 1
21 ; CHECK-NEXT: br i1 [[PRE]], label [[THEN:%.*]], label [[ELSE:%.*]]
23 ; CHECK-NEXT: [[SUB_1:%.*]] = add i8 [[A]], -1
24 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8 [[SUB_1]], 0
25 ; CHECK-NEXT: ret i1 true
27 ; CHECK-NEXT: [[SUB_2:%.*]] = add i8 [[A]], -1
28 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i8 [[SUB_2]], 0
29 ; CHECK-NEXT: ret i1 [[C_2]]
32 %pre = icmp eq i8 %a, 1
33 br i1 %pre, label %then, label %else
36 %sub.1 = add i8 %a, -1
37 %c.1 = icmp eq i8 %sub.1, 0
41 %sub.2 = add i8 %a, -1
42 %c.2 = icmp eq i8 %sub.2, 0
46 define i1 @wrapping_add_unknown_2(i8 %a) {
47 ; CHECK-LABEL: @wrapping_add_unknown_2(
49 ; CHECK-NEXT: [[PRE:%.*]] = icmp eq i8 [[A:%.*]], 0
50 ; CHECK-NEXT: br i1 [[PRE]], label [[THEN:%.*]], label [[ELSE:%.*]]
52 ; CHECK-NEXT: [[SUB_1:%.*]] = add i8 [[A]], -1
53 ; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8 [[SUB_1]], 0
54 ; CHECK-NEXT: ret i1 [[C_1]]
56 ; CHECK-NEXT: [[SUB_2:%.*]] = add i8 [[A]], -1
57 ; CHECK-NEXT: [[C_2:%.*]] = icmp eq i8 [[SUB_2]], 0
58 ; CHECK-NEXT: ret i1 [[C_2]]
61 %pre = icmp eq i8 %a, 0
62 br i1 %pre, label %then, label %else
65 %sub.1 = add i8 %a, -1
66 %c.1 = icmp eq i8 %sub.1, 0
70 %sub.2 = add i8 %a, -1
71 %c.2 = icmp eq i8 %sub.2, 0
75 ; Test from https://github.com/llvm/llvm-project/issues/48253.
76 define i1 @test_48253_eq_ne(i8 %a, i8 %b) {
77 ; CHECK-LABEL: @test_48253_eq_ne(
79 ; CHECK-NEXT: [[CMP_1:%.*]] = icmp ne i8 [[A:%.*]], [[B:%.*]]
80 ; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq i8 [[B]], 0
81 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP_1]], [[CMP_2]]
82 ; CHECK-NEXT: br i1 [[OR]], label [[EXIT_1:%.*]], label [[IF_END:%.*]]
84 ; CHECK-NEXT: [[SUB_1:%.*]] = add i8 [[B]], -1
85 ; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[SUB_1]], [[A]]
86 ; CHECK-NEXT: [[SUB_2:%.*]] = add i8 [[B]], -2
87 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[SUB_2]], [[A]]
88 ; CHECK-NEXT: [[XOR_1:%.*]] = xor i1 true, [[C_2]]
89 ; CHECK-NEXT: ret i1 [[XOR_1]]
91 ; CHECK-NEXT: [[SUB_3:%.*]] = add i8 [[B]], -1
92 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[SUB_3]], [[A]]
93 ; CHECK-NEXT: [[SUB_4:%.*]] = add i8 [[B]], -2
94 ; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[SUB_4]], [[A]]
95 ; CHECK-NEXT: [[XOR_2:%.*]] = xor i1 [[C_3]], [[C_4]]
96 ; CHECK-NEXT: ret i1 [[XOR_2]]
99 %cmp.1 = icmp ne i8 %a, %b
100 %cmp.2 = icmp eq i8 %b, 0
101 %or = or i1 %cmp.1, %cmp.2
102 br i1 %or, label %exit.1, label %if.end
105 %sub.1 = add i8 %b, -1
106 %t.1 = icmp ult i8 %sub.1, %a
107 %sub.2 = add i8 %b, -2
108 %c.2 = icmp ult i8 %sub.2, %a
109 %xor.1 = xor i1 %t.1, %c.2
113 %sub.3 = add i8 %b, -1
114 %c.3 = icmp ult i8 %sub.3, %a
115 %sub.4 = add i8 %b, -2
116 %c.4 = icmp ult i8 %sub.4, %a
117 %xor.2 = xor i1 %c.3, %c.4
121 define i1 @test_ult(i8 %a, i8 %b) {
122 ; CHECK-LABEL: @test_ult(
124 ; CHECK-NEXT: [[CMP_1:%.*]] = icmp uge i8 [[A:%.*]], 20
125 ; CHECK-NEXT: [[CMP_2:%.*]] = icmp ult i8 [[A]], [[B:%.*]]
126 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP_1]], [[CMP_2]]
127 ; CHECK-NEXT: [[SUB_1:%.*]] = add i8 [[A]], -1
128 ; CHECK-NEXT: [[SUB_2:%.*]] = add i8 [[A]], -2
129 ; CHECK-NEXT: [[SUB_3:%.*]] = add i8 [[A]], -20
130 ; CHECK-NEXT: [[SUB_4:%.*]] = add i8 [[A]], 21
131 ; CHECK-NEXT: [[ADD_1:%.*]] = add i8 [[A]], 1
132 ; CHECK-NEXT: br i1 [[AND]], label [[IF_END:%.*]], label [[EXIT_1:%.*]]
134 ; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[SUB_1]], [[B]]
135 ; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[SUB_2]], [[B]]
136 ; CHECK-NEXT: [[XOR_1:%.*]] = xor i1 true, true
137 ; CHECK-NEXT: [[T_3:%.*]] = icmp ult i8 [[SUB_3]], [[B]]
138 ; CHECK-NEXT: [[XOR_2:%.*]] = xor i1 [[XOR_1]], true
139 ; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[SUB_4]], [[B]]
140 ; CHECK-NEXT: [[XOR_3:%.*]] = xor i1 [[XOR_2]], [[C_1]]
141 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[ADD_1]], [[B]]
142 ; CHECK-NEXT: [[XOR_4:%.*]] = xor i1 [[XOR_3]], [[C_2]]
143 ; CHECK-NEXT: ret i1 [[XOR_4]]
145 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[SUB_1]], [[B]]
146 ; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[SUB_2]], [[B]]
147 ; CHECK-NEXT: [[XOR_5:%.*]] = xor i1 [[C_3]], [[C_4]]
148 ; CHECK-NEXT: [[C_5:%.*]] = icmp ult i8 [[SUB_3]], [[B]]
149 ; CHECK-NEXT: [[XOR_6:%.*]] = xor i1 [[XOR_5]], [[C_5]]
150 ; CHECK-NEXT: [[C_6:%.*]] = icmp ult i8 [[SUB_4]], [[B]]
151 ; CHECK-NEXT: [[XOR_7:%.*]] = xor i1 [[XOR_6]], [[C_6]]
152 ; CHECK-NEXT: [[C_7:%.*]] = icmp ult i8 [[ADD_1]], [[B]]
153 ; CHECK-NEXT: [[XOR_8:%.*]] = xor i1 [[XOR_7]], [[C_7]]
154 ; CHECK-NEXT: ret i1 [[XOR_8]]
157 %cmp.1 = icmp uge i8 %a, 20
158 %cmp.2 = icmp ult i8 %a, %b
159 %and = and i1 %cmp.1, %cmp.2
160 %sub.1 = add i8 %a, -1
161 %sub.2 = add i8 %a, -2
162 %sub.3 = add i8 %a, -20
163 %sub.4 = add i8 %a, 21
164 %add.1 = add i8 %a, 1
165 br i1 %and, label %if.end, label %exit.1
168 %t.1 = icmp ult i8 %sub.1, %b
169 %t.2 = icmp ult i8 %sub.2, %b
170 %xor.1 = xor i1 %t.1, %t.2
172 %t.3 = icmp ult i8 %sub.3, %b
173 %xor.2 = xor i1 %xor.1, %t.3
175 %c.1 = icmp ult i8 %sub.4, %b
176 %xor.3 = xor i1 %xor.2, %c.1
178 %c.2 = icmp ult i8 %add.1, %b
179 %xor.4 = xor i1 %xor.3, %c.2
183 %c.3 = icmp ult i8 %sub.1, %b
184 %c.4 = icmp ult i8 %sub.2, %b
185 %xor.5 = xor i1 %c.3, %c.4
187 %c.5 = icmp ult i8 %sub.3, %b
188 %xor.6 = xor i1 %xor.5, %c.5
190 %c.6 = icmp ult i8 %sub.4, %b
191 %xor.7 = xor i1 %xor.6, %c.6
193 %c.7 = icmp ult i8 %add.1, %b
194 %xor.8 = xor i1 %xor.7, %c.7
198 define i1 @test_slt(i8 %a, i8 %b) {
199 ; CHECK-LABEL: @test_slt(
201 ; CHECK-NEXT: [[CMP_1:%.*]] = icmp sge i8 [[A:%.*]], 20
202 ; CHECK-NEXT: [[CMP_2:%.*]] = icmp slt i8 [[A]], [[B:%.*]]
203 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP_1]], [[CMP_2]]
204 ; CHECK-NEXT: [[SUB_1:%.*]] = add i8 [[A]], -1
205 ; CHECK-NEXT: [[SUB_2:%.*]] = add i8 [[A]], -2
206 ; CHECK-NEXT: [[SUB_3:%.*]] = add i8 [[A]], -20
207 ; CHECK-NEXT: [[SUB_4:%.*]] = add i8 [[A]], 21
208 ; CHECK-NEXT: [[ADD_1:%.*]] = add i8 [[A]], 1
209 ; CHECK-NEXT: br i1 [[AND]], label [[IF_END:%.*]], label [[EXIT_1:%.*]]
211 ; CHECK-NEXT: [[T_1:%.*]] = icmp slt i8 [[SUB_1]], [[B]]
212 ; CHECK-NEXT: [[T_2:%.*]] = icmp slt i8 [[SUB_2]], [[B]]
213 ; CHECK-NEXT: [[XOR_1:%.*]] = xor i1 [[T_1]], [[T_2]]
214 ; CHECK-NEXT: [[T_3:%.*]] = icmp slt i8 [[SUB_3]], [[B]]
215 ; CHECK-NEXT: [[XOR_2:%.*]] = xor i1 [[XOR_1]], [[T_3]]
216 ; CHECK-NEXT: [[C_1:%.*]] = icmp slt i8 [[SUB_4]], [[B]]
217 ; CHECK-NEXT: [[XOR_3:%.*]] = xor i1 [[XOR_2]], [[C_1]]
218 ; CHECK-NEXT: [[C_2:%.*]] = icmp slt i8 [[ADD_1]], [[B]]
219 ; CHECK-NEXT: [[XOR_4:%.*]] = xor i1 [[XOR_3]], [[C_2]]
220 ; CHECK-NEXT: ret i1 [[XOR_4]]
222 ; CHECK-NEXT: [[C_3:%.*]] = icmp slt i8 [[SUB_1]], [[B]]
223 ; CHECK-NEXT: [[C_4:%.*]] = icmp slt i8 [[SUB_2]], [[B]]
224 ; CHECK-NEXT: [[XOR_5:%.*]] = xor i1 [[C_3]], [[C_4]]
225 ; CHECK-NEXT: [[C_5:%.*]] = icmp slt i8 [[SUB_3]], [[B]]
226 ; CHECK-NEXT: [[XOR_6:%.*]] = xor i1 [[XOR_5]], [[C_5]]
227 ; CHECK-NEXT: [[C_6:%.*]] = icmp slt i8 [[SUB_4]], [[B]]
228 ; CHECK-NEXT: [[XOR_7:%.*]] = xor i1 [[XOR_6]], [[C_6]]
229 ; CHECK-NEXT: [[C_7:%.*]] = icmp slt i8 [[ADD_1]], [[B]]
230 ; CHECK-NEXT: [[XOR_8:%.*]] = xor i1 [[XOR_7]], [[C_7]]
231 ; CHECK-NEXT: ret i1 [[XOR_8]]
234 %cmp.1 = icmp sge i8 %a, 20
235 %cmp.2 = icmp slt i8 %a, %b
236 %and = and i1 %cmp.1, %cmp.2
237 %sub.1 = add i8 %a, -1
238 %sub.2 = add i8 %a, -2
239 %sub.3 = add i8 %a, -20
240 %sub.4 = add i8 %a, 21
241 %add.1 = add i8 %a, 1
242 br i1 %and, label %if.end, label %exit.1
245 %t.1 = icmp slt i8 %sub.1, %b
246 %t.2 = icmp slt i8 %sub.2, %b
247 %xor.1 = xor i1 %t.1, %t.2
249 %t.3 = icmp slt i8 %sub.3, %b
250 %xor.2 = xor i1 %xor.1, %t.3
252 %c.1 = icmp slt i8 %sub.4, %b
253 %xor.3 = xor i1 %xor.2, %c.1
255 %c.2 = icmp slt i8 %add.1, %b
256 %xor.4 = xor i1 %xor.3, %c.2
260 %c.3 = icmp slt i8 %sub.1, %b
261 %c.4 = icmp slt i8 %sub.2, %b
262 %xor.5 = xor i1 %c.3, %c.4
264 %c.5 = icmp slt i8 %sub.3, %b
265 %xor.6 = xor i1 %xor.5, %c.5
267 %c.6 = icmp slt i8 %sub.4, %b
268 %xor.7 = xor i1 %xor.6, %c.6
270 %c.7 = icmp slt i8 %add.1, %b
271 %xor.8 = xor i1 %xor.7, %c.7