diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index b5418e2737d0bb..7d81ae9a522363 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -8026,9 +8026,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) { case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_OLE: { - BinaryOperator *SubI = cast(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; @@ -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; diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll index a1dbbb6ab2378c..e7997c77d38630 100644 --- a/llvm/test/Transforms/InstCombine/fcmp.ll +++ b/llvm/test/Transforms/InstCombine/fcmp.ll @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 }