loop-invariant: Don't move cold bb instructions to preheader in RTL
gcc/ChangeLog: 2021-12-30 Xionghu Luo <luoxhu@linux.ibm.com> * loop-invariant.c (find_invariants_bb): Check profile count before motion. (find_invariants_body): Add argument. gcc/testsuite/ChangeLog: 2021-12-30 Xionghu Luo <luoxhu@linux.ibm.com> * gcc.dg/loop-invariant-2.c: New.
This commit is contained in:
parent
be475aa0aa
commit
dc1969dab3
|
@ -1183,9 +1183,21 @@ find_invariants_insn (rtx_insn *insn, bool always_reached, bool always_executed)
|
|||
call. */
|
||||
|
||||
static void
|
||||
find_invariants_bb (basic_block bb, bool always_reached, bool always_executed)
|
||||
find_invariants_bb (class loop *loop, basic_block bb, bool always_reached,
|
||||
bool always_executed)
|
||||
{
|
||||
rtx_insn *insn;
|
||||
basic_block preheader = loop_preheader_edge (loop)->src;
|
||||
|
||||
/* Don't move insn of cold BB out of loop to preheader to reduce calculations
|
||||
and register live range in hot loop with cold BB. */
|
||||
if (!always_executed && preheader->count > bb->count)
|
||||
{
|
||||
if (dump_file)
|
||||
fprintf (dump_file, "Don't move invariant from bb: %d out of loop %d\n",
|
||||
bb->index, loop->num);
|
||||
return;
|
||||
}
|
||||
|
||||
FOR_BB_INSNS (bb, insn)
|
||||
{
|
||||
|
@ -1214,8 +1226,7 @@ find_invariants_body (class loop *loop, basic_block *body,
|
|||
unsigned i;
|
||||
|
||||
for (i = 0; i < loop->num_nodes; i++)
|
||||
find_invariants_bb (body[i],
|
||||
bitmap_bit_p (always_reached, i),
|
||||
find_invariants_bb (loop, body[i], bitmap_bit_p (always_reached, i),
|
||||
bitmap_bit_p (always_executed, i));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -fdump-rtl-loop2_invariant" } */
|
||||
|
||||
volatile int x;
|
||||
void
|
||||
bar (int, char *, char *);
|
||||
void
|
||||
foo (int *a, int n, int k)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (__builtin_expect (x, 0))
|
||||
bar (k / 5, "one", "two");
|
||||
a[i] = k;
|
||||
}
|
||||
}
|
||||
|
||||
/* { dg-final { scan-rtl-dump "Don't move invariant from bb: .*out of loop" "loop2_invariant" } } */
|
Loading…
Reference in New Issue