public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "drwowe at yahoo dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/53056] New: bad code generated for ARM NEON with vector types in structs
Date: Fri, 20 Apr 2012 20:16:00 -0000	[thread overview]
Message-ID: <bug-53056-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 53056
           Summary: bad code generated for ARM NEON with vector types in
                    structs
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: drwowe@yahoo.com


Consider the following snippet:

typedef int vi16 __attribute__((vector_size(16*sizeof(int))));

vi16 add(vi16 a, vi16b) {
  return a + b;
}

compile with arm-linux-gnueabi-gcc-4.7 -O2 -march=armv7-a -mhard-float
-mfpu=neon

Some fairly good code is produced:

        sub     sp, sp, #8
        str     r4, [sp, #-4]!
        fstmfdd sp!, {d8, d9, d10, d11, d12, d13}
        add     ip, sp, #52
        add     r4, sp, #116
        vldmia  r4, {d24-d31}
        stmia   ip, {r2, r3}
        vldmia  ip, {d6-d13}
        vadd.i32        q8, q3, q12
        vadd.i32        q9, q4, q13
        vadd.i32        q10, q5, q14
        vadd.i32        q11, q6, q15
        vstmia  r0, {d16-d23}
        fldmfdd sp!, {d8, d9, d10, d11, d12, d13}
        ldmfd   sp!, {r4}
        add     sp, sp, #8
        bx      lr

However, the the vector is embedded in a struct the code generation becomes
awful.

typedef struct A {
  vi16 v;
} A;

vi16 add1(A a, A b) {
  return a.v + b.v;
}

// Same code as add1
vi16 add2(A a, A b) {
  vi16* av = &a.v;
  vi16* bv = &b.v;
  return a.v + b.v;
}

Both add1 and add2 produce the same code:

add1:
        @ args = 128, pretend = 8, frame = 128
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        sub     sp, sp, #8
        sub     sp, sp, #128
        add     r1, sp, #128
        stmia   sp, {r2, r3}
        stmia   r1, {r2, r3}
        ldr     r3, [sp, #192]
        ldr     r2, [r1, #8]
        str     r3, [sp, #64]
        ldr     r3, [sp, #196]
        str     r2, [sp, #8]
        ldr     r2, [r1, #12]
        str     r3, [sp, #68]
        ldr     r3, [sp, #200]
        ... lots and lots of load and store instructions.

But adding an "optimization barrier" to add2 produces similar code to the
original example, by making the compiler "forget" the origin of the pointer.

vi16 add3(A a, A b) {
  vi16* av = &a.v;
  vi16* bv = &b.v;
  asm("" : "+r"(av), "+r"(bv));  // causes good code to be generated.
  return *av + *bv;
}


             reply	other threads:[~2012-04-20 20:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-20 20:16 drwowe at yahoo dot com [this message]
2012-04-20 20:16 ` [Bug target/53056] " drwowe at yahoo dot com
2012-04-20 20:21 ` drwowe at yahoo dot com
2012-04-21 23:37 ` rearnsha at gcc dot gnu.org
2013-08-05 21:42 ` [Bug target/53056] poor " rearnsha at gcc dot gnu.org

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-53056-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).