Skip to content

Commit

Permalink
[InstCombine] Add additional mask merging tests (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 2, 2024
1 parent b468119 commit eb3361d
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions llvm/test/Transforms/InstCombine/and-or-icmps.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3332,3 +3332,93 @@ define i1 @icmp_eq_or_z_or_pow2orz_fail_bad_pred2(i8 %x, i8 %y) {
%r = or i1 %c0, %cp2
ret i1 %r
}

define i1 @and_slt_to_mask(i8 %x) {
; CHECK-LABEL: @and_slt_to_mask(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -124
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 2
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[CMP]], [[CMP2]]
; CHECK-NEXT: ret i1 [[AND2]]
;
%cmp = icmp slt i8 %x, -124
%and = and i8 %x, 2
%cmp2 = icmp eq i8 %and, 0
%and2 = and i1 %cmp, %cmp2
ret i1 %and2
}

define i1 @and_slt_to_mask_off_by_one(i8 %x) {
; CHECK-LABEL: @and_slt_to_mask_off_by_one(
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], -123
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 2
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[CMP]], [[CMP2]]
; CHECK-NEXT: ret i1 [[AND2]]
;
%cmp = icmp slt i8 %x, -123
%and = and i8 %x, 2
%cmp2 = icmp eq i8 %and, 0
%and2 = and i1 %cmp, %cmp2
ret i1 %and2
}

define i1 @and_sgt_to_mask(i8 %x) {
; CHECK-LABEL: @and_sgt_to_mask(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 123
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 2
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[CMP]], [[CMP2]]
; CHECK-NEXT: ret i1 [[AND2]]
;
%cmp = icmp sgt i8 %x, 123
%and = and i8 %x, 2
%cmp2 = icmp eq i8 %and, 0
%and2 = and i1 %cmp, %cmp2
ret i1 %and2
}

define i1 @and_sgt_to_mask_off_by_one(i8 %x) {
; CHECK-LABEL: @and_sgt_to_mask_off_by_one(
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], 124
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 2
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[CMP]], [[CMP2]]
; CHECK-NEXT: ret i1 [[AND2]]
;
%cmp = icmp sgt i8 %x, 124
%and = and i8 %x, 2
%cmp2 = icmp eq i8 %and, 0
%and2 = and i1 %cmp, %cmp2
ret i1 %and2
}

define i1 @and_ugt_to_mask(i8 %x) {
; CHECK-LABEL: @and_ugt_to_mask(
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], -5
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 2
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[CMP]], [[CMP2]]
; CHECK-NEXT: ret i1 [[AND2]]
;
%cmp = icmp ugt i8 %x, -5
%and = and i8 %x, 2
%cmp2 = icmp eq i8 %and, 0
%and2 = and i1 %cmp, %cmp2
ret i1 %and2
}

define i1 @and_ugt_to_mask_off_by_one(i8 %x) {
; CHECK-LABEL: @and_ugt_to_mask_off_by_one(
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[X:%.*]], -6
; CHECK-NEXT: [[AND:%.*]] = and i8 [[X]], 2
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: [[AND2:%.*]] = and i1 [[CMP]], [[CMP2]]
; CHECK-NEXT: ret i1 [[AND2]]
;
%cmp = icmp ugt i8 %x, -6
%and = and i8 %x, 2
%cmp2 = icmp eq i8 %and, 0
%and2 = and i1 %cmp, %cmp2
ret i1 %and2
}

0 comments on commit eb3361d

Please sign in to comment.