[llvm] [InstCombine] Fold fcmp ogt (x - y), 0 into fcmp ogt x, y #85245 (PR #85506)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 02:38:39 PDT 2024
================
@@ -7973,11 +7973,36 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
switch (LHSI->getOpcode()) {
case Instruction::FSub:
- if ((Pred == FCmpInst::FCMP_OGT || Pred == FCmpInst::FCMP_OLT ||
- Pred == FCmpInst::FCMP_ONE) &&
- match(RHSC, m_AnyZeroFP()) &&
- match(LHSI, m_FSub(m_Value(X), m_Value(Y))))
- return new FCmpInst(Pred, X, Y);
+ switch (Pred) {
+ default:
+ break;
+ case FCmpInst::FCMP_UGT:
+ case FCmpInst::FCMP_ULT:
+ case FCmpInst::FCMP_UNE:
+ case FCmpInst::FCMP_OEQ:
+ case FCmpInst::FCMP_OGE:
+ case FCmpInst::FCMP_OLE: {
+ BinaryOperator *SubI = cast<BinaryOperator>(LHSI);
+ if (!computeKnownFPClass(SubI->getOperand(0), SubI->getFastMathFlags(),
----------------
SahilPatidar wrote:
@jayfoad Perhaps we could handle this that way.
```cpp
if (!computeKnownFPClass(SubI->getOperand(0), SubI->getFastMathFlags(),
fcNan | fcInf, LHSI, 0)
.isKnownNever(fcNan | fcInf) &&
!computeKnownFPClass(SubI->getOperand(1), SubI->getFastMathFlags(),
fcNan | fcInf, LHSI, 0)
.isKnownNever(fcNan | fcInf))
```
https://github.com/llvm/llvm-project/pull/85506
More information about the llvm-commits
mailing list