public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/97856] New: Missed optimization: repeated call
@ 2020-11-16 17:40 miguel.ojeda.sandonis at gmail dot com
  2020-11-17  7:12 ` [Bug rtl-optimization/97856] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: miguel.ojeda.sandonis at gmail dot com @ 2020-11-16 17:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97856
           Summary: Missed optimization: repeated call
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: miguel.ojeda.sandonis at gmail dot com
  Target Milestone: ---

For code such as:

    void f(int);
    void g(int v) {
        switch (v) {
            case 1: f(1);
            case 2: f(2);
            case 3: f(3);
            default: f(4);
        }
    }

GCC generates for e.g. x86_64:

    g(int):
            subq    $8, %rsp
            cmpl    $2, %edi
            je      .L2
            cmpl    $3, %edi
            je      .L3
            cmpl    $1, %edi
            je      .L13
            movl    $4, %edi
            addq    $8, %rsp
            jmp     f(int)
    .L13:
            call    f(int)
    .L2:
            movl    $2, %edi
            call    f(int)
    .L3:
            movl    $3, %edi
            call    f(int)
            movl    $4, %edi
            addq    $8, %rsp
            jmp     f(int)

Repeating the `f(4);` call can be avoided by reordering the cases, reducing
code size.

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

end of thread, other threads:[~2021-09-01  4:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 17:40 [Bug tree-optimization/97856] New: Missed optimization: repeated call miguel.ojeda.sandonis at gmail dot com
2020-11-17  7:12 ` [Bug rtl-optimization/97856] " rguenth at gcc dot gnu.org
2021-09-01  4:41 ` pinskia at gcc dot gnu.org
2021-09-01  4:41 ` pinskia 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).