From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12181 invoked by alias); 23 Apr 2012 04:52:04 -0000 Received: (qmail 12173 invoked by uid 22791); 23 Apr 2012 04:52:02 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CP X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Apr 2012 04:51:49 +0000 From: "xinliangli at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/53081] New: memcpy/memset loop recognition Date: Mon, 23 Apr 2012 04:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xinliangli at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg01880.txt.bz2 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 #include 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); }