From: Marek Polacek <polacek@redhat.com>
To: Eric Botcazou <ebotcazou@adacore.com>
Cc: gcc-patches@gcc.gnu.org, Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PATCH] Don't bypass blocks with multiple latch edges (PR middle-end/54838)
Date: Sat, 01 Dec 2012 16:18:00 -0000 [thread overview]
Message-ID: <20121201161826.GH10621@redhat.com> (raw)
In-Reply-To: <3679567.118qcDcHed@polaris>
On Fri, Nov 30, 2012 at 11:00:28PM +0100, Eric Botcazou wrote:
> OK, let's tweak the patch as follows:
> 1) when current_loops is not NULL, we compute may_be_loop_header and whether
> the loop has more than 1 latch edge exactly,
> 2) when current_loops is NULL, we use your above method to do the same,
> 3) once this is done, we return from the function before entering the loop if
> this is a (potential) header with more than 1 (potential) latch edge. The
> comment can say that threading through a loop header with more than 1 latch
> edge is delicate and cite tree-threadupdate.c:thread_through_loop_header.
Like this? Regtested/bootstrapped on x86_64-linux, ok for trunk?
2012-12-01 Marek Polacek <polacek@redhat.com>
PR middle-end/54838
* cprop.c (bypass_block): Determine number of latches. Return
when there is more than one latch edge.
* gcc.dg/pr54838.c: New test.
--- gcc/cprop.c.mp 2012-11-29 15:49:53.120524295 +0100
+++ gcc/cprop.c 2012-12-01 16:14:59.387335461 +0100
@@ -1510,13 +1510,28 @@ bypass_block (basic_block bb, rtx setcc,
if (note)
find_used_regs (&XEXP (note, 0), NULL);
- may_be_loop_header = false;
- FOR_EACH_EDGE (e, ei, bb->preds)
- if (e->flags & EDGE_DFS_BACK)
- {
- may_be_loop_header = true;
- break;
- }
+ /* Determine whether there are more latch edges. Threading through
+ a loop header with more than one latch is delicate, see e.g.
+ tree-ssa-threadupdate.c:thread_through_loop_header. */
+ if (current_loops)
+ {
+ may_be_loop_header = bb == bb->loop_father->header;
+ if (may_be_loop_header
+ && bb->loop_father->latch == NULL)
+ return 0;
+ }
+ else
+ {
+ unsigned n_back_edges = 0;
+ FOR_EACH_EDGE (e, ei, bb->preds)
+ if (e->flags & EDGE_DFS_BACK)
+ n_back_edges++;
+
+ may_be_loop_header = n_back_edges > 0;
+
+ if (n_back_edges > 1)
+ return 0;
+ }
change = 0;
for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); )
--- gcc/testsuite/gcc.dg/pr54838.c.mp 2012-11-26 14:48:43.783980854 +0100
+++ gcc/testsuite/gcc.dg/pr54838.c 2012-11-26 14:49:51.051158719 +0100
@@ -0,0 +1,24 @@
+/* PR middle-end/54838 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-forward-propagate -ftracer" } */
+
+void bar (void);
+
+void
+foo (void *b, int *c)
+{
+again:
+ switch (*c)
+ {
+ case 1:
+ if (!b)
+ {
+ bar ();
+ return;
+ }
+ goto again;
+ case 3:
+ if (!b)
+ goto again;
+ }
+}
Marek
next prev parent reply other threads:[~2012-12-01 16:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-26 14:28 Marek Polacek
2012-11-28 9:55 ` Eric Botcazou
2012-11-28 18:39 ` Marek Polacek
2012-11-29 8:34 ` Richard Biener
2012-11-29 8:57 ` Steven Bosscher
2012-11-29 9:35 ` Richard Biener
2012-11-29 15:39 ` Marek Polacek
2012-11-29 15:42 ` Marek Polacek
2012-11-29 15:51 ` Steven Bosscher
2012-11-29 16:56 ` Marek Polacek
2012-11-29 17:45 ` Eric Botcazou
2012-11-30 9:02 ` Richard Biener
2012-11-30 16:28 ` Marek Polacek
2012-11-30 22:01 ` Eric Botcazou
2012-11-30 22:33 ` Eric Botcazou
2012-12-01 16:18 ` Marek Polacek [this message]
2012-12-02 10:06 ` Eric Botcazou
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=20121201161826.GH10621@redhat.com \
--to=polacek@redhat.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.com \
/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: link
Be 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).