https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116835
--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> --- 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; ```
