@@ -221,6 +221,19 @@ define i32 @select_abs_of_abs_eq(i32 %x) {
221
221
ret i32 %sel
222
222
}
223
223
224
+ ; The comparison is not with the same value we take abs() of, so this isn't the pattern.
225
+ define i32 @select_abs_of_abs_eq_wrong (i32 %x , i32 %y ) {
226
+ ; CHECK-LABEL: @select_abs_of_abs_eq_wrong(
227
+ ; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
228
+ ; CHECK-NEXT: ret i32 [[ABS]]
229
+ ;
230
+ %abs = call i32 @llvm.abs.i32 (i32 %x , i1 false )
231
+ %neg = sub i32 0 , %abs
232
+ %cmp = icmp eq i32 %y , 0 ; not %x
233
+ %sel = select i1 %cmp , i32 %neg , i32 %abs
234
+ ret i32 %sel
235
+ }
236
+
224
237
define i32 @select_abs_of_abs_ne (i32 %x ) {
225
238
; CHECK-LABEL: @select_abs_of_abs_ne(
226
239
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
@@ -246,6 +259,20 @@ define i32 @select_nabs_of_abs_eq(i32 %x) {
246
259
ret i32 %sel
247
260
}
248
261
262
+ ; The comparison is not with the same value we take abs() of, so this isn't the pattern.
263
+ define i32 @select_nabs_of_abs_eq_wrong (i32 %x , i32 %y ) {
264
+ ; CHECK-LABEL: @select_nabs_of_abs_eq_wrong(
265
+ ; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
266
+ ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
267
+ ; CHECK-NEXT: ret i32 [[NEG]]
268
+ ;
269
+ %abs = call i32 @llvm.abs.i32 (i32 %x , i1 false )
270
+ %neg = sub i32 0 , %abs
271
+ %cmp = icmp eq i32 %y , 0
272
+ %sel = select i1 %cmp , i32 %abs , i32 %neg
273
+ ret i32 %sel
274
+ }
275
+
249
276
define i32 @select_nabs_of_abs_ne (i32 %x ) {
250
277
; CHECK-LABEL: @select_nabs_of_abs_ne(
251
278
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
0 commit comments