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

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 03:23:01 PDT 2024


================
@@ -7867,6 +7867,51 @@ static Instruction *foldFCmpFNegCommonOp(FCmpInst &I) {
   return new FCmpInst(Pred, Op0, Zero, "", &I);
 }
 
+static Instruction *foldFCmpFSubIntoFCmp(FCmpInst &I, Instruction *LHSI,
+                                         Constant *RHSC, InstCombinerImpl &CI) {
+  const CmpInst::Predicate Pred = I.getPredicate();
+  Value *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:
+    // Skip optimization: fsub x, y unless guaranteed !isinf(x) ||
+    // !isinf(y).
----------------
jayfoad wrote:

Suggest explaining this a bit more fully, e.g.:
```suggestion
    // The optimization is not valid if X and Y are infinities of the same
    // sign, i.e. the inf - inf = nan case. If the fsub has the ninf or nnan flag
    // then we can assume we do not have that case. Otherwise we might
    // be able to prove that either X or Y is not infinity.
```

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


More information about the llvm-commits mailing list