From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11149 invoked by alias); 11 Dec 2011 23:41:37 -0000 Received: (qmail 11141 invoked by uid 22791); 11 Dec 2011 23:41:36 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,HK_LOTTO_NAME 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; Sun, 11 Dec 2011 23:41:18 +0000 From: "peteraward+gcc at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51506] New: Function cloning misses constant struct Date: Sun, 11 Dec 2011 23:58:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: peteraward+gcc 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" Content-Transfer-Encoding: quoted-printable 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: 2011-12/txt/msg01184.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D51506 Bug #: 51506 Summary: Function cloning misses constant struct Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: peteraward+gcc@gmail.com The actual problem I=E2=80=99m dealing with is with avr-gcc, so the goal is= to achieve a small code size. I=E2=80=99m trying to write my code like this: lcd_init(lcd_t l, ...) where the first parameter is passed a *constant* struct which contains the memory addresses of each of the pins for the LCD. Thus, I want the compiler= to note that all calls have the same first argument, clone the function, and propagate the constant. However, it doesn=E2=80=99t seem to be working in practice. In trying to build this test case, I found the compiler would just inline a= ll the functions, which defeats the point (in the actual code, the cost of inlining is too high). So, I=E2=80=99ve added the noinline attribute, which= I don=E2=80=99t think should stop this optimisation, but apologies if it does. Anyhow, here=E2=80=99s the testcase. (using gcc version 4.6.2 (Debian 4.6.2-5), on 64-bit Linux) $ cat test.c typedef struct { int a; int b; } dint; __attribute__((noinline)) static int compute_int(int x, int var) { int y =3D 0; for (int i =3D 0; i < x; i++) y +=3D i * x; return y + var; } __attribute__((noinline)) static int compute_dint(dint x, int var) { int z =3D x.a + x.b; int y =3D 0; for (int i =3D 0; i < z; i++) y +=3D i * z; return y + var; } int main() { int rv; rv +=3D compute_dint((dint) {6, 1}, 1); rv +=3D compute_dint((dint) {6, 1}, 2); rv +=3D compute_dint((dint) {6, 1}, 3); rv +=3D compute_int(5, 1); rv +=3D compute_int(5, 2); rv +=3D compute_int(5, 3); return rv; } $ gcc -fdump-ipa-all -fipa-cp -fipa-cp-clone -Os -std=3Dc99 test.c Expected result: both compute_int and compute_dint should be optimised to versions where "x"= is constant. Actual reslut: only compute_int is optimised.