public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/103150] New: Structure return is not optimized on 32-bit targets
@ 2021-11-09  7:18 sebastian.huber@embedded-brains.de
  2021-11-09  7:22 ` [Bug target/103150] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sebastian.huber@embedded-brains.de @ 2021-11-09  7:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103150
           Summary: Structure return is not optimized on 32-bit targets
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastian.huber@embedded-brains.de
  Target Milestone: ---

Consider the following test case:

struct timespec {
  long long tv_sec;
  long tv_nsec;
};

void  a(struct timespec *);
void  b(struct timespec *);

static inline struct timespec c(void)
{
  struct timespec t;

  a(&t);

  return t;
}

void f(void)
{
  struct timespec ts = c();
  b(&ts);
}

For the 64-bit targets (I checked x86_64, aarch64, riscv, powerpc) this is
optimized to:

aarch64-rtems6-gcc -O2 -S -o - getptr.c 
        .arch armv8-a
        .file   "getptr.c"
        .text
        .align  2
        .p2align 4,,11
        .global f
        .type   f, %function
f:
        stp     x29, x30, [sp, -32]!
        mov     x29, sp
        add     x0, sp, 16
        bl      a
        add     x0, sp, 16
        bl      b
        ldp     x29, x30, [sp], 32
        ret
        .size   f, .-f
        .ident  "GCC: (GNU) 10.3.1 20210409 (RTEMS 6, RSB
889cf95db0122bd1a6b21598569620c40ff2069d, Newlib eb03ac1)"

The pointer used to get the data from a() is directly passed to the consumer
b().

However, for 32-bit targets this test case seems to be not optimized and the
data is copied on the stack frame. For example:

arm-rtems6-gcc -O2 -S -o - getptr.c 
        .cpu arm7tdmi
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 2
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .file   "getptr.c"
        .text
        .align  2
        .global f
        .arch armv4t
        .syntax unified
        .arm
        .fpu softvfp
        .type   f, %function
f:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 32
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r4, lr}
        sub     sp, sp, #32
        add     r4, sp, #16
        mov     r0, r4
        bl      a
        mov     ip, sp
        ldm     r4, {r0, r1, r2, r3}
        stm     ip, {r0, r1, r2, r3}
        mov     r0, ip
        bl      b
        add     sp, sp, #32
        @ sp needed
        pop     {r4, lr}
        bx      lr
        .size   f, .-f
        .ident  "GCC: (GNU) 10.3.1 20210409 (RTEMS 6, RSB
889cf95db0122bd1a6b21598569620c40ff2069d, Newlib eb03ac1)"

riscv-rtems6-gcc -O2 -S -o - getptr.c 
        .file   "getptr.c"
        .option nopic
        .text
        .align  1
        .globl  f
        .type   f, @function
f:
        addi    sp,sp,-48
        addi    a0,sp,16
        sw      ra,44(sp)
        call    a
        lw      a5,16(sp)
        mv      a0,sp
        sw      a5,0(sp)
        lw      a5,20(sp)
        sw      a5,4(sp)
        lw      a5,24(sp)
        sw      a5,8(sp)
        lw      a5,28(sp)
        sw      a5,12(sp)
        call    b
        lw      ra,44(sp)
        addi    sp,sp,48
        jr      ra
        .size   f, .-f
        .ident  "GCC: (GNU) 10.3.1 20210409 (RTEMS 6, RSB
889cf95db0122bd1a6b21598569620c40ff2069d, Newlib eb03ac1)"

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

* [Bug target/103150] Structure return is not optimized on 32-bit targets
  2021-11-09  7:18 [Bug target/103150] New: Structure return is not optimized on 32-bit targets sebastian.huber@embedded-brains.de
@ 2021-11-09  7:22 ` pinskia at gcc dot gnu.org
  2021-11-09  7:25 ` pinskia at gcc dot gnu.org
  2021-11-09 20:29 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-09  7:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is a few bugs filed about this same issue, See PR 101926 (this might be a
dup of one of those).

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

* [Bug target/103150] Structure return is not optimized on 32-bit targets
  2021-11-09  7:18 [Bug target/103150] New: Structure return is not optimized on 32-bit targets sebastian.huber@embedded-brains.de
  2021-11-09  7:22 ` [Bug target/103150] " pinskia at gcc dot gnu.org
@ 2021-11-09  7:25 ` pinskia at gcc dot gnu.org
  2021-11-09 20:29 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-09  7:25 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |99128

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely a dup of bug 99128.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99128
[Bug 99128] Stack used for concatenating values when returning struct by
register

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

* [Bug target/103150] Structure return is not optimized on 32-bit targets
  2021-11-09  7:18 [Bug target/103150] New: Structure return is not optimized on 32-bit targets sebastian.huber@embedded-brains.de
  2021-11-09  7:22 ` [Bug target/103150] " pinskia at gcc dot gnu.org
  2021-11-09  7:25 ` pinskia at gcc dot gnu.org
@ 2021-11-09 20:29 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-09 20:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

end of thread, other threads:[~2021-11-09 20:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09  7:18 [Bug target/103150] New: Structure return is not optimized on 32-bit targets sebastian.huber@embedded-brains.de
2021-11-09  7:22 ` [Bug target/103150] " pinskia at gcc dot gnu.org
2021-11-09  7:25 ` pinskia at gcc dot gnu.org
2021-11-09 20:29 ` 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).