[llvm] logical AND and OR in if-conditionals can turn to multiple branch instructions (PR #162041)

Abhishek Kaushik via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 6 00:08:14 PDT 2025


================
@@ -3625,6 +3625,24 @@ X86TargetLowering::getJumpConditionMergingParams(Instruction::BinaryOps Opc,
       match(Lhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())) &&
       match(Rhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())))
     BaseCost += 1;
+  
+  // For OR conditions with EQ comparisons, prefer splitting into branches
+  // (unless CCMP is available). OR+EQ cannot be optimized via bitwise ops,
+  // unlike OR+NE which becomes (P|Q)!=0. Similarly, don't split signed
+  // comparisons (SLT, SGT) that can be optimized.
+  if (BaseCost >= 0 && !Subtarget.hasCCMP() && Opc == Instruction::Or) {
----------------
abhishek-kaushik22 wrote:

Can we use a match here like the previous check? 
```
if (BaseCost >= 0 && !Subtarget.hasCCMP() && Opc == Instruction::Or &&
      match(Lhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())) &&
      match(Rhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())))
    return {-1,-1,-1};
```

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


More information about the llvm-commits mailing list