public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103799] New: switch expansion could be smarter
@ 2021-12-22  7:44 pinskia at gcc dot gnu.org
  2021-12-22  7:44 ` [Bug tree-optimization/103799] " pinskia at gcc dot gnu.org
  2021-12-22  8:56 ` marxin at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103799
           Summary: switch expansion could be smarter
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
auto f(char c)
{
  int t1;
  switch (c)
    {
       case '1':
         t1 = 1;
         break;
       case '2':
         t1 = 2;
         break;
       case '3':
         t1 = 3;
         break;
       case '\0':
         t1 = 4;
         break;
       default:
         t1 = -1;
    }
   return t1;
}


auto f1(char c)
{
  int t1;
  switch (c)
    {
       case '1':
         t1 = 1;
         break;
       case '2':
         t1 = 2;
         break;
       case '3':
         t1 = 3;
         break;
    default:
      if (c == '\0') t1 = 4; else t1 = -1;
    }
   return t1;
}

f1 produces better code than f.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-22  8:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22  7:44 [Bug tree-optimization/103799] New: switch expansion could be smarter pinskia at gcc dot gnu.org
2021-12-22  7:44 ` [Bug tree-optimization/103799] " pinskia at gcc dot gnu.org
2021-12-22  8:56 ` marxin at gcc dot gnu.org

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).