[Bug tree-optimization/116835] [13/14/15/16 Regression] phiprop will prop back into a loop

2025-11-24 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|13.5|16.0

--- Comment #18 from Andrew Pinski  ---
Fixed on the trunk for GCC 16; since nobody has seen this wrong code for over
10 years and I only found it while improving the pass and only with weak so
closing as fixed.

[Bug tree-optimization/116835] [13/14/15/16 Regression] phiprop will prop back into a loop

2025-11-24 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835

--- Comment #17 from GCC Commits  ---
The trunk branch has been updated by Andrew Pinski :

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

commit r16-5557-gf726857ded73f5692280a33be958ce75ffc54b18
Author: Andrew Pinski 
Date:   Thu Nov 20 20:43:16 2025 -0800

phiprop: Avoid proping loads into loops [PR116835]

This is v2 which uses Richi's code.
This amends "the post-dominance check to deal with
SSA cycles [...]. We need to constrain the load to
be in the same or a subloop (use
flow_loop_nested_p, not loop depth) or in the same
BB when either the load or the PHI is in an irreducible region."
(as described by Richard).

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/116835

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Admend the
post-dom check to deal with ssa cycles.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr116835.c: New test.
* gcc.dg/tree-ssa/phiprop-6.c: New test.
* gcc.dg/tree-ssa/phiprop-7.c: New test.

Signed-off-by: Andrew Pinski 
Co-authored-by: Richard Biener 

[Bug tree-optimization/116835] [13/14/15/16 Regression] phiprop will prop back into a loop

2025-11-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835

--- Comment #16 from Andrew Pinski  ---
I have a set of patches which improve phiprop and also fix this one (it is
richi's fix really).

[Bug tree-optimization/116835] [13/14/15/16 Regression] phiprop will prop back into a loop

2025-11-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835

Andrew Pinski  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=91812

--- Comment #15 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #14)
> From
> https://inbox.sourceware.org/gcc-patches/
> CAFiYyc2LbQDLD=ukntp5yvauttyndnlm9vv-13uge2yp+wg...@mail.gmail.com/ :
> 
> ```
> We need to constrain the load to be in the same or a subloop (use
> flow_loop_nested_p,
> not loop depth) or in the same BB when either the load or the PHI is
> in an irreducible region.
> 
> >
> > +  /* Only replace loads in blocks are in the same loop
> > +are inside an deeper loop.  This is to make sure not
> > +to prop back into the loop.  */
> > +  if (bb_loop_depth (gimple_bb (use_stmt)) < bb_loop_depth (bb))
> > +   continue;
> > +
> 
> So something like
> 
>/* Amend the post-dominance check for SSA cycles, we need to
>   make sure each PHI result value is dereferenced.  */
>if (!(gimple_bb (use_stmt) == bb
>  || (!(bb->flags & BB_IRREDUCIBLE_LOOP)
> && !(gimple_bb (use_stmt)->flags & BB_IRREDUCIBLE_LOOP)
> && (bb->loop_father == gimple_bb (use_stmt)->loop_father
>   || flow_loop_nested_p (bb->loop_father, gimple_bb
> (use_stmt)->loop_father)
> continue;
> ```

Oh this came up in PR 91812 comment #6 too.
Of course we have loop info now always :).

[Bug tree-optimization/116835] [13/14/15/16 Regression] phiprop will prop back into a loop

2025-11-17 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835

--- Comment #14 from Andrew Pinski  ---
From
https://inbox.sourceware.org/gcc-patches/CAFiYyc2LbQDLD=ukntp5yvauttyndnlm9vv-13uge2yp+wg...@mail.gmail.com/
:

```
We need to constrain the load to be in the same or a subloop (use
flow_loop_nested_p,
not loop depth) or in the same BB when either the load or the PHI is
in an irreducible region.

>
> +  /* Only replace loads in blocks are in the same loop
> +are inside an deeper loop.  This is to make sure not
> +to prop back into the loop.  */
> +  if (bb_loop_depth (gimple_bb (use_stmt)) < bb_loop_depth (bb))
> +   continue;
> +

So something like

   /* Amend the post-dominance check for SSA cycles, we need to
  make sure each PHI result value is dereferenced.  */
   if (!(gimple_bb (use_stmt) == bb
 || (!(bb->flags & BB_IRREDUCIBLE_LOOP)
&& !(gimple_bb (use_stmt)->flags & BB_IRREDUCIBLE_LOOP)
&& (bb->loop_father == gimple_bb (use_stmt)->loop_father
  || flow_loop_nested_p (bb->loop_father, gimple_bb
(use_stmt)->loop_father)
continue;
```

[Bug tree-optimization/116835] [13/14/15/16 Regression] phiprop will prop back into a loop

2025-07-11 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|12.5|13.5

--- Comment #13 from Richard Biener  ---
GCC 12 branch is being closed.