From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27773 invoked by alias); 19 Mar 2007 11:05:20 -0000 Received: (qmail 27745 invoked by uid 48); 19 Mar 2007 11:05:07 -0000 Date: Mon, 19 Mar 2007 11:05:00 -0000 Subject: [Bug tree-optimization/31261] New: Missed tree optimizations: (8 - (x & 7)) & 7 X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jakub at gcc dot gnu dot org" 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: 2007-03/txt/msg01797.txt.bz2 In 4.2 with -O2 -m32 -fomit-frame-pointer on x86_64: unsigned int foo (unsigned int x) { return (8 - (x & 7)) & 7; } results in andl $7, reg; negl reg; andl $7, reg. On 4.3 apparently some RTL optimization catches this, but it is still a missed tree optimization, fold should be able to fold: (cst - (x & cstmask)) & cstmask2 as (cst & cstmask2) + (-x & cstmask2) if x is unsigned or if -INT_MIN wraps to INT_MIN, both cstmask and cstmask2 are constants z^2-1 for some z and (cstmask & cstmask2) == cstmask2. BTW, even for (8 + (x & 7)) & 7 the optimized dump contains: (x & 7) + 8 & 7 for both 4.2/4.3 (no idea why 8 & 7 hasn't been simplified as 0). -- Summary: Missed tree optimizations: (8 - (x & 7)) & 7 Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31261