From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23253 invoked by alias); 15 Dec 2014 19:22:36 -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 23184 invoked by uid 48); 15 Dec 2014 19:22:32 -0000 From: "mpolacek 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:22: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: mpolacek 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/msg01802.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64309 --- Comment #5 from Marek Polacek --- (In reply to Oleg Endo from comment #4) > (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. :) Note that this transformation doesn't work. > 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. I don't think so. I tried to come up with a more general transformation that would simplify ((CST << n) & CST) != 0, but I haven't found anything yet. So maybe just this? ((1 << n) & 1) != 0 -> n == 0 ((1 << n) & 1) == 0 -> n != 0