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>
This commit is contained in:
Andrew Pinski
2025-05-04 19:24:09 +00:00
parent 2c8d632d9e
commit 8335fd561f

View File

@@ -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);
}
}
}