From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16252 invoked by alias); 2 Aug 2013 22:35:27 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 16180 invoked by uid 48); 2 Aug 2013 22:35:24 -0000 From: "bernd.edlinger at hotmail dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/58065] New: ARM MALLOC_ABI_ALIGNMENT is wrong Date: Fri, 02 Aug 2013 22:35:00 -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: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bernd.edlinger at hotmail dot de X-Bugzilla-Status: UNCONFIRMED 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 cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-08/txt/msg00162.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58065 Bug ID: 58065 Summary: ARM MALLOC_ABI_ALIGNMENT is wrong Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: bernd.edlinger at hotmail dot de Target: arm*-*-* the ARM target architecture does not define the MALLOC_ABI_ALIGNMENT, therefore the default is used as BITS_PER_WORD, 32 in this case. This produces sometimes suboptimal code, because the front-end assumes that the function malloc() returns only word-aligned pointers, which is likely wrong. I have not found any specific requirements on the malloc alignment in the AAPCS document at http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf but I believe that the intention is to align everything including stack pointers to 8 bytes. Therefore I would suggest the attached patch which defines MALLOC_ABI_ALIGNMENT as BIGGEST_ALIGNMENT, which is 64 bits. As a proof that this has indeed some subtle influence on the generated code I attach a test case. The function foo is called by bar, and bar uses malloc to allocate the memory, with compiler options "-O3 -g0 -mfpu=neon -mfloat-abi=softfp" the function foo is inlined into bar, but the inlined version does not use vstr instructions any more, because the front-end does assume that malloc returns 4 byte aligned memory. If that was really true, foo must fail, if it is called without inlining. Therefore this code is just clumsy and less optimal than it could be.