[llvm] [InstCombine] Optimize redundant floating point comparisons in `or` inst (PR #158097)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 08:46:25 PDT 2025


================
@@ -4514,6 +4514,30 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
     if (Value *V = SimplifyAddWithRemainder(I))
       return replaceInstUsesWith(I, V);
 
+  Value *V0, *V1;
+  const APFloat *V0Op1, *V1Op1;
+  if (match(Op0, m_SpecificFCmp(FCmpInst::FCMP_OLT, m_Value(V0),
+                                m_APFloat(V0Op1))) &&
+      match(Op1, m_SpecificFCmp(FCmpInst::FCMP_OLT, m_Value(V1),
+                                m_APFloat(V1Op1)))) {
+    if (V0 == V1) {
+      if (V0Op1 > V1Op1)
+        replaceInstUsesWith(I, Op0);
----------------
dtcxzyw wrote:

This fold should be implemented in simplifyAndOrOfFCmps.


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


More information about the llvm-commits mailing list