public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
@ 2005-06-23  6:00 vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  6:03 ` [Bug tree-optimization/22158] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23  6:00 UTC (permalink / raw)
  To: gcc-bugs

static char *s0 = "000000000000000000000000000000000000000000000000";
static char s1[] = "111111111111111111111111111111111111111111111111";
static char *s2 = "000000000000000000000000000000000000000000000000";
static char s3[] = "111111111111111111111111111111111111111111111111";

void f(char*);
void g() {
    f(s0);
    f(s1);
    f(s2);
    f(s3);
}

s1 and s2 are aligned on 32 bytes even with -Os, while s2 and s4 are not.
See http://gcc.gnu.org/ml/gcc/2002-01/msg01068.html,
http://gcc.gnu.org/ml/gcc/2002-01/msg01068/i386.c.PATCH

-- 
           Summary: char global_var[] = "larger than 32 bytes"; uses silly
                    amounts of alignment even with -Os
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vda at port dot imtp dot ilyichevsk dot odessa dot ua
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-pc-linux-gnu
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu


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


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

* [Bug tree-optimization/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23  6:03 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  6:04 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23  6:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-23 06:03 -------
Created an attachment (id=9129)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9129&action=view)
Do not align at all if -Os

Sorry only have 3.4.1 sources available locally...

Patch is run tested.

-- 


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


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

* [Bug tree-optimization/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  6:03 ` [Bug tree-optimization/22158] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23  6:04 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  6:59 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23  6:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-23 06:04 -------
Created an attachment (id=9130)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9130&action=view)
Same patch with slightly different formatting

Also run tested

-- 


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


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

* [Bug tree-optimization/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  6:03 ` [Bug tree-optimization/22158] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  6:04 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23  6:59 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23  7:07 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23  6:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-23 06:59 -------
Created an attachment (id=9131)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9131&action=view)
While we are at it, speed up ix86_data_alignment

All if()s below are true only if align<128, so we can skip all of them.

And what is this?

   if (AGGREGATE_TYPE_P (type)
	&& TYPE_SIZE (type)
	&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
	&& (TREE_INT_CST_LOW (TYPE_SIZE (type)) >= 256
	   || TREE_INT_CST_HIGH (TYPE_SIZE (type))) && align < 256)
     return 256;

I do not remember anything which requires such wasteful alignment.
Maybe a comment would be in order there. (Or removal ;)

-- 


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


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

* [Bug tree-optimization/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (2 preceding siblings ...)
  2005-06-23  6:59 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23  7:07 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23 11:51 ` [Bug target/22158] " pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23  7:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-23 07:07 -------
Created an attachment (id=9132)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9132&action=view)
Same for ix86_local_alignment()


-- 


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (3 preceding siblings ...)
  2005-06-23  7:07 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23 11:51 ` pinskia at gcc dot gnu dot org
  2005-06-23 12:02 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-23 11:51 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |target


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (4 preceding siblings ...)
  2005-06-23 11:51 ` [Bug target/22158] " pinskia at gcc dot gnu dot org
@ 2005-06-23 12:02 ` pinskia at gcc dot gnu dot org
  2005-06-23 12:57 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-23 12:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-23 12:02 -------
Why do you think this is a bug?
Note the alignment change was done to support MMX/SSE:
<http://gcc.gnu.org/ml/gcc-patches/2000-06/msg00860.html>.

-- 


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (5 preceding siblings ...)
  2005-06-23 12:02 ` pinskia at gcc dot gnu dot org
@ 2005-06-23 12:57 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23 13:03 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23 12:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-23 12:56 -------
In majority of cases char msg[] = "A message" is used for text strings.
These are _bytes_, they need no alignment whatsoever, let alone 32 byte one.

I'm perfectly fine if other people want to do it, but I don't, so I use -Os.
I want to suppress this behavior for -Os.

Is it a bug or not is a matter of definition 'what is a bug' really...

BTW what is that another mysterious piece of code aligning something else to 32
bytes?

-- 


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (6 preceding siblings ...)
  2005-06-23 12:57 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23 13:03 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-23 13:13 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-23 13:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-23 13:03 -------
Oh, I did look at http://gcc.gnu.org/ml/gcc-patches/2000-06/msg00860.html,
I see 128 and 256 bit alignment added, but I don't immediately see where it is
applied to byte arrays (strings) - patch is not so small, where should I look?


-- 


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (7 preceding siblings ...)
  2005-06-23 13:03 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-23 13:13 ` pinskia at gcc dot gnu dot org
  2005-06-24  6:34 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-23 13:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-23 13:12 -------
(In reply to comment #7)
> Oh, I did look at http://gcc.gnu.org/ml/gcc-patches/2000-06/msg00860.html,
> I see 128 and 256 bit alignment added, but I don't immediately see where it is
> applied to byte arrays (strings) - patch is not so small, where should I look?

actually that did not add it, it was there before that patch, just moved it to the function.
The comment above DATA_ALIGNMENT in i386.h should explain why it was this is done:
   One use of this macro is to increase alignment of medium-size
   data to make it all fit in fewer cache lines.  Another is to 
   cause character arrays to be word-aligned so that `strcpy' calls
   that copy constants to character arrays can be done inline.  */

Though this should be moved to i386.c so this question no longer is there.

-- 


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (8 preceding siblings ...)
  2005-06-23 13:13 ` pinskia at gcc dot gnu dot org
@ 2005-06-24  6:34 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-06-24 11:51 ` pluto at agmk dot net
  2005-07-09 16:34 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 15+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-06-24  6:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-06-24 06:34 -------
>One use of this macro is to increase alignment of medium-size
>data to make it all fit in fewer cache lines.

1) This potentially makes single string fit into fewer cachelines,
but it noticeably increases the sum of all strings!
2) If cacheline is >32bytes, this optimization can even make things worse:

Unaligned string fits into 64 byte (say, Athlon64) cacheline:
[..some_string.]
^0      ^32     ^64

Same string spills over to second cacheline after alignment:
[.......some_st][ring.......]
^0      ^32     ^64

>Another is to 
>cause character arrays to be word-aligned so that `strcpy' calls
>that copy constants to character arrays can be done inline.

I do not fully understand. Is it about non-static local
char arrays initialized by string?

void f() {
    char s[] = "Long str";
}

How alignment affects this code? x86 CPUs can do unaligned loads/stores
just fine, thus 'inlinability' of implicit strcpy does not depend on alignment.
Also such local arrays are not very typical, so why optimize for this case?


-- 


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (9 preceding siblings ...)
  2005-06-24  6:34 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-06-24 11:51 ` pluto at agmk dot net
  2005-07-09 16:34 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 15+ messages in thread
From: pluto at agmk dot net @ 2005-06-24 11:51 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pluto at agmk dot net


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
  2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (10 preceding siblings ...)
  2005-06-24 11:51 ` pluto at agmk dot net
@ 2005-07-09 16:34 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-09 16:34 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  GCC build triplet|i386-pc-linux-gnu           |
   GCC host triplet|i386-pc-linux-gnu           |


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
       [not found] <bug-22158-1101@http.gcc.gnu.org/bugzilla/>
  2006-11-27 22:57 ` pinskia at gcc dot gnu dot org
@ 2006-11-27 23:03 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-27 23:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from pinskia at gcc dot gnu dot org  2006-11-27 23:03 -------
This was also fixed.
s2:
        .long   .LC0
        .data
        .align 4
        .type   s3, @object
        .size   s3, 49
s3:
        .string "111111111111111111111111111111111111111111111111"


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.2.0


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


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

* [Bug target/22158] char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os
       [not found] <bug-22158-1101@http.gcc.gnu.org/bugzilla/>
@ 2006-11-27 22:57 ` pinskia at gcc dot gnu dot org
  2006-11-27 23:03 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-27 22:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from pinskia at gcc dot gnu dot org  2006-11-27 22:57 -------
I think this was fixed by:
2006-01-10  Jan Beulich  <jbeulich@novell.com>

        * config/i386/i386.c (ix86_data_alignment): Don't force alignment to
        256 bits when optimize_size.


-- 


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


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

end of thread, other threads:[~2006-11-27 23:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-23  6:00 [Bug tree-optimization/22158] New: char global_var[] = "larger than 32 bytes"; uses silly amounts of alignment even with -Os vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23  6:03 ` [Bug tree-optimization/22158] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23  6:04 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23  6:59 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23  7:07 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23 11:51 ` [Bug target/22158] " pinskia at gcc dot gnu dot org
2005-06-23 12:02 ` pinskia at gcc dot gnu dot org
2005-06-23 12:57 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23 13:03 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-23 13:13 ` pinskia at gcc dot gnu dot org
2005-06-24  6:34 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-06-24 11:51 ` pluto at agmk dot net
2005-07-09 16:34 ` pinskia at gcc dot gnu dot org
     [not found] <bug-22158-1101@http.gcc.gnu.org/bugzilla/>
2006-11-27 22:57 ` pinskia at gcc dot gnu dot org
2006-11-27 23:03 ` pinskia at gcc dot gnu dot org

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