Projects
Mega:23.03
gcc
_service:tar_scm:0037-Backport-loop-invariant-D...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:0037-Backport-loop-invariant-Don-t-move-cold-bb-instructi.patch of Package gcc
From 897d637aec3b077eb9ef95b2f4a5f7656e36ebd6 Mon Sep 17 00:00:00 2001 From: benniaobufeijiushiji <linda7@huawei.com> Date: Wed, 15 Jun 2022 11:33:03 +0800 Subject: [PATCH 03/12] [Backport] loop-invariant: Don't move cold bb instructions to preheader in RTL Reference: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=dc1969dab392661cdac1170bbb8c9f83f388580d When inner loop is unlikely to execute, loop invariant motion would move cold instrcutions to a hotter loop. This patch adds profile count checking to fix the problem. --- gcc/loop-invariant.c | 17 ++++++++++++++--- gcc/testsuite/gcc.dg/loop-invariant-2.c | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/loop-invariant-2.c diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 37ae6549e..24b9bcb11 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -1184,9 +1184,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) { @@ -1215,8 +1227,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)); } diff --git a/gcc/testsuite/gcc.dg/loop-invariant-2.c b/gcc/testsuite/gcc.dg/loop-invariant-2.c new file mode 100644 index 000000000..df3d84585 --- /dev/null +++ b/gcc/testsuite/gcc.dg/loop-invariant-2.c @@ -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" } } */ -- 2.27.0.windows.1
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2