Skip to content

Commit

Permalink
[InstCombine] add/adjust tests for flooring div; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Dec 18, 2022
1 parent 1706960 commit 3c7d059
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions llvm/test/Transforms/InstCombine/add.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,23 @@ define i32 @floor_sdiv(i32 %x) {
ret i32 %r
}

define <2 x i32> @floor_sdiv_vec_commute(<2 x i32> %x) {
; CHECK-LABEL: @floor_sdiv_vec_commute(
; CHECK-NEXT: [[D:%.*]] = sdiv <2 x i32> [[X:%.*]], <i32 4, i32 4>
; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[X]], <i32 -2147483645, i32 -2147483645>
; CHECK-NEXT: [[I:%.*]] = icmp ugt <2 x i32> [[A]], <i32 -2147483648, i32 -2147483648>
; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[I]] to <2 x i32>
; CHECK-NEXT: [[R:%.*]] = add nsw <2 x i32> [[D]], [[S]]
; CHECK-NEXT: ret <2 x i32> [[R]]
;
%d = sdiv <2 x i32> %x, <i32 4, i32 4>
%a = and <2 x i32> %x, <i32 -2147483645, i32 -2147483645>
%i = icmp ugt <2 x i32> %a, <i32 -2147483648, i32 -2147483648>
%s = sext <2 x i1> %i to <2 x i32>
%r = add <2 x i32> %s, %d
ret <2 x i32> %r
}

define i8 @floor_sdiv_uses(i8 %x) {
; CHECK-LABEL: @floor_sdiv_uses(
; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[X:%.*]], 16
Expand Down Expand Up @@ -2520,10 +2537,14 @@ define i32 @floor_sdiv_wrong_div(i32 %x) {
define i32 @floor_sdiv_wrong_mask(i32 %x) {
; CHECK-LABEL: @floor_sdiv_wrong_mask(
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 4
; CHECK-NEXT: ret i32 [[D]]
; CHECK-NEXT: [[A:%.*]] = and i32 [[X]], -2147483644
; CHECK-NEXT: [[I:%.*]] = icmp ugt i32 [[A]], -2147483648
; CHECK-NEXT: [[S:%.*]] = sext i1 [[I]] to i32
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[D]], [[S]]
; CHECK-NEXT: ret i32 [[R]]
;
%d = sdiv i32 %x, 4
%a = and i32 %x, 3
%a = and i32 %x, -2147483644
%i = icmp ugt i32 %a, -2147483648
%s = sext i1 %i to i32
%r = add i32 %d, %s
Expand All @@ -2532,30 +2553,31 @@ define i32 @floor_sdiv_wrong_mask(i32 %x) {

define i32 @floor_sdiv_wrong_cmp(i32 %x) {
; CHECK-LABEL: @floor_sdiv_wrong_cmp(
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 8
; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X]], 31
; CHECK-NEXT: [[X_LOBIT_NOT:%.*]] = xor i32 [[X_LOBIT]], -1
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[D]], [[X_LOBIT_NOT]]
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 4
; CHECK-NEXT: [[A:%.*]] = and i32 [[X]], -2147483646
; CHECK-NEXT: [[I:%.*]] = icmp eq i32 [[A]], -2147483646
; CHECK-NEXT: [[S:%.*]] = sext i1 [[I]] to i32
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[D]], [[S]]
; CHECK-NEXT: ret i32 [[R]]
;
%d = sdiv i32 %x, 8
%d = sdiv i32 %x, 4
%a = and i32 %x, -2147483645
%i = icmp ult i32 %a, -2147483648
%i = icmp ugt i32 %a, -2147483647
%s = sext i1 %i to i32
%r = add i32 %d, %s
ret i32 %r
}

define i32 @floor_sdiv_wrong_ext(i32 %x) {
; CHECK-LABEL: @floor_sdiv_wrong_ext(
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 8
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 4
; CHECK-NEXT: [[A:%.*]] = and i32 [[X]], -2147483645
; CHECK-NEXT: [[I:%.*]] = icmp ugt i32 [[A]], -2147483648
; CHECK-NEXT: [[S:%.*]] = zext i1 [[I]] to i32
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[D]], [[S]]
; CHECK-NEXT: ret i32 [[R]]
;
%d = sdiv i32 %x, 8
%d = sdiv i32 %x, 4
%a = and i32 %x, -2147483645
%i = icmp ugt i32 %a, -2147483648
%s = zext i1 %i to i32
Expand All @@ -2565,14 +2587,14 @@ define i32 @floor_sdiv_wrong_ext(i32 %x) {

define i32 @floor_sdiv_wrong_op(i32 %x, i32 %y) {
; CHECK-LABEL: @floor_sdiv_wrong_op(
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 8
; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 4
; CHECK-NEXT: [[A:%.*]] = and i32 [[Y:%.*]], -2147483645
; CHECK-NEXT: [[I:%.*]] = icmp ugt i32 [[A]], -2147483648
; CHECK-NEXT: [[S:%.*]] = zext i1 [[I]] to i32
; CHECK-NEXT: [[R:%.*]] = add nsw i32 [[D]], [[S]]
; CHECK-NEXT: ret i32 [[R]]
;
%d = sdiv i32 %x, 8
%d = sdiv i32 %x, 4
%a = and i32 %y, -2147483645
%i = icmp ugt i32 %a, -2147483648
%s = zext i1 %i to i32
Expand Down

0 comments on commit 3c7d059

Please sign in to comment.