diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2025-05-04 19:24:09 +0000 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2025-05-07 14:33:05 +0000 |
commit | 8335fd561fa823d32556512c09dfce44463e8eaa (patch) | |
tree | a7ef13f27564908428dc30d2d244b2c425d2f106 | |
parent | 2c8d632d9ed4e3aeee2156ba17fe631ecbc90dbf (diff) | |
download | gcc-8335fd561fa823d32556512c09dfce44463e8eaa.zip gcc-8335fd561fa823d32556512c09dfce44463e8eaa.tar.gz gcc-8335fd561fa823d32556512c09dfce44463e8eaa.tar.bz2 |
Loop-IM: Hoist (non-expensive) stmts to executed all loop when running before PRE
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_apinski@quicinc.com>
-rw-r--r-- | gcc/tree-ssa-loop-im.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index a3ca5af..b7f9f9b 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); + } } } |