public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/57949] New: [powerpc64] Structure parameter alignment issue with vector extensions
@ 2013-07-21 16:30 wschmidt at gcc dot gnu.org
  2013-07-22 16:02 ` [Bug target/57949] " wschmidt at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: wschmidt at gcc dot gnu.org @ 2013-07-21 16:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57949

            Bug ID: 57949
           Summary: [powerpc64] Structure parameter alignment issue with
                    vector extensions
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: ABI, wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wschmidt at gcc dot gnu.org
                CC: bergner at vnet dot ibm.com, dje at gcc dot gnu.org
              Host: powerpc64-*-*
            Target: powerpc64-*-*
             Build: powerpc64-*-*

Created attachment 30533
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30533&action=edit
Generated assembly with -O2 -maltivec

When passing parameters, the 64-bit PowerPC ELF ABI requires:

"Fixed size aggregates and unions passed by value are mapped to as many
doublewords of the parameter save area as the value uses in memory.  Aggregates
and unions are aligned according to their alignment requirements.  This may
result in doublewords being skipped for alignment."

The following demonstrates a case where a structure is currently misaligned in
the parameter save area:

=====
typedef float v4sf __attribute__ ((vector_size (16)));

struct s { long m; v4sf v; };

extern long n;
extern v4sf ve;

void test3 (long d1, long d2, long d3, long d4, long d5, long d6,
            long d7, long d8, long d9, struct s vs) {
  n = vs.m;
  ve = vs.v;
}
=====

Member v of struct s has 16-byte alignment, requiring internal padding of 8
bytes between members m and v.  This is correctly honored.  A struct s should
have 16-byte alignment because it contains a member requiring 16-byte
alignment.  When passing parameters, this apparently is not being honored.

The parameter save area begins at 48(r1).  Accordingly, d9 should be placed at
112(r1).  Alignment padding should require vs to begin at 128(r1).  So vs.m
should be at 128(r1), and vs.v should be at 144(r1).

The attached assembly code (compiled with -O2 -maltivec on
powerpc64-unknown-linux-gnu) shows that vs.m is accessed at 120(r1) and vs.v is
accessed at 136(r1).

If vs.v were to be accessed as a vector with an lvx instruction, we would get
incorrect code because the low-order 4 bits of the address would be ignored,
causing a load from 128(r1).  However, there appears to be code that avoids
this problem by copying the vector member to an aligned stack slot using ld/std
before loading it as a vector.

There is not a problem with local stack variables; so far as I can tell, a
local "struct s" is always aligned correctly.

It's not clear to me without further investigation whether this is a problem
unique to PPC64 or whether it could occur on other targets.  Opening this as a
target-specific bug for now.

Note that we may not be able to change this behavior at this time.  Fixing it
would cause incompatibilities with existing libraries that pass such
structures.  However, such interfaces are probably rare.  It may be worth
fixing this and providing an option to compile with the old behavior, in case
anyone runs into an incompatibility.


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

end of thread, other threads:[~2014-04-04 14:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-21 16:30 [Bug target/57949] New: [powerpc64] Structure parameter alignment issue with vector extensions wschmidt at gcc dot gnu.org
2013-07-22 16:02 ` [Bug target/57949] " wschmidt at gcc dot gnu.org
2013-07-22 16:30 ` wschmidt at gcc dot gnu.org
2013-07-23 17:24 ` wschmidt at gcc dot gnu.org
2013-07-23 20:29 ` wschmidt at gcc dot gnu.org
2013-07-23 20:40 ` joseph at codesourcery dot com
2013-07-31  2:26 ` wschmidt at gcc dot gnu.org
2013-08-14 20:39 ` wschmidt at gcc dot gnu.org
2013-11-15 23:41 ` uweigand at gcc dot gnu.org
2014-04-04 14:05 ` wschmidt 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).