From: Richard Biener <rguenther@suse.de>
To: Peter Bergner <bergner@vnet.ibm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,Bill Schmidt
<wschmidt@linux.vnet.ibm.com>,Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH, v3] Fix PR51513, switch statement with default case containing __builtin_unreachable leads to wild branch
Date: Mon, 08 May 2017 17:57:00 -0000 [thread overview]
Message-ID: <2B12773A-43AF-4223-A006-04DC46B31070@suse.de> (raw)
In-Reply-To: <4b4b12ad-3801-fd6d-0750-d975ba620841@vnet.ibm.com>
On May 8, 2017 6:41:01 PM GMT+02:00, Peter Bergner <bergner@vnet.ibm.com> wrote:
>On 05/03/2017 08:32 AM, Richard Biener wrote:
> > As for Bernhards concern I share this -- please intead make the
> > interface take either a gimple_seq or a gimple_stmt_iterator
> > instead of a basic-block. That makes it more obvious you
> > can't use things like gsi_after_labels. Also I think it's more
> > natural to work backwards as the last stmt in the sequence
> > _has_ to be __builtin_unreachable () and thus checking that first
> > is the cheapest thing to do given that in most cases it will
> > not be __builtin_unreachable () (but a noreturn call or an
> > inifinite loop).
> >
> > Thus, name it gimple_seq_unreachable_p.
>
>So you mean something like the following?
Yes.
>
>/* Returns true if the sequence of statements STMTS only contains
> a call to __builtin_unreachable (). */
>
>bool
>gimple_seq_unreachable_p (gimple_seq stmts)
>{
> gimple_stmt_iterator gsi = gsi_last (stmts);
>
> if (!gimple_call_builtin_p (gsi_stmt (gsi), BUILT_IN_UNREACHABLE))
> return false;
>
> for (gsi_prev (&gsi); !gsi_end_p (gsi); gsi_prev (&gsi))
> {
> gimple *stmt = gsi_stmt (gsi);
> if (gimple_code (stmt) != GIMPLE_LABEL
> && !is_gimple_debug (stmt)
> && !gimple_clobber_p (stmt))
> return false;
> }
> return true;
>}
>
>
>
> > On Wed, 26 Apr 2017, Peter Bergner wrote:
> >> One difference from the last patch is that I am no longer setting
> >> default_label to NULL when we emit a decision tree. I noticed that
> >> the decision tree code seemed to generate slightly better code for
> >> some of my unit tests if I left it alone. This simplified the
> >> patch somewhat by removing the changes to emit_case_nodes().
>[snip]
> >
> > Can you do the gimple_unreachable_bb_p check earlier in
> > expand_case so it covers the emit_case_decision_tree path as well
> > (and verify that works, of course)? So basically right at
> >
> > /* Find the default case target label. */
> > default_label = jump_target_rtx
> > (CASE_LABEL (gimple_switch_default_label (stmt)));
> > edge default_edge = EDGE_SUCC (bb, 0);
> > int default_prob = default_edge->probability;
> >
> > handle this case.
>
>That is what the previous patch did, but as I mention above,
>we generate slightly better code for some test cases (other
>tests seemed to generate the same code) if we don't attempt
>to handle the decision tree case. I'll note that the current
>unpatched compiler already knows how to remove unreachable
>case statement blocks when we expand to a decision tree.
>
>I can add that code back if you think that it will have a
>positive benefit for some test case I haven't tried yet.
>
>Peter
next prev parent reply other threads:[~2017-05-08 17:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-13 0:29 [PATCH] " Peter Bergner
2017-04-13 8:14 ` Richard Biener
2017-04-13 11:07 ` Jakub Jelinek
2017-04-13 20:06 ` Peter Bergner
2017-04-20 8:08 ` Richard Biener
2017-04-20 14:21 ` Peter Bergner
2017-04-27 5:08 ` [PATCH, v3] " Peter Bergner
2017-04-27 12:46 ` Bernhard Reutner-Fischer
2017-04-27 15:16 ` Peter Bergner
2017-05-03 13:43 ` Richard Biener
2017-05-08 16:51 ` Peter Bergner
2017-05-08 17:57 ` Richard Biener [this message]
2017-05-08 18:26 ` Peter Bergner
2017-05-08 20:55 ` Peter Bergner
2017-05-09 7:57 ` Richard Biener
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=2B12773A-43AF-4223-A006-04DC46B31070@suse.de \
--to=rguenther@suse.de \
--cc=bergner@vnet.ibm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=wschmidt@linux.vnet.ibm.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).