public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lh_mouse at 126 dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/110247] New: suboptimal code about `no_caller_saved_registers` on caller side
Date: Wed, 14 Jun 2023 06:49:00 +0000	[thread overview]
Message-ID: <bug-110247-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110247
           Summary: suboptimal code about `no_caller_saved_registers` on
                    caller side
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lh_mouse at 126 dot com
  Target Milestone: ---

Given:
(https://gcc.godbolt.org/z/xevzx56Y5)

```
int complex(int x, int y)
  __attribute__((__no_caller_saved_registers__));

int test(int x, int y, int z)
  {
    return complex(x, y) + complex(y, z) + complex(z, x);
  }
```


My understanding is that `__no_caller_saved_registers__` says no register will
be clobbered by `complex`, so it is not necessary for GCC to establish a stack
frame and push arguments there. This is gonna help a lot if the function will
be inlined.


Clang generates much better assembly but I wonder whether it is valid to assume
that arguments registers are also preserved, like

```
test:
  push rcx            ; align %rsp
                      ; %edi := x, %esi = y, %edx = z
  call complex        ;
  mov ecx, eax        ; %ecx = complex(x, y)
  xchg edi, esi       ; %edi = y
  xchg esi, edx       ; %esi = z, %edx = x
  call complex        ;
  add ecx, eax        ; %ecx += complex(y, z)
  mov edi, esi        ; %edi = z
  mov esi, edx        ; %esi = x
  call complex        ;
  add eax, ecx        ; %eax = %ecx + complex(z, x)
  pop rcx
  ret
```

             reply	other threads:[~2023-06-14  6:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14  6:49 lh_mouse at 126 dot com [this message]
2023-06-14 16:53 ` [Bug target/110247] " pinskia at gcc dot gnu.org
2023-06-15  3:52 ` lh_mouse at 126 dot com

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-110247-4@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).