[InstSimplify] Add tests for a peculiar abs of abs form (NFC)

This pattern shows up when canonicalizing to spf abs form to
intrinsic abs form.
This commit is contained in:
Nikita Popov 2020-09-05 21:40:53 +02:00
parent 6276196b86
commit 4af70f1516

View File

@ -201,3 +201,63 @@ define i1 @abs_ule_int_min(i8 %x) {
%c = icmp ule i8 %abs, 128
ret i1 %c
}
define i32 @select_abs_of_abs_eq(i32 %x) {
; CHECK-LABEL: @select_abs_of_abs_eq(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 0
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[ABS]]
; CHECK-NEXT: ret i32 [[SEL]]
;
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
%neg = sub i32 0, %abs
%cmp = icmp eq i32 %x, 0
%sel = select i1 %cmp, i32 %neg, i32 %abs
ret i32 %sel
}
define i32 @select_abs_of_abs_ne(i32 %x) {
; CHECK-LABEL: @select_abs_of_abs_ne(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X]], 0
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[ABS]], i32 [[NEG]]
; CHECK-NEXT: ret i32 [[SEL]]
;
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
%neg = sub i32 0, %abs
%cmp = icmp ne i32 %x, 0
%sel = select i1 %cmp, i32 %abs, i32 %neg
ret i32 %sel
}
define i32 @select_nabs_of_abs_eq(i32 %x) {
; CHECK-LABEL: @select_nabs_of_abs_eq(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 0
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[ABS]], i32 [[NEG]]
; CHECK-NEXT: ret i32 [[SEL]]
;
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
%neg = sub i32 0, %abs
%cmp = icmp eq i32 %x, 0
%sel = select i1 %cmp, i32 %abs, i32 %neg
ret i32 %sel
}
define i32 @select_nabs_of_abs_ne(i32 %x) {
; CHECK-LABEL: @select_nabs_of_abs_ne(
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X]], 0
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[NEG]], i32 [[ABS]]
; CHECK-NEXT: ret i32 [[SEL]]
;
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
%neg = sub i32 0, %abs
%cmp = icmp ne i32 %x, 0
%sel = select i1 %cmp, i32 %neg, i32 %abs
ret i32 %sel
}