https://gcc.gnu.org/g:fbc849d9c3872a05a308724f4009c18685b5af9c

commit r16-2297-gfbc849d9c3872a05a308724f4009c18685b5af9c
Author: Andrew Pinski <quic_apin...@quicinc.com>
Date:   Mon Jul 7 12:16:54 2025 -0700

    ifconv: Small improvement to fold_build_cond_expr; lhs and rhs being the 
same.
    
    This is a small compile time optimization, as match and simplify will 
generate
    the same thing but with rhs and lhs being the same we can return early 
instead
    of having to go through match and simplify. This might not show up that much
    at this point but can/will show up after my patch for PR 119920 where we 
factor
    out common code between the 2 sides of the if statement while in if-conv.
    
    Bootstrapped and tested on x86_64-linux-gnu.
    
    gcc/ChangeLog:
    
            * tree-if-conv.cc (fold_build_cond_expr): Return early if lhs and 
rhs
            are the same.
    
    Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>

Diff:
---
 gcc/tree-if-conv.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index d2b9f9fe0809..366e959fd776 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -494,6 +494,10 @@ fold_or_predicates (location_t loc, tree c1, tree c2)
 static tree
 fold_build_cond_expr (tree type, tree cond, tree rhs, tree lhs)
 {
+  /* Short cut the case where both rhs and lhs are the same. */
+  if (operand_equal_p (rhs, lhs))
+    return rhs;
+
   /* If COND is comparison r != 0 and r has boolean type, convert COND
      to SSA_NAME to accept by vect bool pattern.  */
   if (TREE_CODE (cond) == NE_EXPR)

Reply via email to