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

commit a7cdd9b8bc3e05431b7d7cbec12fc23344c28054
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Mon Apr 21 17:27:45 2025 +0200

    Correction régressions transfer_simplify_*

Diff:
---
 gcc/tree-ssa-loop-niter.cc |  7 ++++---
 gcc/tree.cc                | 12 +++++++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 0fa9388594bc..9d352da8b2a0 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -3926,8 +3926,8 @@ do_warn_aggressive_loop_optimizations (class loop *loop,
         known constant bound.  */
       || wi::cmpu (i_bound, wi::to_widest (loop->nb_iterations)) >= 0
       /* And undefined behavior happens unconditionally.  */
-      || !dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (stmt))
-      || loop->latch == gimple_bb (stmt))
+      || !(dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (stmt))
+          || loop->latch == gimple_bb (stmt)))
     return;
 
   edge e = single_exit (loop);
@@ -4004,7 +4004,8 @@ record_estimate (class loop *loop, tree bound, const 
widest_int &i_bound,
 
   /* If statement is executed on every path to the loop latch, we can directly
      infer the upper bound on the # of iterations of the loop.  */
-  if (!dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (at_stmt)))
+  if (!(dominated_by_p (CDI_DOMINATORS, loop->latch, gimple_bb (at_stmt)))
+       || loop->latch == gimple_bb (at_stmt))
     upper = false;
 
   /* Update the number of iteration estimates according to the bound.
diff --git a/gcc/tree.cc b/gcc/tree.cc
index eccfcc89da40..86e6515f9cee 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13058,7 +13058,17 @@ array_ref_up_bound (tree exp)
   /* If there is a domain type and it has an upper bound, use it, substituting
      for a PLACEHOLDER_EXPR as needed.  */
   if (domain_type && TYPE_MAX_VALUE (domain_type))
-    return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
+    {
+      tree val = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), 
exp);
+      if (TREE_OPERAND (exp, 2))
+        return fold_build2_loc (EXPR_LOCATION (exp), PLUS_EXPR,
+                               TREE_TYPE (val), val,
+                               fold_convert_loc (EXPR_LOCATION (exp),
+                                                 TREE_TYPE (val),
+                                                 TREE_OPERAND (exp, 2)));
+      else
+       return val;
+    }
 
   /* Otherwise fail.  */
   return NULL_TREE;

Reply via email to