diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index b2b0f449ba1871..639151c0f9984e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -8046,9 +8046,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; @@ -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; diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll index cdaa1e2775f56e..bd4f8a56069d74 100644 --- a/llvm/test/Transforms/InstCombine/fcmp.ll +++ b/llvm/test/Transforms/InstCombine/fcmp.ll @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 }