This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR25413 - data alignment question


Given a pointer to type T - when can we assume that the data pointed to is
naturally aligned (aligned on the size of the type T)?

      The vectorizer currently works under the assumption that all data is
naturally aligned. At least one place where this may result in generation
of wrong code by the vectorizer is when we peel the first few iterations of
a loop in order to align a data-reference in the loop (this is what happens
in PR25413).

To fix this we can distinguish between two cases:

1. The misalignment of the dataref can be computed at compile time, in
which case it's possible to figure out at compile time if the data is not
naturally aligned (see testcase recently committed by Devang to apple-ppc
branch:
http://gcc.gnu.org/viewcvs/branches/apple-local-200502-branch/gcc/testsuite/gcc.dg/vect/vect-align-1.c?rev=108214&view=markup
). In this case, we can avoid using loop-peeling to force the dataref's
alignment.

2. The misalignment of the dataref cannot be computed at compile time
(e.g., a pointer is passed as an argument to a function). In this
situation, are there cases in which we can still assume/prove that the data
pointed-to is naturally aligned? Which (target dependent) API can be
consulted here? 'get_mode_alignment' on Pentium4 returns 64bit for
DFmode/DImode although data of these modes may reside on an address which
is only 32bit alignd (see testcase in PR25413). Same for TYPE_ALIGN.
BIGGEST_FIELD_ALIGNMENT seems to be the only relevant parameter that
returns 32bit on x86. Since we don't know if a given pointer points to a
field, should we always check for:
      MIN (BIGGEST_FIELD_ALIGNMENT, get_mode_alignment)?
Would that be safe?

In any case, if we can't prove whether data is naturally aligned we can
always (1) avoid peeling, or (2) peel the loop but control the number of
iterations that it will execute using a runtime test (i.e. have it iterate
the entire loop-count if the data is not naturally aligned).
I hope however that we won't have to be that conservative anytime we have a
pointer with unknown alignment (cause this is usually what happens in real
world applications).

So, in short - when can we assume that pointer types have the minimum
alignment required by their underlying type?

thanks,

dorit


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]