public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/53081] New: memcpy/memset loop recognition
@ 2012-04-23  4:52 xinliangli at gmail dot com
  2012-04-23  5:03 ` [Bug middle-end/53081] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: xinliangli at gmail dot com @ 2012-04-23  4:52 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53081
           Summary: memcpy/memset loop recognition
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: xinliangli@gmail.com


Both LLVM and icc recognize initialization and copy loop and synthesize calls
to memcpy and memset.  memmove call can also be synthesized when src/target may
overlap.

Option needs to provided to disable such optimization in signal handlers.

I consider this as optimization for benchmarking ;) For instance, the prime
number finder program sieve.c is one of the benchmarks in LLVM. Both LLVM and
icc beats gcc in this one because of the missing optimization.


#ifndef T
#define T int
#endif

T arr[1000];

void foo(int n)
{
  int i;
  for (i = 0; i < n; i++)
    {
      arr[i] = 0;
    }
}

void foo2(int n, T* p)
{
  int i;
  for (i = 0; i < n; i++)
    {
      *p++ = 0;
    }
}

#ifndef T
#define T int
#endif

T arr[1000];
T arr2[1000];

void foo(int n)
{
  int i;
  for (i = 0; i < n; i++)
    {
      arr[i] = arr2[i];
    }
}


// sieve.c

/* -*- mode: c -*-
 * $Id: sieve.c 36673 2007-05-03 16:55:46Z laurov $
 * http://www.bagley.org/~doug/shootout/
 */

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[]) {
#ifdef SMALL_PROBLEM_SIZE
#define LENGTH 17000
#else
#define LENGTH 170000
#endif
    int NUM = ((argc == 2) ? atoi(argv[1]) : LENGTH);
    static char flags[8192 + 1];
    long i, k;
    int count = 0;

    while (NUM--) {
        count = 0; 
        for (i=2; i <= 8192; i++) {
            flags[i] = 1;
        }
        for (i=2; i <= 8192; i++) {
            if (flags[i]) {
                /* remove all multiples of prime: i */
                for (k=i+i; k <= 8192; k+=i) {
                    flags[k] = 0;
                }
                count++;
            }
        }
    }
    printf("Count: %d\n", count);
    return(0);
}


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

end of thread, other threads:[~2012-06-20  8:45 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-23  4:52 [Bug middle-end/53081] New: memcpy/memset loop recognition xinliangli at gmail dot com
2012-04-23  5:03 ` [Bug middle-end/53081] " pinskia at gcc dot gnu.org
2012-04-23  5:07 ` pinskia at gcc dot gnu.org
2012-04-23  5:34 ` xinliangli at gmail dot com
2012-04-23  5:35 ` xinliangli at gmail dot com
2012-04-23  6:53 ` amonakov at gcc dot gnu.org
2012-04-23  6:55 ` pinskia at gcc dot gnu.org
2012-04-23  8:19 ` jakub at gcc dot gnu.org
2012-04-23 10:27 ` [Bug tree-optimization/53081] " rguenth at gcc dot gnu.org
2012-06-05  9:25 ` rguenth at gcc dot gnu.org
2012-06-06  9:45 ` rguenth at gcc dot gnu.org
2012-06-06  9:46 ` rguenth at gcc dot gnu.org
2012-06-06  9:46 ` rguenth at gcc dot gnu.org
2012-06-06 11:32 ` Joost.VandeVondele at mat dot ethz.ch
2012-06-06 11:39 ` rguenther at suse dot de
2012-06-06 11:54 ` Joost.VandeVondele at mat dot ethz.ch
2012-06-06 12:43 ` izamyatin at gmail dot com
2012-06-20  8:45 ` izamyatin at gmail 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).