From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22584 invoked by alias); 16 Jul 2012 10:41:30 -0000 Received: (qmail 22574 invoked by uid 22791); 16 Jul 2012 10:41:29 -0000 X-SWARE-Spam-Status: No, hits=-3.6 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; Mon, 16 Jul 2012 10:41:17 +0000 From: "vermaelen.wouter at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/53979] New: (a^b^b) not simplified to (a) (in combination with CSE??) Date: Mon, 16 Jul 2012 10:41: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: enhancement X-Bugzilla-Who: vermaelen.wouter 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-07/txt/msg01217.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53979 Bug #: 53979 Summary: (a^b^b) not simplified to (a) (in combination with CSE??) Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: vermaelen.wouter@gmail.com The following 3 functions should ideally generate identical code (and they do when using clang). int f1(int a, int b) { int c = b; return (a ^ b ^ c) | (a ^ b) | a; } int f2(int a, int b) { return (a ^ b) | a; } int f3(int a, int b) { return a | b; } I tested gcc revision trunk@189510 and it shows 2 missed optimizations: 1) (a ^ b ^ b) not simplified to (a) Normally gcc performs this optimization, but I *guess* it misses it here because of the CSE opportunity with (a ^ b). 2) ((a ^ b) | a) not simplified to (a | b) Of course in this example it's easy to manually rewrite the code. But in my original code this function was actually a template and for some instantiations the expression for the variable 'c' simplified to just 'b'. So the first missed optimization is something I saw in real code. The second missed optimization only occurs in this (much) simplified variant of the function.