llvm.org GIT mirror llvm / 7d91dcd
[EarlyCSE] Add tests for negated min/max/abs [NFC] Summary: I'm planning to update the hashing logic to recognize their equivalence in a subsequent change (D62644). Reviewers: spatel Reviewed By: spatel Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62918 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362657 91177308-0d34-0410-b5e6-96231b3b80d8 Joseph Tremoulet 3 months ago
1 changed file(s) with 102 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
106106 ret i1 %r
107107 }
108108
109 ; Min/max can also have an inverted predicate and select operands.
110 ; TODO: Ensure we always recognize this (currently depends on hash collision)
111
112 define i1 @smin_inverted(i8 %a, i8 %b) {
113 ; CHECK-LABEL: @smin_inverted(
114 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A:%.*]], [[B:%.*]]
115 ; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
116 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
117 ; CHECK: ret i1
118 ;
119 %cmp1 = icmp slt i8 %a, %b
120 %cmp2 = xor i1 %cmp1, -1
121 %m1 = select i1 %cmp1, i8 %a, i8 %b
122 %m2 = select i1 %cmp2, i8 %b, i8 %a
123 %r = icmp eq i8 %m1, %m2
124 ret i1 %r
125 }
126
109127 define i8 @smax_commute(i8 %a, i8 %b) {
110128 ; CHECK-LABEL: @smax_commute(
111129 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A:%.*]], [[B:%.*]]
136154 ret i8 %r
137155 }
138156
157 ; TODO: Ensure we always recognize this (currently depends on hash collision)
158 define i1 @smax_inverted(i8 %a, i8 %b) {
159 ; CHECK-LABEL: @smax_inverted(
160 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A:%.*]], [[B:%.*]]
161 ; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
162 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
163 ; CHECK: ret i1
164 ;
165 %cmp1 = icmp sgt i8 %a, %b
166 %cmp2 = xor i1 %cmp1, -1
167 %m1 = select i1 %cmp1, i8 %a, i8 %b
168 %m2 = select i1 %cmp2, i8 %b, i8 %a
169 %r = icmp eq i8 %m1, %m2
170 ret i1 %r
171 }
172
139173 define i8 @umin_commute(i8 %a, i8 %b) {
140174 ; CHECK-LABEL: @umin_commute(
141175 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i8 [[A:%.*]], [[B:%.*]]
166200 %m2 = select <2 x i1> %cmp2, <2 x i8> %a, <2 x i8> %b
167201 %r = sub <2 x i8> %m2, %m1
168202 ret <2 x i8> %r
203 }
204
205 ; TODO: Ensure we always recognize this (currently depends on hash collision)
206 define i1 @umin_inverted(i8 %a, i8 %b) {
207 ; CHECK-LABEL: @umin_inverted(
208 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i8 [[A:%.*]], [[B:%.*]]
209 ; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
210 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
211 ; CHECK: ret i1
212 ;
213 %cmp1 = icmp ult i8 %a, %b
214 %cmp2 = xor i1 %cmp1, -1
215 %m1 = select i1 %cmp1, i8 %a, i8 %b
216 %m2 = select i1 %cmp2, i8 %b, i8 %a
217 %r = icmp eq i8 %m1, %m2
218 ret i1 %r
169219 }
170220
171221 define i8 @umax_commute(i8 %a, i8 %b) {
199249 ret i8 %r
200250 }
201251
252 ; TODO: Ensure we always recognize this (currently depends on hash collision)
253 define i1 @umax_inverted(i8 %a, i8 %b) {
254 ; CHECK-LABEL: @umax_inverted(
255 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i8 [[A:%.*]], [[B:%.*]]
256 ; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
257 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[B]]
258 ; CHECK: ret i1
259 ;
260 %cmp1 = icmp ugt i8 %a, %b
261 %cmp2 = xor i1 %cmp1, -1
262 %m1 = select i1 %cmp1, i8 %a, i8 %b
263 %m2 = select i1 %cmp2, i8 %b, i8 %a
264 %r = icmp eq i8 %m1, %m2
265 ret i1 %r
266 }
267
202268 ; Min/max may exist with non-canonical operands. Value tracking can match those.
203269
204270 define i8 @smax_nsw(i8 %a, i8 %b) {
235301 ret i8 %r
236302 }
237303
304 ; TODO: Ensure we always recognize this (currently depends on hash collision)
305 define i8 @abs_inverted(i8 %a) {
306 ; CHECK-LABEL: @abs_inverted(
307 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
308 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i8 [[A]], 0
309 ; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
310 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]]
311 ; CHECK: ret i8
312 ;
313 %neg = sub i8 0, %a
314 %cmp1 = icmp sgt i8 %a, 0
315 %cmp2 = xor i1 %cmp1, -1
316 %m1 = select i1 %cmp1, i8 %a, i8 %neg
317 %m2 = select i1 %cmp2, i8 %neg, i8 %a
318 %r = or i8 %m2, %m1
319 ret i8 %r
320 }
321
238322 define i8 @nabs_swapped(i8 %a) {
239323 ; CHECK-LABEL: @nabs_swapped(
240324 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
246330 %neg = sub i8 0, %a
247331 %cmp1 = icmp slt i8 %a, 0
248332 %cmp2 = icmp sgt i8 %a, 0
333 %m1 = select i1 %cmp1, i8 %a, i8 %neg
334 %m2 = select i1 %cmp2, i8 %neg, i8 %a
335 %r = xor i8 %m2, %m1
336 ret i8 %r
337 }
338
339 ; TODO: Ensure we always recognize this (currently depends on hash collision)
340 define i8 @nabs_inverted(i8 %a) {
341 ; CHECK-LABEL: @nabs_inverted(
342 ; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[A:%.*]]
343 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i8 [[A]], 0
344 ; CHECK-NEXT: [[CMP2:%.*]] = xor i1 [[CMP1]], true
345 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[CMP1]], i8 [[A]], i8 [[NEG]]
346 ; CHECK: ret i8
347 ;
348 %neg = sub i8 0, %a
349 %cmp1 = icmp slt i8 %a, 0
350 %cmp2 = xor i1 %cmp1, -1
249351 %m1 = select i1 %cmp1, i8 %a, i8 %neg
250352 %m2 = select i1 %cmp2, i8 %neg, i8 %a
251353 %r = xor i8 %m2, %m1