public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3753] tree-ssa-sink: do not touch calls that return twice Date: Mon, 7 Nov 2022 13:01:40 +0000 (GMT) [thread overview] Message-ID: <20221107130140.0925F385829A@sourceware.org> (raw) https://gcc.gnu.org/g:5d060d8b0477ff4911f41c816281daaa24b41a13 commit r13-3753-g5d060d8b0477ff4911f41c816281daaa24b41a13 Author: Alexander Monakov <amonakov@ispras.ru> Date: Mon Nov 7 15:33:01 2022 +0300 tree-ssa-sink: do not touch calls that return twice Avoid moving pure/const calls that may return twice in tree-ssa-sink: properly redirecting the associated abnormal edge is non-trivial. gcc/ChangeLog: PR tree-optimization/107505 * tree-ssa-sink.cc (statement_sink_location): Additionally reject ECF_RETURNS_TWICE calls. gcc/testsuite/ChangeLog: PR tree-optimization/107505 * gcc.dg/pr107505.c: New test. Diff: --- gcc/testsuite/gcc.dg/pr107505.c | 26 ++++++++++++++++++++++++++ gcc/tree-ssa-sink.cc | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/pr107505.c b/gcc/testsuite/gcc.dg/pr107505.c new file mode 100644 index 00000000000..01270eac91c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr107505.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-guess-branch-probability" } */ + +int n; + +void +bar (void); + +__attribute__ ((noinline, returns_twice)) int +zero (void) +{ + return 0; +} + +void +foo (void) +{ + int a = zero (); + + for (n = 0; n < 2; ++n) + { + } + + if (a) + bar (); +} diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc index 9213052017a..eb7c2e6819c 100644 --- a/gcc/tree-ssa-sink.cc +++ b/gcc/tree-ssa-sink.cc @@ -263,12 +263,13 @@ statement_sink_location (gimple *stmt, basic_block frombb, *zero_uses_p = false; - /* We only can sink assignments and non-looping const/pure calls. */ + /* We only can sink assignments and const/pure calls that are guaranteed + to return exactly once. */ int cf; if (!is_gimple_assign (stmt) && (!is_gimple_call (stmt) || !((cf = gimple_call_flags (stmt)) & (ECF_CONST|ECF_PURE)) - || (cf & ECF_LOOPING_CONST_OR_PURE))) + || (cf & (ECF_LOOPING_CONST_OR_PURE|ECF_RETURNS_TWICE)))) return false; /* We only can sink stmts with a single definition. */
reply other threads:[~2022-11-07 13:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221107130140.0925F385829A@sourceware.org \ --to=amonakov@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).