[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
Fri Mar 22 05:29:53 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()) &&
----------------
jayfoad wrote:

For `ogt olt one ueq uge ule` you do not need to worry about infinity.

For `ugt ult une oeq oge ole` you need to rule out the `+inf - +inf = nan` and `-inf - -inf = nan` cases. To do that, you can check for _any_ of:
- The subtraction has the ninf flag.
- The subtraction has the nnan flag.
- X is known never infinity.
- Y is known never infinity.

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


More information about the llvm-commits mailing list