This is the mail archive of the gcc-bugs@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]

[Bug middle-end/23782] SRA pessimizes passing structures by value at -Os (+22% code size)



------- Comment #5 from rguenth at gcc dot gnu dot org  2008-01-27 13:27 -------
I think this is another variant of PR28831.  For the simplified testcase

typedef struct {
    unsigned short x, y;        /* x should be the easyest to read */
} coord;

void setpixel (coord xy, unsigned color);
void plotHline (coord xy, unsigned short xend, unsigned color);

extern inline void
UI_plotHline (coord xy, unsigned short xend, unsigned color)
{
  plotHline (xy, xend, color);
}
extern inline void
UI_setpixel (coord xy, unsigned color)
{
  setpixel (xy, color);
}

void drawbutton (coord    upperleft, coord  lowerright,
            unsigned upperleftcolor, unsigned lowerrightrcolor,
            unsigned fillcolor, unsigned drawbackground)
{
  UI_setpixel (upperleft, upperleftcolor);
  if (drawbackground)
    UI_plotHline (((coord) { .x = upperleft.x, .y = upperleft.y }),
                  lowerright.x, fillcolor);
  UI_setpixel (lowerright, lowerrightrcolor);
}

We end up doing extra stack temporaried for the first call exanding from:

<bb 2>:
  upperleft$x = upperleft.x;
  upperleft$y = upperleft.y;
  lowerright$x = lowerright.x;
  lowerright$y = lowerright.y;
  xy.y = upperleft$y;
  xy.x = upperleft$x;
  setpixel (xy, upperleftcolor);

In our case SRA inhibits re-use of struct temporaries as
we no longer see the simple copies.

And indeed with -fno-tree-sra the size goes down to that of GCC 3.4.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |28831
          Component|target                      |middle-end
      Known to fail|                            |4.3.0
      Known to work|                            |3.4.6
            Summary|-Os +22%: gcc-3.4.4 does it |SRA pessimizes passing
                   |in 230 bytes, gcc-4.0.2-pre |structures by value at -Os
                   |in 281 bytes                |(+22% code size)


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


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