[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
Fri Mar 22 05:06:45 PDT 2024


================
@@ -7972,6 +7972,11 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
   Constant *RHSC;
   if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
     switch (LHSI->getOpcode()) {
+    case Instruction::FSub:
+      if (Pred == FCmpInst::FCMP_OGT && match(RHSC, m_PosZeroFP()) &&
----------------
SahilPatidar wrote:

```cpp
if (match(RHSC, m_AnyZeroFP()) &&
    match(LHSI, m_FSub(m_Value(X), m_Value(Y))) &&
    isKnownNeverInfinity(X, 0, getSimplifyQuery().getWithInstruction(LHSI)) &&
    isKnownNeverInfinity(Y, 0, getSimplifyQuery().getWithInstruction(LHSI)))
  return new FCmpInst(Pred, X, Y);
```
Is this the correct way to do it? It doesn't seem to be producing the expected output; `isKnownNeverInfinity` produces false for every test.

https://github.com/llvm/llvm-project/pull/85506


More information about the llvm-commits mailing list