@@ -400,6 +400,91 @@ define i64 @vector_legalized(i16 %a, i16 %b) {
400400 ret i64 %z
401401}
402402
403+ ;
404+ ; sub(select(icmp(a,b),a,b),select(icmp(a,b),b,a)) -> abdu(a,b)
405+ ;
406+
407+ define i8 @abd_select_i8 (i8 %a , i8 %b ) nounwind {
408+ ; CHECK-LABEL: abd_select_i8:
409+ ; CHECK: // %bb.0:
410+ ; CHECK-NEXT: and w8, w0, #0xff
411+ ; CHECK-NEXT: cmp w8, w1, uxtb
412+ ; CHECK-NEXT: csel w8, w0, w1, lo
413+ ; CHECK-NEXT: csel w9, w1, w0, lo
414+ ; CHECK-NEXT: sub w0, w9, w8
415+ ; CHECK-NEXT: ret
416+ %cmp = icmp ult i8 %a , %b
417+ %ab = select i1 %cmp , i8 %a , i8 %b
418+ %ba = select i1 %cmp , i8 %b , i8 %a
419+ %sub = sub i8 %ba , %ab
420+ ret i8 %sub
421+ }
422+
423+ define i16 @abd_select_i16 (i16 %a , i16 %b ) nounwind {
424+ ; CHECK-LABEL: abd_select_i16:
425+ ; CHECK: // %bb.0:
426+ ; CHECK-NEXT: and w8, w0, #0xffff
427+ ; CHECK-NEXT: cmp w8, w1, uxth
428+ ; CHECK-NEXT: csel w8, w0, w1, ls
429+ ; CHECK-NEXT: csel w9, w1, w0, ls
430+ ; CHECK-NEXT: sub w0, w9, w8
431+ ; CHECK-NEXT: ret
432+ %cmp = icmp ule i16 %a , %b
433+ %ab = select i1 %cmp , i16 %a , i16 %b
434+ %ba = select i1 %cmp , i16 %b , i16 %a
435+ %sub = sub i16 %ba , %ab
436+ ret i16 %sub
437+ }
438+
439+ define i32 @abd_select_i32 (i32 %a , i32 %b ) nounwind {
440+ ; CHECK-LABEL: abd_select_i32:
441+ ; CHECK: // %bb.0:
442+ ; CHECK-NEXT: cmp w0, w1
443+ ; CHECK-NEXT: csel w8, w0, w1, hi
444+ ; CHECK-NEXT: csel w9, w1, w0, hi
445+ ; CHECK-NEXT: sub w0, w8, w9
446+ ; CHECK-NEXT: ret
447+ %cmp = icmp ugt i32 %a , %b
448+ %ab = select i1 %cmp , i32 %a , i32 %b
449+ %ba = select i1 %cmp , i32 %b , i32 %a
450+ %sub = sub i32 %ab , %ba
451+ ret i32 %sub
452+ }
453+
454+ define i64 @abd_select_i64 (i64 %a , i64 %b ) nounwind {
455+ ; CHECK-LABEL: abd_select_i64:
456+ ; CHECK: // %bb.0:
457+ ; CHECK-NEXT: cmp x0, x1
458+ ; CHECK-NEXT: csel x8, x0, x1, hs
459+ ; CHECK-NEXT: csel x9, x1, x0, hs
460+ ; CHECK-NEXT: sub x0, x8, x9
461+ ; CHECK-NEXT: ret
462+ %cmp = icmp uge i64 %a , %b
463+ %ab = select i1 %cmp , i64 %a , i64 %b
464+ %ba = select i1 %cmp , i64 %b , i64 %a
465+ %sub = sub i64 %ab , %ba
466+ ret i64 %sub
467+ }
468+
469+ define i128 @abd_select_i128 (i128 %a , i128 %b ) nounwind {
470+ ; CHECK-LABEL: abd_select_i128:
471+ ; CHECK: // %bb.0:
472+ ; CHECK-NEXT: cmp x0, x2
473+ ; CHECK-NEXT: sbcs xzr, x1, x3
474+ ; CHECK-NEXT: csel x8, x0, x2, lo
475+ ; CHECK-NEXT: csel x9, x2, x0, lo
476+ ; CHECK-NEXT: csel x10, x1, x3, lo
477+ ; CHECK-NEXT: csel x11, x3, x1, lo
478+ ; CHECK-NEXT: subs x0, x9, x8
479+ ; CHECK-NEXT: sbc x1, x11, x10
480+ ; CHECK-NEXT: ret
481+ %cmp = icmp ult i128 %a , %b
482+ %ab = select i1 %cmp , i128 %a , i128 %b
483+ %ba = select i1 %cmp , i128 %b , i128 %a
484+ %sub = sub i128 %ba , %ab
485+ ret i128 %sub
486+ }
487+
403488declare i8 @llvm.abs.i8 (i8 , i1 )
404489declare i16 @llvm.abs.i16 (i16 , i1 )
405490declare i32 @llvm.abs.i32 (i32 , i1 )
0 commit comments