PATCH: PR target/38736: [4.4 Regression] -mavx can change the ABI via BIGGEST_ALIGNMENT

H.J. Lu hjl.tools@gmail.com
Wed Jan 7 19:28:00 GMT 2009


On Wed, Jan 7, 2009 at 10:30 AM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> Index: gcc/doc/extend.texi
>> ===================================================================
>> --- gcc/doc/extend.texi       (revision 4884)
>> +++ gcc/doc/extend.texi       (working copy)
>> @@ -3697,9 +3697,8 @@ that forces the union to be double-word
>>  As in the preceding examples, you can explicitly specify the alignment
>>  (in bytes) that you wish the compiler to use for a given variable or
>>  structure field.  Alternatively, you can leave out the alignment factor
>> -and just ask the compiler to align a variable or field to the maximum
>> -useful alignment for the target machine you are compiling for.  For
>> -example, you could write:
>> +and use @code{ATTRIBUTE_ALIGNED_VALUE} for the target machine you are
>> +compiling for.  For example, you could write:
>>
>>  @smallexample
>>  short array[3] __attribute__ ((aligned));
>> @@ -3707,11 +3706,11 @@ short array[3] __attribute__ ((aligned))
>>
>>  Whenever you leave out the alignment factor in an @code{aligned} attribute
>>  specification, the compiler automatically sets the alignment for the declared
>> -variable or field to the largest alignment which is ever used for any data
>> -type on the target machine you are compiling for.  Doing this can often make
>> -copy operations more efficient, because the compiler can use whatever
>> -instructions copy the biggest chunks of memory when performing copies to
>> -or from the variables or fields that you have aligned this way.
>> +variable or field to @code{ATTRIBUTE_ALIGNED_VALUE}.  Doing this can
>> +often make copy operations more efficient, because the compiler can use
>> +whatever instructions copy the biggest chunks of memory aligned at
>> +@code{ATTRIBUTE_ALIGNED_VALUE} when performing copies to or from the
>> +variables or fields that you have aligned this way.
>
> ATTRIBUTE_ALIGNED_VALUE is an internal compiler macro.  extend.texi is
> external user documentation.  extend.texi should not documented the
> attribute in terms of ATTRIBUTE_ALIGNED_VALUE.
>
>
>> Index: gcc/testsuite/gcc.target/i386/pr38736-2.c
>> ===================================================================
>> --- gcc/testsuite/gcc.target/i386/pr38736-2.c (revision 0)
>> +++ gcc/testsuite/gcc.target/i386/pr38736-2.c (revision 0)
>> @@ -0,0 +1,19 @@
>> +/* PR target/38736 */
>> +/* { dg-do run } */
>> +/* { dg-require-effective-target avx } */
>> +/* { dg-options "-O2 -mavx" } */
>> +
>> +extern void abort (void);
>> +
>> +struct alignment_test_struct
>> +{
>> +  char space[4] __attribute__((__aligned__));
>> +};
>> +
>> +int
>> +main ()
>> +{
>> +  if (__alignof__(struct alignment_test_struct) != 16)
>> +    abort ();
>> +  return 0;
>> +}
>
> This test case seems to be asserting that attribute ((aligned)) should
> always align to a 16-byte boundary on x86.  It is not clear to me that
> that should be the case.  In fact, I tend to think that it should not
> be the case.
>
> It would be better to (somehow) have a multi-file test which checked
> that attributed ((aligned)) has the same value with and without -mavx.
>
>> +/* Alignment value for attribute ((aligned)).  It is a constant
>> +   since it is the part of the ABI.  */
>> +#define ATTRIBUTE_ALIGNED_VALUE 128
>
> Please add some comment here about the AVX issue.
>
> Ian
>

Here is the updated patch.  OK for mainline?

Thanks.

-- 
H.J.
---

gcc/

2009-01-07  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/38736
	* c-common.c (handle_aligned_attribute): Use
	ATTRIBUTE_ALIGNED_VALUE instead of BIGGEST_ALIGNMENT for
	default alignment value.

	* defaults.h (ATTRIBUTE_ALIGNED_VALUE): New.
	* config/i386/i386.h (ATTRIBUTE_ALIGNED_VALUE): Likewise.

	* doc/extend.texi: Update __attribute__ ((aligned)).

	* doc/tm.texi: Document ATTRIBUTE_ALIGNED_VALUE.

gcc/testsuite/

2009-01-07  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/38736
	* g++.dg/compat/abi/pr38736_main.C: New.
	* g++.dg/compat/abi/pr38736_x.C: Likewise.
	* g++.dg/compat/abi/pr38736_y.C: Likewise.
	* gcc.dg/compat/pr38736_main.c: Likewise.
	* gcc.dg/compat/pr38736_x.c: Likewise.
	* gcc.dg/compat/pr38736_y.c: Likewise.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gcc-aligned-2.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090107/0d460eb9/attachment.ksh>


More information about the Gcc-patches mailing list