From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30813 invoked by alias); 7 Jan 2012 11:00:12 -0000 Received: (qmail 30671 invoked by uid 22791); 7 Jan 2012 11:00:05 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Sat, 07 Jan 2012 10:59:48 +0000 From: "ktietz at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51781] New: Missed optimization for ==/!= comparison type-sinking Date: Sat, 07 Jan 2012 11:00: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: ktietz at gcc dot gnu.org 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-01/txt/msg00712.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51781 Bug #: 51781 Summary: Missed optimization for ==/!= comparison type-sinking Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: ktietz@gcc.gnu.org Target: *-*-* The following code shows an issue about missed optimization for ==/!= comparisons. extern unsigned char ar[256]; int foo (int x, int y) { int i = (int) ar[x]; return (i == (y & 0xff)); } Compiled with 4.7 using -O2 we get the following optimized tree: ;; Function foo (foo, funcdef_no=0, decl_uid=1600, cgraph_uid=0) foo (int x, int y) { int i; _Bool D.2716; int D.2715; int D.2714; unsigned char D.2713; : D.2713_2 = ar[x_1(D)]; i_3 = (int) D.2713_2; D.2715_5 = y_4(D) & 255; D.2716_6 = D.2715_5 == i_3; D.2714_7 = (int) D.2716_6; return D.2714_7; } But to be expected would be: ;; Function foo (foo, funcdef_no=0, decl_uid=1709, cgraph_uid=0) foo (int x, int y) { unsigned char D.1719; _Bool D.1716; int D.1714; unsigned char D.1713; : D.1713_2 = ar[x_1(D)]; D.1719_9 = (unsigned char) y_4(D); D.1716_6 = D.1713_2 == D.1719_9; D.1714_7 = (int) D.1716_6; return D.1714_7; }