[llvm] [InstCombine] FP fold, cond ? x : -x == 0 into x == 0 #85250 (PR #85673)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 22 08:57:48 PDT 2024


================
@@ -7972,6 +7972,13 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
   Constant *RHSC;
   if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
     switch (LHSI->getOpcode()) {
+    case Instruction::Select:
+      if ((Pred == FCmpInst::FCMP_UEQ || Pred == FCmpInst::FCMP_OEQ ||
+           Pred == FCmpInst::FCMP_UNE || Pred == FCmpInst::FCMP_ONE) &&
+          match(LHSI, m_Select(m_Value(), m_Value(X), m_FNeg(m_Value(Y)))) &&
+          X == Y && match(RHSC, m_AnyZeroFP()))
----------------
jayfoad wrote:

Also you should check the RHS constant before the LHS expression, since it's cheaper to check.

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


More information about the llvm-commits mailing list