public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "brooks at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/56335] New: Optimization assumes __attribute__((aligned(N))) always works.
Date: Fri, 15 Feb 2013 06:31:00 -0000	[thread overview]
Message-ID: <bug-56335-4@http.gcc.gnu.org/bugzilla/> (raw)


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

             Bug #: 56335
           Summary: Optimization assumes __attribute__((aligned(N)))
                    always works.
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: brooks@gcc.gnu.org


Created attachment 29460
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29460
(Generated assembly code)

As recently discussed in bug 56334, the documentation for
__attribute__((aligned(N))) notes that it does not necessarily produce the
requested alignment for static variables: "On many systems, the linker is only
able to arrange for variables to be aligned up to a certain maximum alignment.
(For some linkers, the maximum supported alignment may be very very small.)"

However, it appears that GCC itself has not read this documentation!

Consider this trivial .c file:

  #define N (1<<27)
  static float __attribute__((aligned(N))) a[128];
  void foo() 
  {
    if ((unsigned long) a % N == 0)
      bar(a);
    else
      bar_unaligned(a);
  }

We are not actually going to get this static array aligned to a 128-megabyte
alignment (especially if this goes into a shared library), but GCC nonetheless
eliminates the branch and possible call to bar_unaligned.  See, for instance,
the output of this command line (where align5.c is the above file):

  i686-pc-linux-gnu-gcc -O2 -S -fpic align5.c -o align5.s

There is clearly no reference to bar_unaligned in the generated assembly,
indicating that it has been optimized out.


             reply	other threads:[~2013-02-15  6:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15  6:31 brooks at gcc dot gnu.org [this message]
2013-02-15  9:28 ` [Bug c/56335] " rguenth at gcc dot gnu.org
2013-02-15 15:47 ` joseph at codesourcery dot com
2024-04-09  4:45 ` pinskia 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-56335-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).