Skip to content

Commit

Permalink
fix: Handle ninf values (update test)
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilPatidar committed May 8, 2024
1 parent 54de447 commit bf21f85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
15 changes: 10 additions & 5 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8046,9 +8046,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_OEQ:
case FCmpInst::FCMP_OGE:
case FCmpInst::FCMP_OLE: {
BinaryOperator *SubI = cast<BinaryOperator>(LHSI);
if (!isKnownNeverInfOrNaN(SubI->getOperand(0), 0, SQ) &&
!isKnownNeverInfOrNaN(SubI->getOperand(1), 0, SQ))
if (!LHSI->hasNoNaNs() && !LHSI->hasNoInfs() &&
!isKnownNeverInfinity(LHSI->getOperand(0), /*Depth=*/0,
getSimplifyQuery().getWithInstruction(&I)) &&
!isKnownNeverInfinity(LHSI->getOperand(1), /*Depth=*/0,
getSimplifyQuery().getWithInstruction(&I)))
break;
}
LLVM_FALLTHROUGH;
Expand All @@ -8059,8 +8061,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
case FCmpInst::FCMP_UGE:
case FCmpInst::FCMP_ULE:
if (match(RHSC, m_AnyZeroFP()) &&
match(LHSI, m_FSub(m_Value(X), m_Value(Y))))
return new FCmpInst(Pred, X, Y, "", &I);
match(LHSI, m_FSub(m_Value(X), m_Value(Y)))) {
replaceOperand(I, 0, X);
replaceOperand(I, 1, Y);
return &I;
}
break;
}
break;
Expand Down
44 changes: 16 additions & 28 deletions llvm/test/Transforms/InstCombine/fcmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1847,8 +1847,7 @@ define <8 x i1> @fcmp_ueq_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_oge_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_oge_fsub_const_ninf_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub ninf <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf oge <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf oge <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub ninf <8 x float> %x, %y
Expand All @@ -1858,8 +1857,7 @@ define <8 x i1> @fcmp_oge_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_ole_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_ole_fsub_const_ninf_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub ninf <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ole <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ole <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub ninf <8 x float> %x, %y
Expand All @@ -1869,8 +1867,7 @@ define <8 x i1> @fcmp_ole_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_oeq_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_oeq_fsub_const_ninf_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub ninf <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf oeq <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf oeq <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub ninf <8 x float> %x, %y
Expand Down Expand Up @@ -1910,8 +1907,7 @@ define <8 x i1> @fcmp_one_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_ugt_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_ugt_fsub_const_ninf_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub ninf <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ugt <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ugt <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub ninf <8 x float> %x, %y
Expand All @@ -1921,8 +1917,7 @@ define <8 x i1> @fcmp_ugt_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_ult_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_ult_fsub_const_ninf_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub ninf <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ult <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf ult <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub ninf <8 x float> %x, %y
Expand All @@ -1932,8 +1927,7 @@ define <8 x i1> @fcmp_ult_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_une_fsub_const_ninf_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_une_fsub_const_ninf_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub ninf <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf une <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp ninf une <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub ninf <8 x float> %x, %y
Expand Down Expand Up @@ -1973,8 +1967,7 @@ define <8 x i1> @fcmp_ueq_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_oge_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_oge_fsub_const_nnan_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub nnan <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oge <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oge <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub nnan <8 x float> %x, %y
Expand All @@ -1984,8 +1977,7 @@ define <8 x i1> @fcmp_oge_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_ole_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_ole_fsub_const_nnan_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub nnan <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ole <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ole <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub nnan <8 x float> %x, %y
Expand All @@ -1995,8 +1987,7 @@ define <8 x i1> @fcmp_ole_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_oeq_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_oeq_fsub_const_nnan_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub nnan <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oeq <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oeq <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub nnan <8 x float> %x, %y
Expand Down Expand Up @@ -2036,8 +2027,7 @@ define <8 x i1> @fcmp_one_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_ugt_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_ugt_fsub_const_nnan_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub nnan <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ugt <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ugt <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub nnan <8 x float> %x, %y
Expand All @@ -2047,22 +2037,20 @@ define <8 x i1> @fcmp_ugt_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {

define <8 x i1> @fcmp_ult_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_ult_fsub_const_nnan_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub fast <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp fast ult <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ult <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub fast <8 x float> %x, %y
%cmp = fcmp fast ult <8 x float> %fs, zeroinitializer
%fs = fsub nnan <8 x float> %x, %y
%cmp = fcmp nnan ult <8 x float> %fs, zeroinitializer
ret <8 x i1> %cmp
}

define <8 x i1> @fcmp_une_fsub_const_nnan_vec(<8 x float> %x, <8 x float> %y) {
; CHECK-LABEL: @fcmp_une_fsub_const_nnan_vec(
; CHECK-NEXT: [[FS:%.*]] = fsub fast <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp fast une <8 x float> [[FS]], zeroinitializer
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan une <8 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <8 x i1> [[CMP]]
;
%fs = fsub fast <8 x float> %x, %y
%cmp = fcmp fast une <8 x float> %fs, zeroinitializer
%fs = fsub nnan <8 x float> %x, %y
%cmp = fcmp nnan une <8 x float> %fs, zeroinitializer
ret <8 x i1> %cmp
}

0 comments on commit bf21f85

Please sign in to comment.