[llvm] [InstCombine] Fold fcmp ogt (x - y), 0 into fcmp ogt x, y #85245 (PR #85506)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 02:16:56 PDT 2024


================
@@ -8016,6 +8016,39 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
   Constant *RHSC;
   if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
     switch (LHSI->getOpcode()) {
+    case Instruction::FSub:
+      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: {
+        if (!LHSI->hasNoNaNs() && !LHSI->hasNoInfs() &&
+            !isKnownNeverInfinity(LHSI->getOperand(0), /*Depth=*/0,
+                                  getSimplifyQuery().getWithInstruction(&I)) &&
+            !isKnownNeverInfinity(LHSI->getOperand(1), /*Depth=*/0,
+                                  getSimplifyQuery().getWithInstruction(&I)))
----------------
arsenm wrote:

```suggestion
            !isKnownNeverInfinity(LHSI->getOperand(1), /*Depth=*/0,
                                  getSimplifyQuery().getWithInstruction(&I)) &&
            !isKnownNeverInfinity(LHSI->getOperand(0), /*Depth=*/0,
                                  getSimplifyQuery().getWithInstruction(&I)))
```

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


More information about the llvm-commits mailing list