public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Paul Koning <paulkoning@comcast.net>, GCC Development <gcc@gcc.gnu.org>
Subject: Re: Switch statement optimization
Date: Tue, 19 Apr 2022 16:33:37 +0200	[thread overview]
Message-ID: <89297d85-74cb-0833-ed55-41296690be13@suse.cz> (raw)
In-Reply-To: <321638F8-8BF6-4AFC-8434-471B05F6BBFA@comcast.net>

On 4/18/22 16:41, Paul Koning via Gcc wrote:
> In switch statements with dense case values, the typical result is a jump table, which is fast.  If the values are sparse, a tree of compares is generated instead.
> 
> What if nearly all cases are dense but there are a few outliers?  An example appears in the NFS protocol parser, where you get a switch statement with cases for each of the opcode values.  All but one are small integers assigned in sequence, but one is 10044.  So the "sparse" case kicks in and a compare tree is generated for everything.
> 
> I can avoid this by putting in special case code for the 10044 case, then all the rest ends up being a jump table.  That brings up the question if GCC should recognize such scenarios and break up the switch statement into "dense parts" handled by a jump table, leaving the sorting between those as a compare tree.

Hello.

We currently support identification of such dense/interesting groups of case values (we name them clusters).
See e.g. gcc/testsuite/gcc.dg/tree-ssa/switch-1.c where you can have a decision tree that contains
mix of individual cases, jump-tables (JT) and bit-tests (BT).

Can you please share your test-case so that I can analyze it?
You can investigate with -fdump-tree-switchlower1.

Cheers.
Martin

> 
> 	paul
> 


  reply	other threads:[~2022-04-19 14:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18 14:41 Paul Koning
2022-04-19 14:33 ` Martin Liška [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-07-10 14:48 Joern RENNECKE
2006-07-11 10:03 ` Christian Hildner
2006-07-10  9:39 Christian Hildner
2006-07-10 11:06 ` Ben Elliston

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=89297d85-74cb-0833-ed55-41296690be13@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc@gcc.gnu.org \
    --cc=paulkoning@comcast.net \
    /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).