public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96427] New: Missing align attribute for anchor section from local variables
@ 2020-08-03  9:12 zhongyunde at tom dot com
  2020-08-03 10:54 ` [Bug c/96427] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zhongyunde at tom dot com @ 2020-08-03  9:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

            Bug ID: 96427
           Summary: Missing align attribute for anchor section from local
                    variables
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhongyunde at tom dot com
  Target Milestone: ---

For the following code, we can known the local array a_1 is aligned 64 bytes,
but now gcc only aligned to default 32 bytes for related anchor data.

====================== test case ================================
int bar (long long v);
int foo (int i)
{
  long long v;
  int a_1[131] __attribute__((aligned(64))) = {38580, 691093, 378582, 691095,
938904, 251417, 38906, 251419, 2938908, 251421, 938910, 4863, 92352, 104865,
792354, 4867, 2792356,251429, 938918,251431, 938920,251433, 938922, 104875,
22792364, 104877, 2792366, 104879, 2792368, 104881, 6180210,8492723,
6180212,8492725,
6180214,8492727,33656,346169,33658,346171,33660,346173,33662,8492735,
6180224,8492737, 6180226,8492739,
6180228,346181,33670,346183,33672,346185,33674,7906507, 593996,7906509,
593998,7906511, 594000,7906513,447442,7759955,447444,7759957,447446,7759959,
594008,7906521, 594010,7906523, 594012,7906525,
594014,7759967,447456,7759969,447458,7759971,447460,8492773, 6180262,8492775,
6180264,8492777, 6180266,346219,33708,346221,33710,346223,33712,346225,
6180274,8492787, 6180276,8492789,
6180278,8492791,33720,346233,33722,346235,33724,346237,33726,7906559,
594048,7906561, 594050,7906563,
594052,7760005,447494,7760007,447496,7760009,447498,7906571, 594060,7906573,
594062,7906575, 94064, 7906577, 447506, 760019, 447508, 760021, 447510};
  const long long * ptr = (const long long *)a_1;
  v = ptr[0];

  return bar (v);
} 

========= test base on the X86 gcc 9.3 on https://gcc.godbolt.org  ========= 
        .text
.Ltext0:
        .section   .rodata
        .align 32  # here, use the default alignment 32 byte of section .rodata
.LC0:
        .long   38580
        .long   691093
        .long   378582
        ...

foo(int):
        mov     rdi, QWORD PTR .LC0[rip]
        jmp     bar(long long)

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

* [Bug c/96427] Missing align attribute for anchor section from local variables
  2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
@ 2020-08-03 10:54 ` rguenth at gcc dot gnu.org
  2020-08-04  4:46 ` zhongyunde at tom dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-03 10:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-08-03
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed, the constant initializer doesn't inherit the alignment.  But it
works for the following for example where with -O -mavx512 we output
an aligned load and _do_ align the initializer.  So, are you requesting
the initializer honor the targets alignment?

typedef int v4si __attribute__((vector_size(64)));
int bar (v4si v);
int foo (int i)
{
  int a_1[131] __attribute__((aligned(64))) = {38580, 691093, 378582, 691095,
938904, 251417, 38906, 251419, 2938908, 251421, 938910, 4863, 92352, 104865,
792354, 4867, 2792356,251429, 938918,251431, 938920,251433, 938922, 104875,
22792364, 104877, 2792366, 104879, 2792368, 104881, 6180210,8492723,
6180212,8492725,
6180214,8492727,33656,346169,33658,346171,33660,346173,33662,8492735,
6180224,8492737, 6180226,8492739,
6180228,346181,33670,346183,33672,346185,33674,7906507, 593996,7906509,
593998,7906511, 594000,7906513,447442,7759955,447444,7759957,447446,7759959,
594008,7906521, 594010,7906523, 594012,7906525,
594014,7759967,447456,7759969,447458,7759971,447460,8492773, 6180262,8492775,
6180264,8492777, 6180266,346219,33708,346221,33710,346223,33712,346225,
6180274,8492787, 6180276,8492789,
6180278,8492791,33720,346233,33722,346235,33724,346237,33726,7906559,
594048,7906561, 594050,7906563,
594052,7760005,447494,7760007,447496,7760009,447498,7906571, 594060,7906573,
594062,7906575, 94064, 7906577, 447506, 760019, 447508, 760021, 447510};
  v4si * ptr = (v4si *)a_1;
  v4si v = ptr[0];
  return bar (v);
}

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

* [Bug c/96427] Missing align attribute for anchor section from local variables
  2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
  2020-08-03 10:54 ` [Bug c/96427] " rguenth at gcc dot gnu.org
@ 2020-08-04  4:46 ` zhongyunde at tom dot com
  2020-08-04  8:04 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zhongyunde at tom dot com @ 2020-08-04  4:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

--- Comment #2 from zhongyunde at tom dot com <zhongyunde at tom dot com> ---
should the data alignment honor the user specified ?

Now, it seems compiler _do_ align the initializer according align load. 
so even if the local array doesn't specify the __attribute__((aligned(64))), it
still align to 64 bytes.

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

* [Bug c/96427] Missing align attribute for anchor section from local variables
  2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
  2020-08-03 10:54 ` [Bug c/96427] " rguenth at gcc dot gnu.org
  2020-08-04  4:46 ` zhongyunde at tom dot com
@ 2020-08-04  8:04 ` rguenth at gcc dot gnu.org
  2020-08-05 13:21 ` zhongyunde at huawei dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-04  8:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to zhongyunde@tom.com from comment #2)
> should the data alignment honor the user specified ?

Technically the user requested alignment for the variable and GCC chose
to elide that with the constant pool entry for the initializer which does
not have any alignment specified (it could be shared amongst different
variables).

> Now, it seems compiler _do_ align the initializer according align load. 
> so even if the local array doesn't specify the __attribute__((aligned(64))),
> it still align to 64 bytes.

Yes, if GCC can then it will align data if it thinks that's beneficial.

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

* [Bug c/96427] Missing align attribute for anchor section from local variables
  2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
                   ` (2 preceding siblings ...)
  2020-08-04  8:04 ` rguenth at gcc dot gnu.org
@ 2020-08-05 13:21 ` zhongyunde at huawei dot com
  2020-08-06 10:25 ` rguenth at gcc dot gnu.org
  2020-08-20 12:56 ` zhongyunde at tom dot com
  5 siblings, 0 replies; 7+ messages in thread
From: zhongyunde at huawei dot com @ 2020-08-05 13:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

vfdff <zhongyunde at huawei dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zhongyunde at huawei dot com

--- Comment #4 from vfdff <zhongyunde at huawei dot com> ---
I test your case base on x86-64 gcc 10.1 with -O2 -S -mavx512f, the .rodata
aligned to 64 bytes, and it aligned to 32 bytes on x86-64 gcc 9.3 with -O2 -S
-mavx512f, i.e. it have different behaviour base on different gcc version.

so it is a undefined behaviour ?

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

* [Bug c/96427] Missing align attribute for anchor section from local variables
  2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
                   ` (3 preceding siblings ...)
  2020-08-05 13:21 ` zhongyunde at huawei dot com
@ 2020-08-06 10:25 ` rguenth at gcc dot gnu.org
  2020-08-20 12:56 ` zhongyunde at tom dot com
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-06 10:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to vfdff from comment #4)
> I test your case base on x86-64 gcc 10.1 with -O2 -S -mavx512f, the .rodata
> aligned to 64 bytes, and it aligned to 32 bytes on x86-64 gcc 9.3 with -O2
> -S -mavx512f, i.e. it have different behaviour base on different gcc version.
> 
> so it is a undefined behaviour ?

Well, it's an optimization so it's unspecified, not undefined behavior.

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

* [Bug c/96427] Missing align attribute for anchor section from local variables
  2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
                   ` (4 preceding siblings ...)
  2020-08-06 10:25 ` rguenth at gcc dot gnu.org
@ 2020-08-20 12:56 ` zhongyunde at tom dot com
  5 siblings, 0 replies; 7+ messages in thread
From: zhongyunde at tom dot com @ 2020-08-20 12:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96427

--- Comment #6 from zhongyunde at tom dot com <zhongyunde at tom dot com> ---
Created attachment 49087
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49087&action=edit
adjust the alignment according the attibute

If user don't specify the alignment, so we can do some optimization.
otherwise, we can obey it firstly, similiar to the patch attached?

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

end of thread, other threads:[~2020-08-20 12:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03  9:12 [Bug c/96427] New: Missing align attribute for anchor section from local variables zhongyunde at tom dot com
2020-08-03 10:54 ` [Bug c/96427] " rguenth at gcc dot gnu.org
2020-08-04  4:46 ` zhongyunde at tom dot com
2020-08-04  8:04 ` rguenth at gcc dot gnu.org
2020-08-05 13:21 ` zhongyunde at huawei dot com
2020-08-06 10:25 ` rguenth at gcc dot gnu.org
2020-08-20 12:56 ` zhongyunde at tom dot com

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