Skip to content

Commit

Permalink
[InstCombine] Add tests for reassoc of and/or of fcmps (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Nov 13, 2024
1 parent 3169a38 commit 9c928d0
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
60 changes: 60 additions & 0 deletions llvm/test/Transforms/InstCombine/and-fcmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5042,6 +5042,66 @@ define i1 @isnormal_logical_select_0_fmf1(half %x) {
ret i1 %and
}

define i1 @and_fcmp_reassoc1(i1 %x, double %a, double %b) {
; CHECK-LABEL: @and_fcmp_reassoc1(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp ult double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = and i1 [[TMP1]], [[X:%.*]]
; CHECK-NEXT: [[RETVAL1:%.*]] = and i1 [[RETVAL]], [[CMP1]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp ult double %a, %b
%cmp1 = fcmp ugt double %a, %b
%and = and i1 %cmp, %x
%retval = and i1 %and, %cmp1
ret i1 %retval
}

define i1 @and_fcmp_reassoc2(i1 %x, double %a, double %b) {
; CHECK-LABEL: @and_fcmp_reassoc2(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp ult double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = and i1 [[X:%.*]], [[TMP1]]
; CHECK-NEXT: [[RETVAL1:%.*]] = and i1 [[RETVAL]], [[CMP1]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp ult double %a, %b
%cmp1 = fcmp ugt double %a, %b
%and = and i1 %x, %cmp
%retval = and i1 %and, %cmp1
ret i1 %retval
}

define i1 @and_fcmp_reassoc3(i1 %x, double %a, double %b) {
; CHECK-LABEL: @and_fcmp_reassoc3(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp ult double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = and i1 [[TMP1]], [[X:%.*]]
; CHECK-NEXT: [[RETVAL1:%.*]] = and i1 [[CMP1]], [[RETVAL]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp ult double %a, %b
%cmp1 = fcmp ugt double %a, %b
%and = and i1 %cmp, %x
%retval = and i1 %cmp1, %and
ret i1 %retval
}

define i1 @and_fcmp_reassoc4(i1 %x, double %a, double %b) {
; CHECK-LABEL: @and_fcmp_reassoc4(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp ult double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = and i1 [[X:%.*]], [[TMP1]]
; CHECK-NEXT: [[RETVAL1:%.*]] = and i1 [[CMP1]], [[RETVAL]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp ult double %a, %b
%cmp1 = fcmp ugt double %a, %b
%and = and i1 %x, %cmp
%retval = and i1 %cmp1, %and
ret i1 %retval
}

declare half @llvm.fabs.f16(half)
declare <2 x half> @llvm.fabs.v2f16(<2 x half>)
declare half @llvm.copysign.f16(half, half)
60 changes: 60 additions & 0 deletions llvm/test/Transforms/InstCombine/or-fcmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4605,3 +4605,63 @@ define i1 @intersect_fmf_4(double %a, double %b) {
%retval = or i1 %cmp, %cmp1
ret i1 %retval
}

define i1 @or_fcmp_reassoc1(i1 %x, double %a, double %b) {
; CHECK-LABEL: @or_fcmp_reassoc1(
; CHECK-NEXT: [[OR:%.*]] = fcmp olt double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = or i1 [[OR]], [[CMP1:%.*]]
; CHECK-NEXT: [[RETVAL1:%.*]] = or i1 [[RETVAL]], [[CMP2]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp olt double %a, %b
%cmp1 = fcmp ogt double %a, %b
%or = or i1 %cmp, %x
%retval = or i1 %or, %cmp1
ret i1 %retval
}

define i1 @or_fcmp_reassoc2(i1 %x, double %a, double %b) {
; CHECK-LABEL: @or_fcmp_reassoc2(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp olt double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = or i1 [[X:%.*]], [[TMP1]]
; CHECK-NEXT: [[RETVAL1:%.*]] = or i1 [[RETVAL]], [[CMP1]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp olt double %a, %b
%cmp1 = fcmp ogt double %a, %b
%or = or i1 %x, %cmp
%retval = or i1 %or, %cmp1
ret i1 %retval
}

define i1 @or_fcmp_reassoc3(i1 %x, double %a, double %b) {
; CHECK-LABEL: @or_fcmp_reassoc3(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp olt double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = or i1 [[TMP1]], [[X:%.*]]
; CHECK-NEXT: [[RETVAL1:%.*]] = or i1 [[CMP1]], [[RETVAL]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp olt double %a, %b
%cmp1 = fcmp ogt double %a, %b
%or = or i1 %cmp, %x
%retval = or i1 %cmp1, %or
ret i1 %retval
}

define i1 @or_fcmp_reassoc4(i1 %x, double %a, double %b) {
; CHECK-LABEL: @or_fcmp_reassoc4(
; CHECK-NEXT: [[TMP1:%.*]] = fcmp olt double [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt double [[A]], [[B]]
; CHECK-NEXT: [[RETVAL:%.*]] = or i1 [[X:%.*]], [[TMP1]]
; CHECK-NEXT: [[RETVAL1:%.*]] = or i1 [[CMP1]], [[RETVAL]]
; CHECK-NEXT: ret i1 [[RETVAL1]]
;
%cmp = fcmp olt double %a, %b
%cmp1 = fcmp ogt double %a, %b
%or = or i1 %x, %cmp
%retval = or i1 %cmp1, %or
ret i1 %retval
}

0 comments on commit 9c928d0

Please sign in to comment.