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 Apr 17, 2024
1 parent 8fd78e5 commit 724cfef
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 @@ -8026,9 +8026,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 @@ -8039,8 +8041,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 @@ -1443,8 +1443,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 @@ -1454,8 +1453,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 @@ -1465,8 +1463,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 @@ -1506,8 +1503,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 @@ -1517,8 +1513,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 @@ -1528,8 +1523,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 @@ -1569,8 +1563,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 @@ -1580,8 +1573,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 @@ -1591,8 +1583,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 @@ -1632,8 +1623,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 @@ -1643,22 +1633,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 724cfef

Please sign in to comment.