From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E1BDE3858C60; Tue, 9 Nov 2021 07:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1BDE3858C60 From: "sebastian.huber@embedded-brains.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103150] New: Structure return is not optimized on 32-bit targets Date: Tue, 09 Nov 2021 07:18:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sebastian.huber@embedded-brains.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 07:18:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103150 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 =3D 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=20 .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=20 .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 =3D 0, pretend =3D 0, frame =3D 32 @ frame_needed =3D 0, uses_anonymous_args =3D 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=20 .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)"=