public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pskocik at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/109766] New: Passing doubles through the stack generates a stack adjustment pear each such argument at -Os/-Oz.
Date: Mon, 08 May 2023 09:06:20 +0000	[thread overview]
Message-ID: <bug-109766-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 109766
           Summary: Passing doubles through the stack generates a stack
                    adjustment pear each such argument at -Os/-Oz.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pskocik at gmail dot com
  Target Milestone: ---

/*
 Passing doubles through the stack generates a stack adjustment pear each such
argument at -Os/-Oz.
 These stack adjustments are only coalesced at -O1/-O2/-O3, leaving -Os/-Oz
with larger code.
*/
#define $expr(...) (__extension__({__VA_ARGS__;}))
#define $regF0 $expr(register double x __asm("xmm0"); x)
#define $regF1 $expr(register double x __asm("xmm1"); x)
#define $regF2 $expr(register double x __asm("xmm2"); x)
#define $regF3 $expr(register double x __asm("xmm3"); x)
#define $regF4 $expr(register double x __asm("xmm4"); x)
#define $regF5 $expr(register double x __asm("xmm5"); x)
#define $regF6 $expr(register double x __asm("xmm6"); x)
#define $regF7 $expr(register double x __asm("xmm7"); x)

void func(char const*Fmt, ...);
void callfunc(char const*Fmt, double D0, double D1, double D2, double D3,
double D4, double D5, double D6, double D7){
    func(Fmt,$regF0,$regF1,$regF2,$regF3,$regF4,$regF5,$regF6,$regF7,
            D0,D1,D2,D3,D4,D5,D6,D7);
/*
//gcc @ -Os/-Oz
0000000000000000 <callfunc>:
   0:   50                      push   %rax
   1:   b0 08                   mov    $0x8,%al
   3:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
   8:   66 0f d6 3c 24          movq   %xmm7,(%rsp)
   d:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  12:   66 0f d6 34 24          movq   %xmm6,(%rsp)
  17:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  1c:   66 0f d6 2c 24          movq   %xmm5,(%rsp)
  21:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  26:   66 0f d6 24 24          movq   %xmm4,(%rsp)
  2b:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  30:   66 0f d6 1c 24          movq   %xmm3,(%rsp)
  35:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  3a:   66 0f d6 14 24          movq   %xmm2,(%rsp)
  3f:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  44:   66 0f d6 0c 24          movq   %xmm1,(%rsp)
  49:   48 8d 64 24 f8          lea    -0x8(%rsp),%rsp
  4e:   66 0f d6 04 24          movq   %xmm0,(%rsp)
  53:   e8 00 00 00 00          callq  58 <callfunc+0x58>
                        54: R_X86_64_PLT32      func-0x4
  58:   48 83 c4 48             add    $0x48,%rsp
  5c:   c3                      retq
$sz(callfunc)=93

//clang @ -Os/-Oz
0000000000000000 <callfunc>:
   0:   48 83 ec 48             sub    $0x48,%rsp
   4:   f2 0f 11 7c 24 38       movsd  %xmm7,0x38(%rsp)
   a:   f2 0f 11 74 24 30       movsd  %xmm6,0x30(%rsp)
  10:   f2 0f 11 6c 24 28       movsd  %xmm5,0x28(%rsp)
  16:   f2 0f 11 64 24 20       movsd  %xmm4,0x20(%rsp)
  1c:   f2 0f 11 5c 24 18       movsd  %xmm3,0x18(%rsp)
  22:   f2 0f 11 54 24 10       movsd  %xmm2,0x10(%rsp)
  28:   f2 0f 11 4c 24 08       movsd  %xmm1,0x8(%rsp)
  2e:   f2 0f 11 04 24          movsd  %xmm0,(%rsp)
  33:   b0 08                   mov    $0x8,%al
  35:   e8 00 00 00 00          callq  3a <callfunc+0x3a>
                        36: R_X86_64_PLT32      func-0x4
  3a:   48 83 c4 48             add    $0x48,%rsp
  3e:   c3                      retq   
$sz(callfunc)=63


//gcc @ -O1
0000000000000000 <callfunc>:
   0:   48 83 ec 48             sub    $0x48,%rsp
   4:   f2 0f 11 7c 24 38       movsd  %xmm7,0x38(%rsp)
   a:   f2 0f 11 74 24 30       movsd  %xmm6,0x30(%rsp)
  10:   f2 0f 11 6c 24 28       movsd  %xmm5,0x28(%rsp)
  16:   f2 0f 11 64 24 20       movsd  %xmm4,0x20(%rsp)
  1c:   f2 0f 11 5c 24 18       movsd  %xmm3,0x18(%rsp)
  22:   f2 0f 11 54 24 10       movsd  %xmm2,0x10(%rsp)
  28:   f2 0f 11 4c 24 08       movsd  %xmm1,0x8(%rsp)
  2e:   f2 0f 11 04 24          movsd  %xmm0,(%rsp)
  33:   b8 08 00 00 00          mov    $0x8,%eax
  38:   e8 00 00 00 00          callq  3d <callfunc+0x3d>
                        39: R_X86_64_PLT32      func-0x4
  3d:   48 83 c4 48             add    $0x48,%rsp
  41:   c3                      retq   
$sz(callfunc)=66
*/
}

https://godbolt.org/z/d8T3hxqWK

             reply	other threads:[~2023-05-08  9:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08  9:06 pskocik at gmail dot com [this message]
2023-05-08 13:51 ` [Bug middle-end/109766] Passing doubles through the stack generates a stack adjustment per " sjames at gcc dot gnu.org
2023-05-08 16:28 ` roger at nextmovesoftware dot com
2023-06-16  8:47 ` roger at nextmovesoftware 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-109766-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).