From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11289 invoked by alias); 15 Dec 2014 19:08:42 -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 11239 invoked by uid 48); 15 Dec 2014 19:08:38 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/64309] if (1 & (1 << n)) not simplified to if (n == 0) Date: Mon, 15 Dec 2014 19:08:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: olegendo at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: 5.0 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: 2014-12/txt/msg01796.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64309 --- Comment #4 from Oleg Endo --- (In reply to Richard Biener from comment #1) > Confirmed. Sth like > > (simplify > (ne (bit_and (lshift integer_onep @0) integer_onep) integer_zerop) > (eq @0 { build_zero_cst (TREE_TYPE (@0)); }) > > with eventually also covering if ((1 & (1<< n)) == 0) -> if (n & 1 == 0) > > You can extend this to cover the other cases you mention. I thought you might suggest something like this. :) While the transform for the if (...) is probably going to be beneficial for all the targets, I'm not so sure about the 'return ((1 << 1) & (1 << n));' variant, though. On some targets a shift+and might be cheaper than cmp+cstore. Is there any way to get that information during tree optimization? If not, it might be better to do that transformation on the RTL.