public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement
Date: Fri, 04 Jun 2021 21:38:08 +0000	[thread overview]
Message-ID: <bug-65412-4-y89YxrMOha@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65412-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65412

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |10.0
   Last reconfirmed|2015-12-28 00:00:00         |2021-6-4

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>From *.iftoswitch on the trunk:
;;  Canonical GIMPLE case clusters: 0 1 2 3 4 5


So I looked and this is fixed but not for the low if count.
Take:
#define B(y) void f##y(void);
#define B10(y)  B(y##0)  B(y##1)  B(y##2) \
                B(y##3)  B(y##4)  B(y##5) \
                B(y##6)  B(y##7)  B(y##8) \
                B(y##9)
#define B100(y)  B10(y##0)  B10(y##1)  B10(y##2) \
                 B10(y##3)  B10(y##4)  B10(y##5) \
                 B10(y##6)  B10(y##7)  B10(y##8) \
                 B10(y##9)

B10(1)
B100(1)

#define A(y) else if (x == y) f##y();
#define A10(y)  A(y##0) \
                A(y##1) \
                A(y##2) \
                A(y##3) \
                A(y##4) \
                A(y##5) \
                A(y##6) \
                A(y##7) \
                A(y##8) \
                A(y##9)

#define A100(y) A10(y##0)  \
                A10(y##1) \
                A10(y##2) \
                A10(y##3) \
                A10(y##4) \
                A10(y##5) \
                A10(y##6) \
                A10(y##7) \
                A10(y##8) \
                A10(y##9)

void f10(int x)
{
  if (0) ;
  A10(1)
}
void f100(int x)
{
  if (0) ;
  A100(1)
}

--- CUT ----
f100 is converted while f10 is not.  This is a heuristics at work to see if it
is better as a jump table vs if statements.

https://godbolt.org/z/ofWGb5aKn for reference.

Clang decides (I don't know if they lower switches back to if statements) to do
the switch for all cases.

So we can close this as fixed.

  parent reply	other threads:[~2021-06-04 21:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-12 21:33 [Bug tree-optimization/65412] New: missing control flow optimisation skvadrik at gmail dot com
2015-03-13  9:22 ` [Bug tree-optimization/65412] " rguenth at gcc dot gnu.org
2021-06-04 21:38 ` pinskia at gcc dot gnu.org [this message]
2021-06-04 21:41 ` [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement pinskia at gcc dot gnu.org

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=bug-65412-4-y89YxrMOha@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: 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).