https://gcc.gnu.org/g:192c1c656b8b9a5e88c201c0a1c9a689fb35fd55

commit r16-478-g192c1c656b8b9a5e88c201c0a1c9a689fb35fd55
Author: Andrew Pinski <quic_apin...@quicinc.com>
Date:   Mon Apr 21 23:22:02 2025 -0700

    gimple-fold: Don't replace `bool_var != 0` with `bool_var` inside 
GIMPLE_COND
    
    Since match and simplify will simplify `bool_var != 0` to just `bool_var` 
and
    this is inside a GIMPLE_COND, fold_stmt will return true but nothing has 
changed.
    So let's just reject the replacement if we are replacing with the same 
simplification
    inside replace_stmt_with_simplification. This can speed up things slightly 
because
    now fold_stmt won't return true on all GIMPLE_COND with `bool_var != 0` in 
it.
    
    gcc/ChangeLog:
    
            * gimple-fold.cc (replace_stmt_with_simplification): Return false
            if replacing `bool_var != 0` with `bool_var` in GIMPLE_COND.
    
    Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>

Diff:
---
 gcc/gimple-fold.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index fd52b58905c0..f801e8b6d419 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6246,8 +6246,16 @@ replace_stmt_with_simplification (gimple_stmt_iterator 
*gsi,
                                          false, NULL_TREE)))
        gimple_cond_set_condition (cond_stmt, code, ops[0], ops[1]);
       else if (code == SSA_NAME)
-       gimple_cond_set_condition (cond_stmt, NE_EXPR, ops[0],
-                                  build_zero_cst (TREE_TYPE (ops[0])));
+       {
+         /* If setting the gimple cond to the same thing,
+            return false as nothing changed.  */
+         if (gimple_cond_code (cond_stmt) == NE_EXPR
+             && operand_equal_p (gimple_cond_lhs (cond_stmt), ops[0])
+             && integer_zerop (gimple_cond_rhs (cond_stmt)))
+           return false;
+         gimple_cond_set_condition (cond_stmt, NE_EXPR, ops[0],
+                                    build_zero_cst (TREE_TYPE (ops[0])));
+       }
       else if (code == INTEGER_CST)
        {
          if (integer_zerop (ops[0]))

Reply via email to