public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57186] New: implement load sinking in loops
@ 2013-05-06 14:50 ebotcazou at gcc dot gnu.org
  2013-05-06 14:51 ` [Bug tree-optimization/57186] " ebotcazou at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-05-06 14:50 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57186
           Summary: implement load sinking in loops
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
               URL: http://gcc.gnu.org/ml/gcc-patches/2012-10/msg00742.htm
                    l
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ebotcazou@gcc.gnu.org


Created attachment 30040
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30040
Original implementation

Even at -O3, the compiler doesn't figure out that the following loop is dumb:

#define SIZE 64

int foo (int v[])
{
  int r;

  for (i = 0; i < SIZE; i++)
    r = v[i];

  return r;
}

This isn't entirely unexpected, as it probably matters only for (slightly)
pathological cases.  The attached patch nevertheless implements a form of load
sinking in loops so as to optimize these cases.  It's combined with invariant
motion to optimize:

int foo (int v[], int a)
{
  int r, i;

  for (i = 0; i < SIZE; i++)
    r = v[i] + a;

  return r;
}

and with store sinking to optimize:

int foo (int v1[], int v2[])
{
  int r[SIZE];
  int i, j;

  for (j = 0; j < SIZE; j++)
    for (i = 0; i < SIZE; i++)
      r[j] = v1[j] + v2[i];

  return r[SIZE - 1];
}

The optimization is enabled at -O2 in the patch for measurement purposes but, 
given how rarely it triggers (e.g. exactly 10 occurrences in a GCC bootstrap, 
compiler-only, all languages except Go), it's probably best suited to -O3.

It also comes with 3 testcases.


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

end of thread, other threads:[~2021-07-26 22:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-06 14:50 [Bug tree-optimization/57186] New: implement load sinking in loops ebotcazou at gcc dot gnu.org
2013-05-06 14:51 ` [Bug tree-optimization/57186] " ebotcazou at gcc dot gnu.org
2013-05-06 14:52 ` ebotcazou at gcc dot gnu.org
2013-05-06 14:52 ` ebotcazou at gcc dot gnu.org
2013-05-07  9:02 ` rguenth at gcc dot gnu.org
2021-07-26 22:09 ` pinskia at gcc dot gnu.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).