From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114860 invoked by alias); 13 Mar 2015 20:18:37 -0000 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 Received: (qmail 114597 invoked by uid 48); 13 Mar 2015 20:18:33 -0000 From: "sje at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/59371] [4.8/4.9/5 Regression] Performance regression in GCC 4.8 and later versions. Date: Fri, 13 Mar 2015 20:18:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: sje at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg01458.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59371 --- Comment #15 from Steve Ellcey --- I am not sure yet where and how to improve this automatically but I have found an interesting hand optimization that could point to a way to fix this. If I change the original function: int foo(int *p, unsigned short c) { signed short i; int x = 0; for (i = 0; i < c; i++) { x = x + *p; p++; } return x; } To: int foo(int *p, unsigned short c) { signed short i; unsigned short new_i; int x = 0; if (c > 32767) for (i = 0; i < c; i++) { x = x + *p; p++; } else for (new_i = 0; new_i < c; new_i++) { x = x + *p; p++; } return x; } Then GCC 5.0 generates an empty infinite loop for the first for loop and a compact 4 instruction loop (better even then 4.7) for the second for loop. I am not sure where or if we can do this optimization in GCC but I am going to investigate some more.