While fixing up how rewrite_to_defined_overflow works, gcc.dg/Wrestrict-22.c started to fail. This is because `d p+ 2` would moved by LIM and then be rewritten not using pointer plus. The rewriting part is correct behavior. It only recently started to be moved out; due to r16-190-g6901d56fea2132. Which has the following comment: ``` When we run before PRE and PRE is active hoist all expressions since PRE would do so anyway and we can preserve range info but PRE cannot. ``` This is not true if hoisting past the always executed point; so, instead of hoisting these statements all the way out of the max loops, take into account the always executed loop too.
Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-loop-im.cc (compute_invariantness): Hoist to the always executed point if ignorning the cost. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> --- gcc/tree-ssa-loop-im.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index a3ca5af3e3e..b7f9f9befa5 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -1241,12 +1241,24 @@ compute_invariantness (basic_block bb) lim_data->cost); } - if (lim_data->cost >= LIM_EXPENSIVE - /* When we run before PRE and PRE is active hoist all expressions - since PRE would do so anyway and we can preserve range info - but PRE cannot. */ - || (flag_tree_pre && !in_loop_pipeline)) + if (lim_data->cost >= LIM_EXPENSIVE) set_profitable_level (stmt); + /* When we run before PRE and PRE is active hoist all expressions + to the always executed loop since PRE would do so anyway + and we can preserve range info while PRE cannot. */ + else if (flag_tree_pre && !in_loop_pipeline + && outermost) + { + class loop *mloop = lim_data->max_loop; + if (loop_depth (outermost) > loop_depth (mloop)) + { + mloop = outermost; + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " constraining to loop depth %d\n\n\n", + loop_depth (mloop)); + } + set_level (stmt, bb->loop_father, mloop); + } } } -- 2.34.1