public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94779] New: Bad optimization of simple switch
@ 2020-04-27  0:40 gabravier at gmail dot com
  2020-04-27  4:31 ` [Bug tree-optimization/94779] " marxin at gcc dot gnu.org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: gabravier at gmail dot com @ 2020-04-27  0:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94779
           Summary: Bad optimization of simple switch
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f1(unsigned x)
{
    switch (x)
    {
        case 0:
            return 1;
        case 1:
            return 2;
    }
}

gcc fails to optimize this to `return x + 1`, instead opting for some rather
weird code generation (involving `sbb` on x86). However, adding this :

     if (x >= 2)
        __builtin_unreachable();

at the beginning of the function makes it be optimized properly. Maybe this is
a sign of the `x >= 2` condition being always false (due to it leading to UB)
being found too late ?

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

end of thread, other threads:[~2021-08-16 12:39 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  0:40 [Bug tree-optimization/94779] New: Bad optimization of simple switch gabravier at gmail dot com
2020-04-27  4:31 ` [Bug tree-optimization/94779] " marxin at gcc dot gnu.org
2020-04-27  4:35 ` gabravier at gmail dot com
2020-04-27  4:38 ` gabravier at gmail dot com
2020-04-27  4:46 ` marxin at gcc dot gnu.org
2020-04-27  5:47 ` gabravier at gmail dot com
2020-04-27  6:15 ` gabravier at gmail dot com
2020-04-27  6:47 ` rguenth at gcc dot gnu.org
2020-04-27  6:51 ` gabravier at gmail dot com
2020-05-06 15:08 ` jakub at gcc dot gnu.org
2020-05-06 15:12 ` marxin at gcc dot gnu.org
2020-05-06 15:24 ` jakub at gcc dot gnu.org
2020-12-15 13:35 ` jakub at gcc dot gnu.org
2020-12-15 15:02 ` amacleod at redhat dot com
2020-12-17 13:36 ` marxin at gcc dot gnu.org
2020-12-17 13:41 ` jakub at gcc dot gnu.org
2020-12-17 13:57 ` marxin at gcc dot gnu.org
2020-12-17 14:07 ` jakub at gcc dot gnu.org
2020-12-17 16:38 ` amacleod at redhat dot com
2020-12-18 12:07 ` marxin at gcc dot gnu.org
2020-12-18 12:18 ` jakub at gcc dot gnu.org
2020-12-18 12:30 ` marxin at gcc dot gnu.org
2020-12-18 14:35 ` amacleod at redhat dot com
2021-08-16 12:39 ` 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).