From patchwork Tue Jul 19 10:01:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 105425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 60C6CB6F69 for ; Tue, 19 Jul 2011 20:02:08 +1000 (EST) Received: (qmail 17758 invoked by alias); 19 Jul 2011 10:02:06 -0000 Received: (qmail 17745 invoked by uid 22791); 19 Jul 2011 10:02:04 -0000 X-SWARE-Spam-Status: No, hits=-3.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Jul 2011 10:01:32 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 157B28AD27 for ; Tue, 19 Jul 2011 12:01:31 +0200 (CEST) Date: Tue, 19 Jul 2011 12:01:30 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Make integer_all_onesp use TYPE_PRECISION, do not truncate BIT_*_EXPR to bitfield precision, fix PR18908 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch fixes PR18908, both the redundant bitfield truncation and the allegedly missing tree simplification of Bool ^ 1 to ~Bool. The former is because we for no reason truncate the result of bitwise binary expressions again (not needed, operands are already truncated). The latter is because integer_all_onesp uses the mode precision to determine if all bits are set for an unsigned constant - that's never true for all non-mode precision types (and thus Bool). There is no reason for this restriction now that expansion of BIT_NOT_EXPR is fixed. Bootstrapped and tested on x86_64-unknown-linux-gnu, leaving a bit for comments in case there are some. Richard. 2011-07-19 Richard Guenther PR middle-end/18908 * tree.c (integer_all_onesp): Use TYPE_PRECISION, not MODE_PRECISION. * expr.c (expand_expr_real_2): Do not unnecessarily truncate the result of BIT_*_EXPR to bitfield precision. Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 176399) +++ gcc/tree.c (working copy) @@ -1759,9 +1759,7 @@ integer_all_onesp (const_tree expr) if (!uns) return 0; - /* Note that using TYPE_PRECISION here is wrong. We care about the - actual bits, not the (arbitrary) range of the type. */ - prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))); + prec = TYPE_PRECISION (TREE_TYPE (expr)); if (prec >= HOST_BITS_PER_WIDE_INT) { HOST_WIDE_INT high_value; Index: gcc/expr.c =================================================================== --- gcc/expr.c (revision 176399) +++ gcc/expr.c (working copy) @@ -8319,6 +8319,12 @@ expand_expr_real_2 (sepops ops, rtx targ temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp, OPTAB_LIB_WIDEN); gcc_assert (temp); + /* Bitwise operations do not need bitfield reduction as we expect their + operands being properly truncated. */ + if (code == BIT_XOR_EXPR + || code == BIT_AND_EXPR + || code == BIT_IOR_EXPR) + return temp; return REDUCE_BIT_FIELD (temp); } #undef REDUCE_BIT_FIELD